List of usage examples for org.apache.http.client.utils URIBuilder build
public URI build() throws URISyntaxException
From source file:com.adobe.acs.commons.adobeio.service.impl.EndpointServiceImpl.java
/** * Process the Adobe I/O action/*from w w w . ja v a 2s.co m*/ * * @param actionUrl * The url to be executed * @param queryParameters * The query parameters to pass * @param method * The method to be executed * @param payload * The payload of the call * @return JsonObject containing the result of the action * @throws Exception * Thrown when process-action throws an exception */ private JsonObject process(@NotNull final String actionUrl, @NotNull final Map<String, String> queryParameters, @NotNull final String method, final String[] headers, @NotNull final JsonObject payload) { if (isBlank(actionUrl) || isBlank(method)) { LOGGER.error("Method or url is null"); return new JsonObject(); } URI uri = null; try { URIBuilder builder = new URIBuilder(actionUrl); queryParameters.forEach((k, v) -> builder.addParameter(k, v)); uri = builder.build(); } catch (URISyntaxException uriexception) { LOGGER.error(uriexception.getMessage()); return new JsonObject(); } LOGGER.debug("Performing method = {}. queryParameters = {}. actionUrl = {}. payload = {}", method, queryParameters, uri, payload); try { if (StringUtils.equalsIgnoreCase(method, METHOD_POST)) { return processPost(uri, payload, headers); } else if (StringUtils.equalsIgnoreCase(method, METHOD_GET)) { return processGet(uri, headers); } else if (StringUtils.equalsIgnoreCase(method, "PATCH")) { return processPatch(uri, payload, headers); } else { return new JsonObject(); } } catch (IOException ioexception) { LOGGER.error(ioexception.getMessage()); return new JsonObject(); } }
From source file:com.ibm.health.HealthData.java
public String getHealthInformation(String condition) { String result = ""; try {//from ww w . j a va2 s . c om CloseableHttpClient httpClient = HttpClients.createDefault(); URIBuilder builder = new URIBuilder(baseURLAlerts + "/terms"); builder.setParameter("client_id", clientId).setParameter("client_secret", clientSecret) .setParameter("condition", condition); URI uri = builder.build(); HttpGet httpGet = new HttpGet(uri); httpGet.setHeader("Content-Type", "text/plain"); HttpResponse httpResponse = httpClient.execute(httpGet); if (httpResponse.getStatusLine().getStatusCode() == 200) { BufferedReader rd = new BufferedReader( new InputStreamReader(httpResponse.getEntity().getContent(), "UTF-8")); StringBuilder everything = new StringBuilder(); String line; while ((line = rd.readLine()) != null) { everything.append(line); } result = everything.toString(); } else { logger.error("could not get health condition information {}", httpResponse.getStatusLine().getStatusCode()); } } catch (Exception e) { logger.error("Health Information error: {}", e.getMessage()); } return result; }
From source file:com.google.appengine.tck.blobstore.support.FileUploader.java
private String getUploadUrl(URL url, Method method, Map<String, String> params) throws URISyntaxException, IOException { URIBuilder builder = new URIBuilder(url.toURI()); for (Map.Entry<String, String> entry : params.entrySet()) { builder.addParameter(entry.getKey(), entry.getValue()); }/* w ww . jav a2 s . c om*/ HttpClient httpClient = new DefaultHttpClient(); try { HttpUriRequest request; switch (method) { case GET: request = new HttpGet(builder.build()); break; case POST: request = new HttpPost(builder.build()); break; default: throw new IllegalArgumentException(String.format("No such method: %s", method)); } HttpResponse response = httpClient.execute(request); return EntityUtils.toString(response.getEntity()).trim(); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:com.munichtrading.tracking.camera.APIIPCamera.java
private void sendGet(String parameter, String value) { try {/*from w ww .j a v a2 s .c o m*/ URIBuilder builder = new URIBuilder().setScheme("http").setHost(this.device.getHostName()) .setPath("/parameters").addParameter(parameter, value); HttpClient client = HttpClients.createDefault(); HttpGet request = new HttpGet(builder.build()); request.addHeader("User-Agent", USER_AGENT); HttpResponse response = client.execute(request); logger.info("Sending request: " + builder.toString()); logger.info("Response Code : " + response.getStatusLine().getStatusCode()); if (response.getStatusLine().getStatusCode() == 200) { BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line); } this.updateSettings(result.toString()); } else { throw new Exception("Request unsuccessfull"); } } catch (HttpHostConnectException e) { logger.error("Could not connect to device"); } catch (Exception e) { logger.error("Something went wrong"); } }
From source file:eu.dime.userresolver.client.ResolverClient.java
public void search(String token, String name, String surname, String nickname) { HttpGet httpGet;/*from w w w . j a v a 2 s. c o m*/ try { URIBuilder builder = new URIBuilder(serviceEnpoint + "/search"); if (name != null) builder.setParameter("name", name); if (surname != null) builder.setParameter("surname", surname); if (nickname != null) builder.setParameter("nickname", nickname); httpGet = new HttpGet(builder.build()); } catch (URISyntaxException e) { throw new RuntimeException(e); } httpGet.setHeader("Authorization", "Bearer " + token); try { HttpResponse response = httpClient.execute(httpGet); HttpEntity entity = response.getEntity(); if (entity != null) { String jsonResponse = IOUtils.toString(entity.getContent()); LOG.debug("Search response: {}", jsonResponse); } } catch (IOException e) { LOG.debug("Unable to search", e); } }
From source file:com.jaspersoft.studio.server.protocol.restv2.RestV2Connection.java
@Override public ResourceDescriptor move(IProgressMonitor monitor, ResourceDescriptor rd, String destFolderURI) throws Exception { URIBuilder ub = new URIBuilder(url("resources" + destFolderURI)); ub.addParameter("overwrite", "true"); ub.addParameter("createFolders", "true"); Request req = HttpUtils.put(ub.build().toASCIIString(), sp); req.setHeader("Content-Location", rd.getUriString()); String rtype = WsTypes.INST().toRestType(rd.getWsType()); ClientResource<?> crl = toObj(req, WsTypes.INST().getType(rtype), monitor); if (crl != null) return Rest2Soap.getRD(this, crl, rd); return null;/*from ww w . j a va 2s . c o m*/ }
From source file:com.jaspersoft.studio.server.protocol.restv2.RestV2Connection.java
@Override public ResourceDescriptor copy(IProgressMonitor monitor, ResourceDescriptor rd, String destFolderURI) throws Exception { URIBuilder ub = new URIBuilder(url("resources" + destFolderURI)); ub.addParameter("overwrite", "true"); ub.addParameter("createFolders", "true"); Request req = HttpUtils.post(ub.build().toASCIIString(), sp); req.setHeader("Content-Location", rd.getUriString()); String rtype = WsTypes.INST().toRestType(rd.getWsType()); ClientResource<?> crl = toObj(req, WsTypes.INST().getType(rtype), monitor); if (crl != null) return Rest2Soap.getRD(this, crl, rd); return null;/*from w w w . j av a 2s.co m*/ }
From source file:org.talend.dataprep.api.service.command.dataset.CloneDataSet.java
/** * Constructor./*w ww .j av a 2s . co m*/ * * @param dataSetId the requested dataset id. * @param folderPath the folder to clone the dataset * @param cloneName the cloned name */ public CloneDataSet(String dataSetId, String folderPath, String cloneName) { super(GenericCommand.DATASET_GROUP); execute(() -> { try { URIBuilder uriBuilder = new URIBuilder(datasetServiceUrl + "/datasets/clone/" + dataSetId); if (StringUtils.isNotEmpty(folderPath)) { uriBuilder.addParameter("folderPath", folderPath); } if (StringUtils.isNotEmpty(cloneName)) { uriBuilder.addParameter("cloneName", cloneName); } return new HttpPut(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }); onError(e -> new TDPException(APIErrorCodes.UNABLE_TO_COPY_DATASET_CONTENT, e, ExceptionContext.build().put("id", dataSetId))); on(HttpStatus.OK, HttpStatus.BAD_REQUEST).then((httpRequestBase, httpResponse) -> { try { // we transfer status code and content type return new HttpResponse(httpResponse.getStatusLine().getStatusCode(), // IOUtils.toString(httpResponse.getEntity().getContent()), // httpResponse.getStatusLine().getStatusCode() == HttpStatus.BAD_REQUEST.value() ? // APPLICATION_JSON_VALUE : TEXT_PLAIN_VALUE); } catch (IOException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } finally { httpRequestBase.releaseConnection(); } }); }
From source file:models.Pagination.java
private URI createReference(final String path, final int limit, final int offset, final Map<String, String> conditions) { final URIBuilder uriBuilder = new URIBuilder(); uriBuilder.setPath(path);//from w ww. j av a2 s .co m for (Map.Entry<String, String> entry : conditions.entrySet()) { uriBuilder.addParameter(entry.getKey(), entry.getValue()); } uriBuilder.addParameter("limit", String.valueOf(limit)); uriBuilder.addParameter("offset", String.valueOf(offset)); try { return uriBuilder.build(); } catch (final URISyntaxException e) { throw new RuntimeException("Failed building uri", e); } }
From source file:com.gsma.mobileconnect.impl.ParseDiscoveryRedirectTest.java
@Test public void parseDiscoveryRedirect_withUnexpectedMccMnc_shouldReturnEmptyDetails() throws URISyntaxException { // GIVEN/*from www . jav a 2s .co m*/ URIBuilder builder = new URIBuilder("http://localhost/redirect"); builder.addParameter(MCC_MNC_PARAMETER, "random-string"); IDiscovery discovery = Factory.getDiscovery(null, null); CaptureParsedDiscoveryRedirect captureParsedDiscoveryRedirect = new CaptureParsedDiscoveryRedirect(); // WHEN discovery.parseDiscoveryRedirect(builder.build().toString(), captureParsedDiscoveryRedirect); // THEN ParsedDiscoveryRedirect parsedDiscoveryRedirect = captureParsedDiscoveryRedirect .getParsedDiscoveryRedirect(); assertNull(parsedDiscoveryRedirect.getSelectedMCC()); assertNull(parsedDiscoveryRedirect.getSelectedMNC()); assertNull(parsedDiscoveryRedirect.getEncryptedMSISDN()); assertFalse(parsedDiscoveryRedirect.hasMCCAndMNC()); }