org.apache.hc.client5.http.classic.methods.HttpUriRequest Java Examples

The following examples show how to use org.apache.hc.client5.http.classic.methods.HttpUriRequest. 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: DemoIntegrationAT.java    From n2o-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Проверка отдачи статики
 */
@Test
@Order(1)
public void checkStaticContent() throws IOException {
    HttpUriRequest request = new HttpGet("http://localhost:" + port + "/index.html");
    HttpResponse httpResponse = HttpClientBuilder.create().build().execute(request);
    assertThat(httpResponse.getCode(), equalTo(HttpStatus.SC_OK));
}
 
Example #2
Source File: Hc5HttpUtils.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * Create an HttpMethod.
 * 
 * @param url URL of the request.
 * @param properties Properties to add to the request.
 * @param canUseGetMethod Flag indicating if a GET method can be used.
 * @return HttpMethod.
 */
public static HttpUriRequest createMethod(
    String url,
    Map<String, String> properties,
    boolean canUseGetMethod) {
  try {
    if (canUseGetMethod) {
      return createHttpGetMethod(url, properties);
    }
    return createHttpPostMethod(url, properties);
  } catch (URISyntaxException e) {
    log.error("Invalid URL {}: {}", url, e.getMessage());
    return null;
  }
}
 
Example #3
Source File: Hc5HttpServer.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * Send a POST request to the Tool Server.
 * 
 * @param path Path on the tool server.
 * @param properties Request properties.
 * @param manager Response manager.
 * @throws APIException Exception thrown by the API.
 */
@Override
public void sendPost(
    String              path,
    Map<String, String> properties,
    ResponseManager     manager) throws APIException {

  int count = 0;
  int statusCode = HttpStatus.SC_SEE_OTHER;
  String url = baseUrl + path;
  while (count < MAX_ATTEMPTS) {

    // Wait if it's not the first attempt
    count++;
    if (count > 1) {
      waitBeforeRetrying(count);
    }

    // Perform the request
    try {
      final HttpUriRequest method = Hc5HttpUtils.createMethod(url,  properties, false);
      final Hc5HttpResponse response = httpClient.execute(method, new Hc5HttpResponseHandler());
      statusCode = response.status;
      if (statusCode == HttpStatus.SC_OK) {
        if (manager != null) {
          manager.manageResponse(response.inputStream);
        }
        return;
      }
    } catch (IOException e) {
      log.error("IOException (" + url + "): " + e.getMessage());
    }
  }
  throw new APIException("POST returned " + statusCode);
}
 
Example #4
Source File: Hc5HttpServer.java    From wpcleaner with Apache License 2.0 5 votes vote down vote up
/**
 * Send a GET request to the Tool Server.
 * 
 * @param path Path on the tool server.
 * @param manager Response manager.
 * @throws APIException Exception thrown by the API.
 */
@Override
public void sendGet(
    String          path,
    ResponseManager manager) throws APIException {

  int count = 0;
  int statusCode = HttpStatus.SC_SEE_OTHER;
  String url = baseUrl + path;
  while (count < MAX_ATTEMPTS) {

    // Wait if it's not the first attempt
    count++;
    if (count > 1) {
      waitBeforeRetrying(count);
    }

    // Perform the request
    try {
      final HttpUriRequest method = Hc5HttpUtils.createMethod(url, null, true);
      final Hc5HttpResponse response = httpClient.execute(method, new Hc5HttpResponseHandler());
      statusCode = response.status;
      if (statusCode == HttpStatus.SC_OK) {
        if (manager != null) {
          manager.manageResponse(response.inputStream);
        }
        return;
      }
    } catch (IOException e) {
      log.error("IOException (" + url + "): " + e.getMessage());
    }
  }
  throw new APIException("GET returned " + statusCode);
}
 
Example #5
Source File: Http5FileObject.java    From commons-vfs with Apache License 2.0 2 votes vote down vote up
/**
 * Execute the request using the given {@code httpRequest} and return a {@code ClassicHttpResponse} from the execution.
 *
 * @param httpRequest {@code HttpUriRequest} object
 * @return {@code ClassicHttpResponse} from the execution
 * @throws IOException if IO error occurs
 */
protected ClassicHttpResponse executeHttpUriRequest(final HttpUriRequest httpRequest) throws IOException {
    final CloseableHttpClient httpClient = (CloseableHttpClient) getAbstractFileSystem().getHttpClient();
    final HttpClientContext httpClientContext = getAbstractFileSystem().getHttpClientContext();
    return httpClient.execute(httpRequest, httpClientContext);
}