List of usage examples for org.apache.http.client.utils URIBuilder URIBuilder
public URIBuilder(final URI uri)
From source file:com.epam.ngb.cli.manager.command.handler.http.GeneAddingHandler.java
@Override public int runCommand() { try {/*from w ww .ja va2 s . c o m*/ String url = serverParameters.getServerUrl() + getRequestUrl(); URIBuilder builder = new URIBuilder(String.format(url, referenceId)); if (geneFileId != null) { builder.addParameter("geneFileId", String.valueOf(geneFileId)); } HttpPut put = new HttpPut(builder.build()); setDefaultHeader(put); if (isSecure()) { addAuthorizationToRequest(put); } String result = RequestManager.executeRequest(put); checkAndPrintRegistrationResult(result, printJson, printTable); } catch (URISyntaxException e) { throw new ApplicationException(e.getMessage(), e); } return 0; }
From source file:net.rcarz.jiraclient.RestClient.java
/** * Build a URI from a path and query parmeters. * * @param path Path to append to the base URI * @param params Map of key value pairs//from w ww . j a v a2 s . co m * * @return the full URI * * @throws URISyntaxException when the path is invalid */ public URI buildURI(String path, Map<String, String> params) throws URISyntaxException { URIBuilder ub = new URIBuilder(uri); ub.setPath(ub.getPath() + path); if (params != null) { for (Map.Entry<String, String> ent : params.entrySet()) ub.addParameter(ent.getKey(), ent.getValue()); } return ub.build(); }
From source file:de.bmarwell.j9kwsolver.util.RequestToURI.java
/** * Converts a request object for retrieving the captcha image * to an URI for 9kw API./* w w w. j a va 2 s .c o m*/ * @param cs the CaptchaShow request. * @return the URI for the API request. */ public static URI captchaShowToURI(final CaptchaShow cs) { URI uri = null; if (cs == null) { return null; } URI apiURI = stringToURI(cs.getUrl()); URIBuilder builder = new URIBuilder(apiURI).addParameter("id", cs.getId()) .addParameter("action", cs.getAction()).addParameter("apikey", cs.getApikey()) .addParameter("source", cs.getSource()) .addParameter("debug", BooleanUtils10.toIntegerString(cs.isDebug())) .addParameter("base64", BooleanUtils10.toIntegerString(cs.isBase64())); try { uri = builder.build(); } catch (URISyntaxException e) { LOG.error("Konnte URI nicht erstellen!", e); } return uri; }
From source file:tech.beshu.ror.httpclient.ApacheHttpCoreClient.java
@Override public CompletableFuture<RRHttpResponse> send(RRHttpRequest request) { CompletableFuture<HttpResponse> promise = new CompletableFuture<>(); URI uri;/*from w ww . ja v a2 s. c o m*/ HttpRequestBase hcRequest; try { if (request.getMethod() == HttpMethod.POST) { uri = new URIBuilder(request.getUrl().toASCIIString()).build(); hcRequest = new HttpPost(uri); List<NameValuePair> urlParameters = new ArrayList<NameValuePair>(); request.getQueryParams().entrySet() .forEach(x -> urlParameters.add(new BasicNameValuePair(x.getKey(), x.getValue()))); ((HttpPost) hcRequest).setEntity(new UrlEncodedFormEntity(urlParameters)); } else { uri = new URIBuilder(request.getUrl().toASCIIString()).addParameters(request.getQueryParams() .entrySet().stream().map(e -> new BasicNameValuePair(e.getKey(), e.getValue())) .collect(Collectors.toList())).build(); hcRequest = new HttpGet(uri); } } catch (URISyntaxException e) { throw context.rorException(e.getClass().getSimpleName() + ": " + e.getMessage()); } catch (UnsupportedEncodingException e) { throw context.rorException(e.getClass().getSimpleName() + ": " + e.getMessage()); } request.getHeaders().entrySet().forEach(e -> hcRequest.addHeader(e.getKey(), e.getValue())); AccessController.doPrivileged((PrivilegedAction<Void>) () -> { hcHttpClient.execute(hcRequest, new FutureCallback<HttpResponse>() { public void completed(final HttpResponse hcResponse) { int statusCode = hcResponse.getStatusLine().getStatusCode(); logger.debug("HTTP REQ SUCCESS with status: " + statusCode + " " + request); promise.complete(hcResponse); } public void failed(final Exception ex) { logger.debug("HTTP REQ FAILED " + request); logger.info("HTTP client failed to connect: " + request + " reason: " + ex.getMessage()); promise.completeExceptionally(ex); } public void cancelled() { promise.completeExceptionally(new RuntimeException("HTTP REQ CANCELLED: " + request)); } }); return null; }); return promise.thenApply(hcResp -> new RRHttpResponse(hcResp.getStatusLine().getStatusCode(), () -> { try { return hcResp.getEntity().getContent(); } catch (IOException e) { throw new RuntimeException("Cannot read content", e); } })); }
From source file:de.dentrassi.pm.jenkins.UploaderV3.java
@Override public boolean complete() { if (this.failed) { return false; }//ww w . ja v a 2 s . c o m try { closeTransfer(); final URIBuilder uri = new URIBuilder(String.format("%s/api/v3/upload/archive/channel/%s", this.serverUrl, URIUtil.encodeWithinPath(this.channelId))); this.listener.getLogger().println("API endpoint: " + uri.build().toString()); final HttpPut httppost = new HttpPut(uri.build()); final String encodedAuth = Base64 .encodeBase64String(("deploy:" + this.deployKey).getBytes("ISO-8859-1")); httppost.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuth); final InputStream stream = new FileInputStream(this.tempFile); try { httppost.setEntity(new InputStreamEntity(stream, this.tempFile.length())); final HttpResponse response = this.client.execute(httppost); final HttpEntity resEntity = response.getEntity(); this.listener.getLogger().println("Call returned: " + response.getStatusLine()); if (resEntity != null) { switch (response.getStatusLine().getStatusCode()) { case 200: processUploadResult(makeString(resEntity)); return true; case 404: this.listener.error( "Failed to find upload endpoint V3. This could mean that you configured a wrong server URL or that the server does not support the Upload V3. You will need a version 0.14+ of Eclipse Package Drone. It could also mean that you did use wrong credentials."); return false; default: if (!handleError(response)) { addErrorMessage("Failed to upload: " + response.getStatusLine()); } return false; } } addErrorMessage("Did not receive a result"); return false; } finally { stream.close(); } } catch (final Exception e) { e.printStackTrace(this.listener.error("Failed to perform archive upload")); return false; } }
From source file:com.sheepdog.mashmesh.PickupNotification.java
private URI createDynamicMapUri() throws URISyntaxException { URIBuilder uriBuilder = new URIBuilder(DYNAMIC_MAPS_URL); uriBuilder.addParameter("saddr", volunteerUserProfile.getAddress()); uriBuilder.addParameter("daddr", getPatientProfile().getAddress() + " to:" + getAppointmentAddress()); return uriBuilder.build(); }
From source file:ca.islandora.fcrepo.client.FcrepoClient.java
@Override public IFcrepoResponse commitTransaction(final String uri) throws FcrepoOperationFailedException { try {/* w w w. ja v a 2 s. com*/ URIBuilder uriBuilder = new URIBuilder(baseUri); uriBuilder.setPath(uriBuilder.getPath() + "/fcr:tx/fcr:commit"); final String fullUri = uriBuilder.build().toString(); final IFcrepoRequest request = new CreateResourceRequest(httpClient, fullUri); return request.execute(); } catch (URISyntaxException ex) { throw new FcrepoOperationFailedException(null, -1, ex.getMessage()); } }
From source file:com.activiti.service.activiti.ProcessInstanceService.java
public JsonNode listProcesInstancesForProcessDefinition(ObjectNode bodyNode, ServerConfig serverConfig) { JsonNode resultNode = null;/*from w w w. ja va2s .c om*/ try { URIBuilder builder = new URIBuilder("query/historic-process-instances"); builder.addParameter("size", DEFAULT_PROCESSINSTANCE_SIZE); builder.addParameter("sort", "startTime"); builder.addParameter("order", "desc"); String uri = clientUtil.getUriWithPagingAndOrderParameters(builder, bodyNode); HttpPost post = clientUtil.createPost(uri, serverConfig); post.setEntity(clientUtil.createStringEntity(bodyNode.toString())); resultNode = clientUtil.executeRequest(post, serverConfig); } catch (Exception e) { throw new ActivitiServiceException(e.getMessage(), e); } return resultNode; }
From source file:org.wso2.carbon.identity.captcha.util.CaptchaUtil.java
public static String getUpdatedUrl(String url, Map<String, String> attributes) { try {/* ww w .java 2s. c o m*/ URIBuilder uriBuilder = new URIBuilder(url); for (Map.Entry<String, String> entry : attributes.entrySet()) { uriBuilder.addParameter(entry.getKey(), entry.getValue()); } return uriBuilder.build().toString(); } catch (URISyntaxException e) { if (log.isDebugEnabled()) { log.debug("Error occurred while building URL.", e); } return url; } }
From source file:ezbake.azkaban.manager.ExecutionManager.java
/** * Returns all of the current executions of the flow * * @param projectName The project to fetch from * @param flowId The id of the flow to executeFlow the exections for * @return List of flow ID's that are currently executing *//*from w ww.ja va 2 s .co m*/ public RunningExecutionsResult getRunningExecutions(String projectName, String flowId) throws Exception { final URI uri = new URIBuilder(executionUri).setParameter("session.id", sessionId) .setParameter("ajax", "getRunning").setParameter("project", projectName) .setParameter("flow", flowId).build(); final HttpGet get = new HttpGet(uri); final String json = HttpManager.get(get); logger.info("Running executions result: \n{}", json); return (RunningExecutionsResult) JsonUtil.deserialize(json, RunningExecutionsResult.class); }