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:com.github.feribg.audiogetter.helpers.Utils.java
/** * @param path relative path for the resource including / prefix * @param qparams NameValuePair list of parameters * @return a correctly formatted and urlencoded string * @throws URISyntaxException/*from www.java 2s .co m*/ */ public static URI getUri(String scheme, String path, List<NameValuePair> qparams) throws URISyntaxException { return URIUtils.createURI(scheme, Constants.Backend.API_HOST, -1, path, URLEncodedUtils.format(qparams, "UTF-8"), null); }
From source file:com.jelastic.JelasticService.java
public UploadResponse upload(AuthenticationResponse authenticationResponse) { UploadResponse uploadResponse = null; try {/*from w w w. ja va2 s. c o m*/ DefaultHttpClient httpclient = getHttpClient(); final File file = new File(getDir() + File.separator + getFilename()); if (!file.exists()) { throw new IllegalArgumentException( "First build artifact and try again. Artifact not found in location: [" + file.getAbsolutePath() + "]"); } CustomMultiPartEntity multipartEntity = new CustomMultiPartEntity(HttpMultipartMode.BROWSER_COMPATIBLE, new CustomMultiPartEntity.ProgressListener() { public void transferred(long num) { if (((int) ((num / (float) totalSize) * 100)) != numSt) { System.out.println( "File Uploading : [" + (int) ((num / (float) totalSize) * 100) + "%]"); numSt = ((int) ((num / (float) totalSize) * 100)); } } }); multipartEntity.addPart("fid", new StringBody("123456")); multipartEntity.addPart("session", new StringBody(authenticationResponse.getSession())); multipartEntity.addPart("file", new FileBody(file)); totalSize = multipartEntity.getContentLength(); URI uri = URIUtils.createURI(getProtocol(), getApiHoster(), getPort(), getUrlUploader(), null, null); project.log("Upload url : " + uri.toString(), Project.MSG_DEBUG); HttpPost httpPost = new HttpPost(uri); httpPost.setEntity(multipartEntity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(httpPost, responseHandler); project.log("Upload response : " + responseBody, Project.MSG_DEBUG); uploadResponse = deserialize(responseBody, UploadResponse.class); } catch (URISyntaxException | IOException e) { project.log(e.getMessage(), Project.MSG_ERR); } return uploadResponse; }
From source file:org.craftercms.social.util.UGCHttpClient.java
public HttpResponse updateModerationStatus(String ticket, String ugcId, String moderationStatus) throws URISyntaxException, ClientProtocolException, IOException { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("ticket", ticket)); URI uri = URIUtils.createURI(scheme, host, port, appPath + "/api/2/ugc/moderation/" + ugcId + "/status.json", URLEncodedUtils.format(qparams, HTTP.UTF_8), null); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(uri); StringEntity bodyEntity = new StringEntity(moderationStatus.toUpperCase(), "text/xml", HTTP.DEFAULT_CONTENT_CHARSET); httppost.setEntity(bodyEntity);//from w w w.j a v a2 s. co m return httpclient.execute(httppost); }
From source file:de.topicmapslab.couchtm.internal.utils.SysDB.java
/** * Method used to delete something in the database. * /*from www . j a v a2s .c o m*/ * @param query * @param key * @return result */ protected int deleteMethod(String query, String key) { int statusCode = 0; URI uri = null; if (key != null) { List<NameValuePair> pair = new ArrayList<NameValuePair>(); pair.add(new BasicNameValuePair("rev", key)); key = URLEncodedUtils.format(pair, "UTF-8"); } try { uri = URIUtils.createURI("http", url, port, (dbName == null ? "" : dbName + "/") + query, key, null); delete = new HttpDelete(uri); client.execute(delete, responseHandler); } catch (Exception e) { System.err.println(uri.toString()); e.printStackTrace(); } return statusCode; }
From source file:org.jboss.shrinkwrap.mobicents.servlet.sip.test.MobicentsSipServletsDeploymentIntegrationUnitTestCase.java
/** * Tests that we can execute an HTTP request on a Converged SIP Servlets application * and it's fulfilled as expected by returning the SIP application name in addition * to the echo value, proving our deployment succeeded *///from w w w .j a v a 2s. c o m @Test public void requestWebapp() throws Exception { // Get an HTTP Client final HttpClient client = new DefaultHttpClient(); // Make an HTTP Request, adding in a custom parameter which should be echoed back to us final String echoValue = "ShrinkWrap>Tomcat Integration"; final List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("to", PATH_ECHO_SERVLET)); params.add(new BasicNameValuePair("echo", echoValue)); final URI uri = URIUtils.createURI("http", BIND_HOST, HTTP_BIND_PORT, NAME_SIPAPP + SEPARATOR + servletClass.getSimpleName(), URLEncodedUtils.format(params, "UTF-8"), null); final HttpGet request = new HttpGet(uri); // Execute the request log.info("Executing request to: " + request.getURI()); final HttpResponse response = client.execute(request); System.out.println(response.getStatusLine()); final HttpEntity entity = response.getEntity(); if (entity == null) { Assert.fail("Request returned no entity"); } // Read the result, ensure it's what we're expecting (should be the value of request param "echo") final BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent())); final String line = reader.readLine(); Assert.assertEquals("Unexpected response from Servlet", echoValue + NAME_SIPAPP, line); }
From source file:org.mahasen.util.PutUtil.java
/** * @param file/* w ww . j a va 2s . c om*/ * @throws InterruptedException * @throws RegistryException * @throws PastException * @throws IOException */ public void secureUpload(File file, Id resourceId) throws InterruptedException, RegistryException, PastException, IOException, MahasenConfigurationException, MahasenException { // get the IP addresses pool to upload files. Vector<String> nodeIpsToPut = getNodeIpsToPut(); MahasenFileSplitter mahasenFileSplitter = new MahasenFileSplitter(); mahasenFileSplitter.split(file); HashMap<String, String> fileParts = mahasenFileSplitter.getPartNames(); mahasenResource.addPartNames(fileParts.keySet().toArray(new String[fileParts.size()])); Random random = new Random(); for (String currentPartName : fileParts.keySet()) { File splittedFilePart = new File(fileParts.get(currentPartName)); int randomNumber = random.nextInt(nodeIpsToPut.size()); String nodeIp = nodeIpsToPut.get(randomNumber); try { setTrustStore(); URI uri = null; ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("splittedfilename", splittedFilePart.getName())); uri = URIUtils.createURI("https", nodeIp + ":" + MahasenConstants.SERVER_PORT, -1, "/mahasen/upload_request_ajaxprocessor.jsp", URLEncodedUtils.format(qparams, "UTF-8"), null); MahasenUploadWorker uploadWorker = new MahasenUploadWorker(uri, currentPartName, splittedFilePart, mahasenResource, nodeIp); uploadThread = new Thread(uploadWorker); uploadWorker.setJobId(jobId); //keep track of uploading parts AtomicInteger noOfParts = new AtomicInteger(0); storedNoOfParts.put(jobId, noOfParts); uploadThread.start(); } catch (Exception e) { e.printStackTrace(); } } final BlockFlag blockFlag = new BlockFlag(true, 6000); while (true) { AtomicInteger noOfParts = storedNoOfParts.get(jobId); if (noOfParts.get() == fileParts.size()) { storedNoOfParts.remove(uploadThread.getId()); System.out.println("uploaded no of parts " + noOfParts + "out of " + fileParts.size() + "going out " + "#####Thread id:" + uploadThread.getId()); blockFlag.unblock(); break; } if (blockFlag.isBlocked()) { mahasenManager.getNode().getEnvironment().getTimeSource().sleep(10); } else { throw new MahasenException("Time out in uploading " + file.getName()); } } mahasenManager.insertIntoDHT(resourceId, mahasenResource, false); mahasenManager.insertTreeMapIntoDHT(resourceId, mahasenResource, false); ReplicateRequestStarter replicateStarter = new ReplicateRequestStarter(mahasenResource); Thread replicateThread = new Thread(replicateStarter); replicateThread.start(); }
From source file:mobisocial.musubi.identity.AphidIdentityProvider.java
public boolean initiateTwoPhaseClaim(IBIdentity ident, String key, int requestId) { // Send the request to Aphid HttpClient http = new CertifiedHttpClient(mContext); List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("req", new Integer(requestId).toString())); qparams.add(new BasicNameValuePair("type", new Integer(ident.authority_.ordinal()).toString())); qparams.add(new BasicNameValuePair("uid", ident.principal_)); qparams.add(new BasicNameValuePair("time", new Long(ident.temporalFrame_).toString())); qparams.add(new BasicNameValuePair("key", key)); try {//ww w. j a v a2 s . c om // Send the request URI uri = URIUtils.createURI(URL_SCHEME, SERVER_LOCATION, -1, CLAIM_PATH, URLEncodedUtils.format(qparams, "UTF-8"), null); Log.d(TAG, "Aphid URI: " + uri.toString()); HttpGet httpGet = new HttpGet(uri); HttpResponse response = http.execute(httpGet); int code = response.getStatusLine().getStatusCode(); // Read the response BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String responseStr = ""; String line = ""; while ((line = rd.readLine()) != null) { responseStr += line; } Log.d(TAG, "Server response:" + responseStr); // Only 200 should indicate that this worked if (code == HttpURLConnection.HTTP_OK) { // Mark as notified (suppress repeated texts) MIdentity mid = mIdentitiesManager.getIdentityForIBHashedIdentity(ident); if (mid != null) { MPendingIdentity pendingIdent = mPendingIdentityManager.lookupIdentity(mid.id_, ident.temporalFrame_, requestId); if (pendingIdent == null) { pendingIdent = mPendingIdentityManager.fillPendingIdentity(mid.id_, ident.temporalFrame_); mPendingIdentityManager.insertIdentity(pendingIdent); } pendingIdent.notified_ = true; mPendingIdentityManager.updateIdentity(pendingIdent); } return true; } } catch (URISyntaxException e) { Log.e(TAG, "URISyntaxException", e); } catch (IOException e) { Log.i(TAG, "Error claiming keys."); } return false; }
From source file:com.teamlazerbeez.crm.sf.rest.HttpApiClient.java
@Nonnull private URI getUriForPath(String path) throws IOException { try {// w w w. j a v a 2 s . co m return URIUtils.createURI("https", this.host, 443, path, null, null); } catch (URISyntaxException e) { throw new IOException("Couldn't create URI", e); } }
From source file:edu.internet2.middleware.openid.message.encoding.EncodingUtils.java
/** * Append the URL encoded OpenID message parameters to the query string of the provided URI. * // w w w.ja v a 2 s . c o m * @param uri URI to append OpenID message parameter to * @param message URL encoded OpenID message parameters * @return URI with message parameters appended */ public static URI appendMessageParameters(URI uri, String message) { if (uri == null || message == null) { return uri; } // build new query string StringBuffer queryBuffer = new StringBuffer(); if (uri.getRawQuery() != null) { queryBuffer.append(uri.getRawQuery()); } if (queryBuffer.length() > 0 && queryBuffer.charAt(queryBuffer.length() - 1) != '&') { queryBuffer.append('&'); } queryBuffer.append(message); try { return URIUtils.createURI(uri.getScheme(), uri.getHost(), uri.getPort(), uri.getPath(), queryBuffer.toString(), uri.getFragment()); } catch (URISyntaxException e) { log.error("Unable to append message parameters to URI: {}", e); } return null; }
From source file:com.github.feribg.audiogetter.helpers.Utils.java
/** * Prepare soundcloud search URL//from w ww. j av a 2 s.co m * @param query * @param offset * @return * @throws URISyntaxException */ public static URI getSoundCloudSearchURI(String query, Integer offset) throws URISyntaxException { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("client_id", Constants.Soundcloud.CLIENT_ID)); qparams.add(new BasicNameValuePair("offset", String.valueOf(offset))); qparams.add(new BasicNameValuePair("limit", String.valueOf(Constants.Soundcloud.PER_PAGE))); qparams.add(new BasicNameValuePair("q", query)); return URIUtils.createURI(Constants.Soundcloud.API_SCHEME, Constants.Soundcloud.API_HOST, -1, Constants.Soundcloud.API_SEARCH, URLEncodedUtils.format(qparams, "UTF-8"), null); }