List of usage examples for org.apache.http.client.utils URIBuilder build
public URI build() throws URISyntaxException
From source file:pl.raszkowski.sporttrackersconnector.rest.RESTUriBuilder.java
public URI build(String resourcePath, GetParameters getParameters) { try {//from w w w.j a va 2s . c o m URIBuilder uriBuilder = new URIBuilder(resourcePath); if (getParameters.hasParameters()) { uriBuilder.setCustomQuery(getParameters.getCustomQuery()); } return uriBuilder.build(); } catch (URISyntaxException e) { LOG.error("Cannot build URI for resourcePath = {}.", resourcePath); throw new ConnectorException(String.format(CANNOT_BUILD_URI_ERROR_MESSAGE, resourcePath), e); } }
From source file:com.ny.apps.executor.TencentWeiboOAuth2.java
private URI prepareGetUrl() { URI uri = null;//from w w w .ja v a 2 s. co m List<NameValuePair> nvps = new ArrayList<NameValuePair>(); NameValuePair clientId = new BasicNameValuePair("client_id", APPKEY); NameValuePair responseType = new BasicNameValuePair("response_type", "code"); NameValuePair redirectURI = new BasicNameValuePair("redirect_uri", "http://www.smiletony.com"); nvps.add(clientId); nvps.add(responseType); nvps.add(redirectURI); URIBuilder uriBuilder; try { uriBuilder = new URIBuilder("https://open.t.qq.com/cgi-bin/oauth2/authorize"); uriBuilder.addParameters(nvps); uri = uriBuilder.build(); } catch (URISyntaxException e) { e.printStackTrace(); } return uri; }
From source file:org.eclipse.packagedrone.testing.server.channel.UploadApiV3Test.java
protected CloseableHttpResponse upload(final URIBuilder uri, final File file) throws IOException, URISyntaxException { final HttpPut http = new HttpPut(uri.build()); final String encodedAuth = Base64.getEncoder() .encodeToString(uri.getUserInfo().getBytes(StandardCharsets.ISO_8859_1)); http.setHeader(HttpHeaders.AUTHORIZATION, "Basic " + encodedAuth); http.setEntity(new FileEntity(file)); return httpclient.execute(http); }
From source file:ch.asadzia.cognitive.EmotionDetect.java
public ServiceResult process() { HttpClient httpclient = HttpClients.createDefault(); try {// w ww . j a va 2 s . c o m URIBuilder builder = new URIBuilder("https://api.projectoxford.ai/emotion/v1.0/recognize"); URI uri = builder.build(); HttpPost request = new HttpPost(uri); request.setHeader("Content-Type", "application/octet-stream"); request.setHeader("Ocp-Apim-Subscription-Key", apikey); // Request body FileEntity reqEntity = new FileEntity(imageData); request.setEntity(reqEntity); HttpResponse response = httpclient.execute(request); HttpEntity entity = response.getEntity(); if (entity != null) { String responseStr = EntityUtils.toString(entity); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { System.err.println(responseStr); return null; } JSONArray jsonArray = (JSONArray) new JSONParser().parse(responseStr); JSONObject jsonObject = (JSONObject) jsonArray.get(0); HashMap<char[], Double> scores = (HashMap) jsonObject.get("scores"); Map.Entry<char[], Double> maxEntry = null; for (Map.Entry<char[], Double> entry : scores.entrySet()) { System.out.println("Key = " + entry.getKey() + ", Value = " + entry.getValue()); if (maxEntry == null || entry.getValue().compareTo(maxEntry.getValue()) > 0) { maxEntry = entry; } } Object key = maxEntry.getKey(); String winningEmotionName = (String) key; ServiceResult result = new ServiceResult(translateEmotion(winningEmotionName), winningEmotionName); System.out.println(responseStr); return result; } } catch (Exception e) { System.err.println(e.toString()); } return null; }
From source file:teletype.model.vk.Auth.java
private URI getUri(URIBuilder uriBuilder) { URI uri = null;// w w w. ja v a2 s . com try { uri = uriBuilder.build(); } catch (URISyntaxException e) { e.printStackTrace(); } return uri; }
From source file:fichiercentraltheses.PersonXMLCaller.java
public String callForXMLResponse() throws URISyntaxException, IOException { HttpClient httpclient = new DefaultHttpClient(); URIBuilder builder = new URIBuilder(); builder.setScheme("http").setHost("www.theses.fr").setPath("/personnes/").setParameter("q", "levallois") .setParameter("format", "xml"); URI uri = builder.build(); HttpGet httpget = new HttpGet(uri); // HttpGet httpget = new HttpGet("http://ws.seloger.com/search.xml?ci=690381,690382,690383,690387&idqfix=1&idtt=2&idtypebien=1&tri=d_dt_crea"); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity == null) { System.out.println("empty response to API call"); }/* w w w .ja v a 2 s .c om*/ String responseString = EntityUtils.toString(entity); System.out.println(responseString); return responseString; }
From source file:org.apache.ambari.view.internal.actor.repository.Scanner.java
private void scan() { log().info("Scanning URL '{}' for new packages.", url); Optional<Date> lastScannedTs = packageService.getLastScannedTimestamp(name); Long lastScanned = lastScannedTs.map(Date::getTime).orElse(0L); URI uri = null;/*w w w .j a v a 2s . c o m*/ try { URIBuilder builder = new URIBuilder(url); builder.addParameter("after", String.valueOf(lastScanned)); uri = builder.build(); } catch (URISyntaxException e) { throw new RestClientException("URL Syntax error", e); } ApplicationsWrapper wrapper = ws.getForObject(uri, ApplicationsWrapper.class); packageService.updateApplications(wrapper.getApplications(), name); // Do Something scheduleRescanMessage(); }
From source file:ca.islandora.fcrepo.client.FcrepoClient.java
@Override public IFcrepoResponse createTransaction() throws FcrepoOperationFailedException { try {//from w ww.j a v a 2s.c o m URIBuilder uriBuilder = new URIBuilder(baseUri); uriBuilder.setPath(uriBuilder.getPath() + "/fcr:tx"); final String uri = uriBuilder.build().toString(); final IFcrepoRequest request = new CreateResourceRequest(httpClient, uri); return request.execute(); } catch (URISyntaxException ex) { throw new FcrepoOperationFailedException(null, -1, ex.getMessage()); } }
From source file:ca.islandora.fcrepo.client.FcrepoClient.java
@Override public IFcrepoResponse extendTransaction(final String uri) throws FcrepoOperationFailedException { try {/*from ww w.j a va 2s. c om*/ URIBuilder uriBuilder = new URIBuilder(uri); uriBuilder.setPath(uriBuilder.getPath() + "/fcr:tx"); 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:org.talend.dataprep.api.service.command.folder.CreateChildFolder.java
private HttpRequestBase onExecute(final String parentId, final String path) { try {//from w w w. java 2 s. com URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/folders"); uriBuilder.addParameter("parentId", parentId); uriBuilder.addParameter("path", path); return new HttpPut(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }