List of usage examples for org.apache.http.client.utils URIUtils createURI
@Deprecated public static URI createURI(final String scheme, final String host, final int port, final String path, final String query, final String fragment) throws URISyntaxException
From source file:tjs.tuneramblr.util.TuneramblrUrlHelper.java
/** * builds the mobile login URL.this includes the protocol, port, base, and * location. note: this URL does NOT contain a query string. * /*w w w .j a va2s . c om*/ * @return returns a string representing tuneramblr mobile login URL */ public URI getLoginHttpPostUrl() { URI builtUrl = null; try { builtUrl = URIUtils.createURI(PROTOCOL_HTTP, TUNERAMBLR_BASE_URL, NO_PORT, TUNERAMBLR_LOGIN_URL, null, null); } catch (URISyntaxException e) { builtUrl = null; } return builtUrl; }
From source file:com.mendhak.gpslogger.common.OpenGTSClient.java
/** * Send locations sing HTTP GET request to the server * <p/>/*from www .j a v a 2 s .co m*/ * See <a href="http://opengts.sourceforge.net/OpenGTS_Config.pdf">OpenGTS_Config.pdf</a> * section 9.1.2 Default "gprmc" Configuration * * @param id id of the device * @param locations locations */ public void sendHTTP(String id, String accountName, SerializableLocation[] locations) throws Exception { for (SerializableLocation loc : locations) { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("id", id)); qparams.add(new BasicNameValuePair("dev", id)); if (!Utilities.IsNullOrEmpty(accountName)) { qparams.add(new BasicNameValuePair("acct", accountName)); } else { qparams.add(new BasicNameValuePair("acct", id)); } //OpenGTS 2.5.5 requires batt param or it throws exception... qparams.add(new BasicNameValuePair("batt", "0")); qparams.add(new BasicNameValuePair("code", "0xF020")); qparams.add(new BasicNameValuePair("alt", String.valueOf(loc.getAltitude()))); qparams.add(new BasicNameValuePair("gprmc", OpenGTSClient.GPRMCEncode(loc))); URI uri = URIUtils.createURI("http", server, port, path, getQuery(qparams), null); HttpGet httpget = new HttpGet(uri); URL url = httpget.getURI().toURL(); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); Scanner s; if (conn.getResponseCode() != 200) { s = new Scanner(conn.getErrorStream()); tracer.error("Status code: " + String.valueOf(conn.getResponseCode())); if (s.hasNext()) { tracer.error(s.useDelimiter("\\A").next()); } } else { tracer.debug("Status code: " + String.valueOf(conn.getResponseCode())); } } }
From source file:org.craftercms.social.util.UGCHttpClient.java
public HttpResponse addPost(String ticket, String target, String parentId, String textContent, String[] fileAttachments) throws URISyntaxException, ClientProtocolException, IOException { HttpPost httppost = null;//from w w w. j ava2 s . c o m if (fileAttachments == null) { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("ticket", ticket)); if (target != null) qparams.add(new BasicNameValuePair("target", target)); else if (parentId != null) { qparams.add(new BasicNameValuePair("parentId", parentId)); } qparams.add(new BasicNameValuePair("textContent", textContent)); URI uri = URIUtils.createURI(scheme, host, port, appPath + "/api/2/ugc/" + "create.json", URLEncodedUtils.format(qparams, HTTP.UTF_8), null); httppost = new HttpPost(uri); } else { //if (fileAttachments!=null) { httppost = manageAttachments(fileAttachments, ticket, target, textContent); //} } HttpClient httpclient = new DefaultHttpClient(); return httpclient.execute(httppost); }
From source file:com.talis.labs.api.sparql11.http.Sparql11HttpRdfUpdateTest.java
private static URI uri(final String graph) throws URISyntaxException { List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("graph", graph)); URI uri = URIUtils.createURI(SCHEME, HOST, PORT, PATH, URLEncodedUtils.format(params, "UTF-8"), null); return uri;/* www. j av a 2s . c o m*/ }
From source file:com.betfair.testing.utils.cougar.manager.HttpPageManager.java
public int getPage(HttpPageBean bean) { // Get bean properties String requestedProtocol = bean.getProtocol(); String requestedHost = bean.getHost(); int requestedPort = bean.getPort(); String requestedLink = bean.getLink(); String username = bean.getAuthusername(); String password = bean.getAuthpassword(); final SSLSocketFactory sf = new SSLSocketFactory(createEasySSLContext(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme https = new Scheme("https", 9999, sf); // Set up httpClient to use given auth details and protocol DefaultHttpClient client = new DefaultHttpClient(); client.getConnectionManager().getSchemeRegistry().register(https); client.getCredentialsProvider().setCredentials(new AuthScope("localhost", AuthScope.ANY_PORT), new UsernamePasswordCredentials(username, password)); int status = -1; InputStream inputStream = null; // Make the request try {//from w w w .j a va 2 s. c o m final HttpGet httpget = new HttpGet( URIUtils.createURI(requestedProtocol, requestedHost, requestedPort, requestedLink, null, null)); final HttpResponse httpResponse = client.execute(httpget); inputStream = httpResponse.getEntity().getContent(); status = httpResponse.getStatusLine().getStatusCode(); if (status == HttpStatus.SC_OK) { bean.setPageLoaded(true); byte[] buffer = new byte[(int) httpResponse.getEntity().getContentLength()]; int read; int count = 0; while ((read = inputStream.read()) != -1) { buffer[count] = (byte) read; count++; } bean.setPageText(new String(buffer, "UTF-8")); bean.setBuffer(buffer); } } catch (IOException e1) { return -1; } catch (URISyntaxException e) { return -1; } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { // ignore } } } return status; }
From source file:com.jzboy.couchdb.http.URITemplates.java
/** * URI used to see a listing of multiple documents, filtered by the query parameters *//* ww w . j a va 2 s .co m*/ public static URI allDocs(String host, int port, String dbName, String query) throws URISyntaxException { return URIUtils.createURI("http", host, port, dbName + "/_all_docs", query, null); }
From source file:org.mahasen.client.Download.java
/** * @param fileName/*from w w w. j a v a2 s . c o m*/ * @throws IOException */ public void download(String fileName) throws IOException, MahasenClientException, URISyntaxException { httpclient = new DefaultHttpClient(); OutputStream outputStream = null; ClientConfiguration clientConfiguration = ClientConfiguration.getInstance(); try { String userName = clientLoginData.getUserName(); String passWord = clientLoginData.getPassWord(); String hostAndPort = clientLoginData.getHostNameAndPort(); String userId = clientLoginData.getUserId(userName, passWord); Boolean isLogged = clientLoginData.isLoggedIn(); System.out.println(" Is Logged : " + isLogged); if (isLogged == true) { httpclient = WebClientSSLWrapper.wrapClient(httpclient); List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("fileName", fileName)); URI uri = URIUtils.createURI("https", hostAndPort, -1, "/mahasen/download_ajaxprocessor.jsp", URLEncodedUtils.format(qparams, "UTF-8"), null); HttpPost httppost = new HttpPost(uri); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity httpEntity = response.getEntity(); if (httpEntity.getContentLength() > 0) { outputStream = new FileOutputStream(clientConfiguration.getDownloadRepo() + "/" + fileName); httpEntity.writeTo(outputStream); } else { System.out.println("no content available"); } System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (httpEntity != null) { System.out.println("Response content length: " + httpEntity.getContentLength()); System.out.println("Chunked?: " + httpEntity.isChunked()); } EntityUtils.consume(httpEntity); if (response.getStatusLine().getStatusCode() == 900) { throw new MahasenClientException(String.valueOf(response.getStatusLine())); } } else { System.out.println("User has to be logged in to perform this function"); } } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:com.madrobot.net.HttpTaskHelper.java
/** * Access point to add the query parameter to the request url * /*from w ww .j a v a 2 s . c o m*/ * @throws URISyntaxException * if request url syntax is wrong */ private void addQueryParameter() throws URISyntaxException { this.requestUrl = URIUtils.createURI(this.requestUrl.getScheme(), this.requestUrl.getAuthority(), -1, this.requestUrl.getPath(), URLEncodedUtils.format(requestParameter, HTTP.UTF_8), null); }
From source file:org.mahasen.client.UpdateMetadata.java
/** * @param fileToUpdate/*from ww w.ja va2 s.c o m*/ * @param tags * @throws URISyntaxException * @throws AuthenticationExceptionException * * @throws IOException * @throws UnsupportedEncodingException */ public void updateMetadata(String fileToUpdate, String tags) throws URISyntaxException, AuthenticationExceptionException, IOException, UnsupportedEncodingException, MahasenClientException { httpclient = new DefaultHttpClient(); String userName = clientLoginData.getUserName(); String passWord = clientLoginData.getPassWord(); String hostAndPort = clientLoginData.getHostNameAndPort(); String userId = clientLoginData.getUserId(userName, passWord); Boolean isLogged = clientLoginData.isLoggedIn(); System.out.println(" Is Logged : " + isLogged); if (isLogged == true) { httpclient = WebClientSSLWrapper.wrapClient(httpclient); // this will add file name and tags to user defined property list properties.add(new BasicNameValuePair("fileName", fileToUpdate)); properties.add(new BasicNameValuePair("tags", tags)); URI uri = URIUtils.createURI("https", hostAndPort, -1, "/mahasen/update_ajaxprocessor.jsp", URLEncodedUtils.format(properties, "UTF-8"), null); HttpPost httpPost = new HttpPost(uri); HttpResponse response = httpclient.execute(httpPost); HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(resEntity); if (response.getStatusLine().getStatusCode() == 900) { throw new MahasenClientException(String.valueOf(response.getStatusLine())); } } else { System.out.println("User has to be logged in to perform this function"); } httpclient.getConnectionManager().shutdown(); }
From source file:org.soyatec.windowsazure.authenticate.SharedKeyCredentialsWrapper.java
/** * Append the signedString to the uri./* ww w . j a v a2 s.c o m*/ * * @param uri * @param signedString * @return The uri after be appended with signedString. */ private URI appendSignString(URI uri, String signedString) { try { return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), HttpUtilities.getNormalizePath(uri), (uri.getQuery() == null ? Utilities.emptyString() : uri.getQuery()) + "&" + signedString, uri.getFragment()); } catch (URISyntaxException e) { Logger.error("", e); } return uri; }