Java Code Examples for org.apache.http.client.methods.HttpEntityEnclosingRequestBase#setURI()

The following examples show how to use org.apache.http.client.methods.HttpEntityEnclosingRequestBase#setURI() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VrApacheClient.java    From verano-http with MIT License 6 votes vote down vote up
@Override
public final CloseableHttpResponse execute(
    final Dict request
) throws IOException {
    final HttpEntityEnclosingRequestBase base =
        new HttpEntityEnclosingRequestBase() {
            @Override
            public String getMethod() {
                //@checkstyle RequireThisCheck (1 lines)
                return new Method.Of(request).asString();
            }
        };
    final URI uri = new RequestUri.Of(request).uri();
    base.setConfig(this.config);
    base.setURI(uri);
    base.setEntity(new StringEntity(new Body.Of(request).asString()));
    for (final Kvp header : new Headers.Of(request)) {
        base.addHeader(header.key(), header.value());
    }
    return this.origin.get().execute(base);
}
 
Example 2
Source File: HttpClient.java    From aliyun-tsdb-java-sdk with Apache License 2.0 6 votes vote down vote up
public static HttpResponse redirectResponse(HttpResponse httpResponse,
                                            HttpEntityEnclosingRequestBase request,
                                            CloseableHttpAsyncClient httpclient)
        throws ExecutionException, InterruptedException {
    HttpResponse result = null;

    Header[] headers = httpResponse.getHeaders(HttpHeaders.LOCATION);
    for (Header header : headers) {
        if (header.getName().equalsIgnoreCase(HttpHeaders.LOCATION)) {
            String newUrl = header.getValue();
            request.setURI(URI.create(newUrl));
            Future<HttpResponse> future = httpclient.execute(request, null);
            result = future.get();
            break;
        }
    }
    if (result == null) {
        return httpResponse;
    }
    return result;
}
 
Example 3
Source File: P2ResourceITSupport.java    From nexus-repository-p2 with Eclipse Public License 1.0 5 votes vote down vote up
private void prepareRequest(HttpEntityEnclosingRequestBase request, String url, Object body) throws Exception {
  request.setEntity(new ByteArrayEntity(OBJECT_MAPPER.writeValueAsBytes(body), ContentType.APPLICATION_JSON));
  UriBuilder uriBuilder = UriBuilder.fromUri(nexusUrl.toString()).path(url);
  request.setURI(uriBuilder.build());
  String auth = credentials.getUserName() + ":" + credentials.getPassword();
  request.setHeader(HttpHeaders.AUTHORIZATION,
      "Basic " + new String(Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8))));
}
 
Example 4
Source File: ResourceITSupport.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
private void prepareRequest(HttpEntityEnclosingRequestBase request, String url, Object body) throws Exception {
  request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(body), ContentType.APPLICATION_JSON));
  UriBuilder uriBuilder = UriBuilder.fromUri(nexusUrl.toString()).path(url);
  request.setURI(uriBuilder.build());
  String auth = credentials.getUserName() + ":" + credentials.getPassword();
  request.setHeader(HttpHeaders.AUTHORIZATION,
      "Basic " + new String(Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8))));
}
 
Example 5
Source File: RResourceITSupport.java    From nexus-repository-r with Eclipse Public License 1.0 5 votes vote down vote up
private void prepareRequest(HttpEntityEnclosingRequestBase request, String url, Object body) throws Exception {
  request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(body), ContentType.APPLICATION_JSON));
  UriBuilder uriBuilder = UriBuilder.fromUri(nexusUrl.toString()).path(url);
  request.setURI(uriBuilder.build());
  String auth = credentials.getUserName() + ":" + credentials.getPassword();
  request.setHeader(HttpHeaders.AUTHORIZATION,
      "Basic " + new String(Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8))));
}
 
Example 6
Source File: ConanResourceITSupport.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
private void prepareRequest(HttpEntityEnclosingRequestBase request, String url, Object body) throws Exception {
  request.setEntity(new ByteArrayEntity(objectMapper.writeValueAsBytes(body), ContentType.APPLICATION_JSON));
  UriBuilder uriBuilder = UriBuilder.fromUri(nexusUrl.toString()).path(url);
  request.setURI(uriBuilder.build());
  String auth = credentials.getUserName() + ":" + credentials.getPassword();
  request.setHeader(HttpHeaders.AUTHORIZATION,
      "Basic " + new String(Base64.getEncoder().encode(auth.getBytes(StandardCharsets.UTF_8))));
}
 
Example 7
Source File: RestTask.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
private HttpUriRequest requestWithEntity(HttpEntityEnclosingRequestBase request, Uri.Builder uriBuilder) throws UnsupportedEncodingException, URISyntaxException {
    if (params != null) {
        request.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
    }
    request.setURI(new URI(uriBuilder.build().toString()));
    return request;
}
 
