Java Code Examples for org.eclipse.jetty.http.HttpStatus#getCode()

The following examples show how to use org.eclipse.jetty.http.HttpStatus#getCode() . 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: ApplicationTest.java    From rest-utils with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("SameParameterValue")
private HttpStatus.Code makeGetRequest(final TestApp app, final String path) throws Exception {
  final HttpGet httpget = new HttpGet(app.getListeners().get(0).toString() + path);

  try (CloseableHttpClient httpClient = HttpClients.createDefault();
      CloseableHttpResponse response = httpClient.execute(httpget)) {
    return HttpStatus.getCode(response.getStatusLine().getStatusCode());
  }
}
 
Example 2
Source File: ApplicationGroupTest.java    From rest-utils with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("SameParameterValue")
private HttpStatus.Code makeGetRequest(final String path) throws Exception {
  final HttpGet httpget = new HttpGet(server.getListeners().get(0).toString() + path);

  try (CloseableHttpClient httpClient = HttpClients.createDefault();
       CloseableHttpResponse response = httpClient.execute(httpget)) {
    return HttpStatus.getCode(response.getStatusLine().getStatusCode());
  }
}
 
Example 3
Source File: TestCustomizeThreadPool.java    From rest-utils with Apache License 2.0 4 votes vote down vote up
/**
 * Simulate multiple HTTP clients sending HTTP requests same time. Each client will send one HTTP request.
 * The requests will be put in queue if the number of clients are more than the working threads.
 * */
@SuppressWarnings("SameParameterValue")
private void makeConcurrentGetRequests(String uri, int numThread, TestCustomizeThreadPoolApplication app) throws Exception {
  Thread[] threads = new Thread[numThread];
  for(int i = 0; i < numThread; i++) {
    threads[i] = new Thread() {
      public void run() {
        HttpGet httpget = new HttpGet(uri);
        CloseableHttpClient httpclient = HttpClients.createDefault();
        CloseableHttpResponse response = null;
        try {
          response = httpclient.execute(httpget);
          HttpStatus.Code statusCode = HttpStatus.getCode(response.getStatusLine().getStatusCode());
          log.info("Status code {}, reason {} ", statusCode, response.getStatusLine().getReasonPhrase());
          assertThat(statusCode, is(Code.OK));
        } catch (Exception e) {
        } finally {
          try {
            if (response != null) {
              response.close();
            }
            httpclient.close();
          } catch (Exception e) {
          }
        }
      }
    };

    threads[i].start();
  }

  long startingTime = System.currentTimeMillis();
  while(System.currentTimeMillis() - startingTime < 360*1000) {
    log.info("Queue size {}, queue capacity {} ", app.getServer().getQueueSize(), app.getServer().getQueueCapacity());
    assertTrue("Number of jobs in queue is not more than capacity of queue ", app.getServer().getQueueSize() <= app.getServer().getQueueCapacity());
    Thread.sleep(2000);
    if (app.getServer().getQueueSize() == 0)
      break;
  }

  for(int i = 0; i < numThread; i++) {
    threads[i].join();
  }
  log.info("End queue size {}, queue capacity {} ", app.getServer().getQueueSize(), app.getServer().getQueueCapacity());
}