Java Code Examples for org.apache.http.client.utils.URIUtils#createURI()

The following examples show how to use org.apache.http.client.utils.URIUtils#createURI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BitlyUrlService.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Make a GET request and append the Map of parameters onto the query string.
 * @param address		the fully qualified URL to make the request to
 * @param parameters	the Map of parameters, ie key,value pairs
 * @return
 */
private String doGet(String address, Map<String, String> parameters){
	try {
		
		List<NameValuePair> queryParams = new ArrayList<NameValuePair>();
		
		for (Map.Entry<String,String> entry : parameters.entrySet()) {
			queryParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
		}
		
		URI uri = URIUtils.createURI(null, address, -1, null, URLEncodedUtils.format(queryParams, "UTF-8"), null);
		
		log.info(uri.toString());
		
		return doGet(uri.toString());
	
	} catch (URISyntaxException e) {
		log.error(e.getClass() + ":" + e.getMessage());
	}
	return null;
}
 
Example 2
Source File: MDSInterface2.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static MDSResult doPost(String scheme, String host, int port,
                                  String path,
                                  List<NameValuePair> postData) throws UnsupportedEncodingException {
    URI uri = null;
    try {
        uri = URIUtils.createURI(scheme, host, port, path, null, null);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        throw new IllegalArgumentException(String.format("Can not post to mds: %s, %s, %d, %s", scheme, host, port, path), e);
    }
    Log.d(TAG, "doPost() uri: " + uri.toASCIIString());
    HttpPost post = new HttpPost(uri);
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(postData, "UTF-8");
    post.setEntity(entity);
    return MDSInterface2.doExecute(post);

}
 
Example 3
Source File: MDSInterface2.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected static MDSResult doPost(String scheme,
                                  String host,
                                  int port,
                                  String path,
                                  HttpEntity entity) {
    URI uri = null;
    try {
        uri = URIUtils.createURI(scheme, host, port, path, null, null);
    } catch (URISyntaxException e) {
        e.printStackTrace();
        throw new IllegalArgumentException(String.format("Can not post to mds: %s, %s, %d, %s", scheme, host, port, path), e);
    }
    Log.d(TAG, "doPost() uri: " + uri.toASCIIString());
    HttpPost post = new HttpPost(uri);
    post.setEntity(entity);
    return MDSInterface2.doExecute(post);
}
 
Example 4
Source File: BitlyUrlService.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
/**
 * Make a GET request and append the Map of parameters onto the query string.
 * @param address		the fully qualified URL to make the request to
 * @param parameters	the Map of parameters, ie key,value pairs
 * @return
 */
private String doGet(String address, Map<String, String> parameters){
	try {
		
		List<NameValuePair> queryParams = new ArrayList<NameValuePair>();
		
		for (Map.Entry<String,String> entry : parameters.entrySet()) {
			queryParams.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
		}
		
		URI uri = URIUtils.createURI(null, address, -1, null, URLEncodedUtils.format(queryParams, "UTF-8"), null);
		
		log.info(uri.toString());
		
		return doGet(uri.toString());
	
	} catch (URISyntaxException e) {
		log.error(e.getClass() + ":" + e.getMessage());
	}
	return null;
}
 
Example 5
Source File: HttpConnector.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Changes the query string in given URI and returns the updated URI.
 * 
 * @param uri
 * @param newQuery
 * @return the updated URI.
 */
private static URI changeQueryString(URI uri, String newQuery) {
	try {
		URI newURI = URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), newQuery, uri.getFragment());
		return newURI;
	} catch (URISyntaxException e) {
	}
	return null;
}
 
Example 6
Source File: HttpRequestFactory.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 *
 * @param scheme
 * @param host
 * @param port
 * @param path
 * @param queryParams
 * @return
 * @throws IllegalArgumentException
 */
public static HttpGet getHttpGetRequest(String scheme, String host, int port,
                                        String path, List<NameValuePair> queryParams, Header header) {
    try {
        URI uri = URIUtils.createURI(scheme, host, port, path,
                URLEncodedUtils.format(queryParams, "UTF-8"), null);
        HttpGet get = new HttpGet(uri);
        get.addHeader(header);
        return get;
    } catch (URISyntaxException e) {
        throw new IllegalArgumentException(e);
    }
}