Example 8
Source File: ElasticsearchTransport.java    From calcite with Apache License 2.0 5 votes vote down vote up
void closeScroll(Iterable<String> scrollIds) {
  Objects.requireNonNull(scrollIds, "scrollIds");

  // delete current scroll
  final URI uri = URI.create("/_search/scroll");
  // http DELETE with payload
  final HttpEntityEnclosingRequestBase request = new HttpEntityEnclosingRequestBase() {
    @Override public String getMethod() {
      return HttpDelete.METHOD_NAME;
    }
  };

  request.setURI(uri);
  final ObjectNode payload = mapper().createObjectNode();
  // ES2 expects json array for DELETE scroll API
  final ArrayNode array = payload.withArray("scroll_id");

  StreamSupport.stream(scrollIds.spliterator(), false)
      .map(TextNode::new)
      .forEach(array::add);

  try {
    final String json = mapper().writeValueAsString(payload);
    request.setEntity(new StringEntity(json, ContentType.APPLICATION_JSON));
    rawHttp().apply(request);
  } catch (IOException | UncheckedIOException e) {
    LOGGER.warn("Failed to close scroll(s): {}", scrollIds, e);
  }
}
 
Example 9
Source File: HttpMetricNamesHandlerIntegrationTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void tearDownClass() throws Exception {
    URIBuilder builder = new URIBuilder().setScheme("http")
            .setHost("127.0.0.1").setPort(9200)
            .setPath("/metric_metadata/metrics/_query");

    HttpEntityEnclosingRequestBase delete = new HttpEntityEnclosingRequestBase() {
        @Override
        public String getMethod() {
            return "DELETE";
        }
    };
    delete.setURI(builder.build());

    String deletePayload = "{\"query\":{\"match_all\":{}}}";
    HttpEntity entity = new NStringEntity(deletePayload, ContentType.APPLICATION_JSON);
    delete.setEntity(entity);

    HttpClient client = HttpClientBuilder.create().build();
    HttpResponse response = client.execute(delete);
    if(response.getStatusLine().getStatusCode() != 200)
    {
        System.out.println("Couldn't delete index after running tests.");
    }
    else {
        System.out.println("Successfully deleted index after running tests.");
    }
}
 
Example 10
Source File: HttpEventsQueryHandlerIntegrationTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void tearDownClass() throws Exception {
    URIBuilder builder = new URIBuilder().setScheme("http")
            .setHost("127.0.0.1").setPort(9200)
            .setPath("/events/graphite_event/_query");

    HttpEntityEnclosingRequestBase delete = new HttpEntityEnclosingRequestBase() {
        @Override
        public String getMethod() {
            return "DELETE";
        }
    };
    delete.setURI(builder.build());

    String deletePayload = "{\"query\":{\"match_all\":{}}}";
    HttpEntity entity = new NStringEntity(deletePayload, ContentType.APPLICATION_JSON);
    delete.setEntity(entity);

    HttpClient client = HttpClientBuilder.create().build();
    HttpResponse response = client.execute(delete);
    if(response.getStatusLine().getStatusCode() != 200)
    {
        System.out.println("Couldn't delete index after running tests.");
    }
    else {
        System.out.println("Successfully deleted index after running tests.");
    }
}
 
Example 11
Source File: ElasticIOIntegrationTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
private void deleteAllDocuments(String typeToEmpty) throws URISyntaxException, IOException {
    URIBuilder builder = new URIBuilder().setScheme("http")
            .setHost("127.0.0.1").setPort(9200)
            .setPath(typeToEmpty);

    HttpEntityEnclosingRequestBase delete = new HttpEntityEnclosingRequestBase() {
        @Override
        public String getMethod() {
            return "DELETE";
        }
    };
    delete.setURI(builder.build());

    String deletePayload = "{\"query\":{\"match_all\":{}}}";
    HttpEntity entity = new NStringEntity(deletePayload, ContentType.APPLICATION_JSON);
    delete.setEntity(entity);

    HttpClient client = HttpClientBuilder.create().build();
    HttpResponse response = client.execute(delete);
    if(response.getStatusLine().getStatusCode() != 200)
    {
        System.out.println(String.format("Couldn't delete index [%s] after running tests.", typeToEmpty));
    }
    else {
        System.out.println(String.format("Successfully deleted [%s] index after running tests.", typeToEmpty));
    }
}
 
Example 12
Source File: EventElasticSearchIOTest.java    From blueflood with Apache License 2.0 5 votes vote down vote up
@AfterClass
public static void tearDownClass() throws Exception {
    URIBuilder builder = new URIBuilder().setScheme("http")
            .setHost("127.0.0.1").setPort(9200)
            .setPath("/events/graphite_event/_query");

    HttpEntityEnclosingRequestBase delete = new HttpEntityEnclosingRequestBase() {
        @Override
        public String getMethod() {
            return "DELETE";
        }
    };
    delete.setURI(builder.build());

    String deletePayload = "{\"query\":{\"match_all\":{}}}";
    HttpEntity entity = new NStringEntity(deletePayload, ContentType.APPLICATION_JSON);
    delete.setEntity(entity);

    HttpClient client = HttpClientBuilder.create().build();
    HttpResponse response = client.execute(delete);
    if(response.getStatusLine().getStatusCode() != 200)
    {
        System.out.println("Couldn't delete index after running tests.");
    }
    else {
        System.out.println("Successfully deleted index after running tests.");
    }
}