List of usage examples for org.apache.http.client.utils URIBuilder URIBuilder
public URIBuilder(final URI uri)
From source file:ninja.NinjaApiDocTest.java
private URIBuilder build(String relativePath, Map<String, String> parameters) { URIBuilder uriBuilder = new URIBuilder(ninjaTestServer.getServerAddressAsUri()).setPath(relativePath); addParametersToURI(parameters, uriBuilder); return uriBuilder; }
From source file:org.talend.dataprep.api.service.command.preparation.PreparationMove.java
private HttpRequestBase onExecute(String id, String folder, String destination, String newName) { try {// w ww.j a v a 2 s . c o m URIBuilder uriBuilder = new URIBuilder(preparationServiceUrl + "/preparations/" + id + "/move"); if (StringUtils.isNotBlank(folder)) { uriBuilder.addParameter("folder", folder); } if (StringUtils.isNotBlank(destination)) { uriBuilder.addParameter("destination", destination); } if (StringUtils.isNotBlank(newName)) { uriBuilder.addParameter("newName", newName); } return new HttpPut(uriBuilder.build()); } catch (URISyntaxException e) { throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e); } }
From source file:com.jkoolcloud.tnt4j.streams.fields.ActivityCacheTest.java
private static URI makeURI() { try {// w ww.ja v a 2s . c o m URIBuilder uriBuilder = new URIBuilder("http://localhost"); // NON-NLS uriBuilder.setHost("localhost"); // NON-NLS uriBuilder.setPort(TEST_PORT); URI url = uriBuilder.build(); return url; } catch (Exception e) { return null; } }
From source file:org.apache.stratos.mock.iaas.client.MockIaasApiClient.java
public boolean isMockIaaSReady() { try {/* w w w . j ava 2 s . com*/ URI uri = new URIBuilder(endpoint + INIT_CONTEXT).build(); HttpResponse response = restClient.doGet(uri); return response != null && response.getStatusCode() == 200; } catch (Exception e) { String message = "Could not check whether mock-iaas is active"; throw new RuntimeException(message, e); } }
From source file:com.griddynamics.jagger.invoker.http.ApacheHttpInvoker.java
@Override protected HttpRequestBase getHttpMethod(HttpRequestBase query, String endpoint) { try {/*from w ww.j a v a 2 s . c o m*/ if (query.getURI() == null) { query.setURI(URI.create(endpoint)); return query; } else { URIBuilder uriBuilder = new URIBuilder(URI.create(endpoint)); uriBuilder.setQuery(query.getURI().getQuery()); uriBuilder.setFragment(query.getURI().getFragment()); uriBuilder.setUserInfo(query.getURI().getUserInfo()); if (!query.getURI().getPath().isEmpty()) { uriBuilder.setPath(query.getURI().getPath()); } query.setURI(uriBuilder.build()); return query; } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:com.michaeljones.httpclient.apache.ApacheMethodClient.java
@Override public String GetStringContent(String url, List<Pair<String, String>> queryParams) { try {/*from w w w . j a va2 s .c o m*/ HttpGet httpget = new HttpGet(url); // The Hadoop Web HDFS only serves json, but no harm in being explicit. httpget.setHeader("accept", "application/json"); URIBuilder builder = new URIBuilder(url); for (Pair<String, String> queryParam : queryParams) { builder.addParameter(queryParam.getFirst(), queryParam.getSecond()); } httpget.setURI(builder.build()); CloseableHttpResponse response = clientImpl.execute(httpget); try { HttpEntity entity = response.getEntity(); return EntityUtils.toString(entity); } finally { // I believe this releases the connection to the client pool, but does not // close the connection. response.close(); } } catch (IOException | URISyntaxException ex) { throw new RuntimeException("Apache method get string content: " + ex.getMessage()); } }
From source file:io.cloudslang.content.httpclient.consume.FinalLocationConsumerTest.java
@Test public void consumeWithNoRedirects() throws URISyntaxException { URI uri = new URIBuilder(URI).build(); Map<String, String> returnResult = new HashMap<>(); finalLocationConsumer.setUri(uri).setTargetHost(null).setRedirectLocations(null).consume(returnResult); assertEquals(URI, returnResult.get(FINAL_LOCATION)); }
From source file:net.oneandone.shared.artifactory.SearchByChecksum.java
URI buildSearchURI(final String repositoryName, final Sha1 sha1) throws IllegalArgumentException { final URIBuilder uriBuilder = new URIBuilder(baseUri.resolve("api/search/checksum")) .addParameter("repos", repositoryName).addParameter("sha1", sha1.toString()); return Utils.toUri(uriBuilder, "Could not build URI from " + baseUri + " using repositoryName=" + repositoryName + ", sha1=" + sha1); }
From source file:org.talend.dataprep.api.service.command.preparation.PreparationReorderStep.java
private HttpRequestBase onExecute(final String preparationId, final String stepId, final String parentStepId) { try {// www. j a v a 2 s. com URIBuilder builder = new URIBuilder( preparationServiceUrl + "/preparations/" + preparationId + "/steps/" + stepId + "/order"); if (StringUtils.isNotBlank(parentStepId)) { builder.addParameter("parentStepId", parentStepId); } return new HttpPost(builder.build()); } catch (URISyntaxException e) { throw new TDPException(UNEXPECTED_EXCEPTION, e); } }
From source file:org.llorllale.youtrack.api.session.UsernamePassword.java
@Override public Session session() throws AuthenticationException, IOException { try {//w w w . jav a2s . co m final HttpResponse response = this.httpClient .execute(new HttpPost(new URIBuilder(this.youtrackUrl.toString().concat("/user/login")) .setParameter("login", this.username) .setParameter("password", new String(this.password)).build())); //@checkstyle todo there is more branching here if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new AuthenticationException("Invalid credentials."); } final String cookieHeader = "Cookie"; final Cookie cookie = Arrays.asList(response.getAllHeaders()).stream() .filter(header -> "Set-Cookie".equals(header.getName())) .map(header -> new DefaultCookie(cookieHeader, header.getValue().split(";")[0])) .reduce((cookieA, cookieB) -> new DefaultCookie(cookieHeader, cookieA.value().concat("; ").concat(cookieB.value()))) .get(); return new DefaultSession(this.youtrackUrl, cookie); } catch (URISyntaxException e) { throw new IOException(e.getMessage()); } }