Package com.google.code.http4j

Examples of com.google.code.http4j.Response


  }
 
  protected Response submit(Request request, Metrics parentMetrics) throws InterruptedException,
      IOException, URISyntaxException {
    RequestExecutor executor = new BasicRequestExecutor(connectionManager, cookieCache, responseParser);
    Response response = executor.execute(request);
    LOGGER.debug("Metrics for {} : \r\n{}", request.getURI(), response.getMetrics());
    response.getMetrics().setParentMetrics(parentMetrics);
    return postProcess(request, response);
  }
View Full Code Here


    noEntity = "HTTP/1.0 304 Not Modified\r\nContent-Type:text/html; charset=UTF-8\r\nContent-Length:12\r\n\r\n".getBytes();
  }
 
  @Test
  public void parseIdentity() throws IOException {
    Response response = parser.parse(new ByteArrayInputStream(identity));
    Assert.assertNotNull(response);
    StatusLine statusLine = response.getStatusLine();
    Assert.assertNotNull(statusLine);
    Assert.assertEquals(statusLine.getVersion(), HTTP.HTTP_1_1);
    Assert.assertEquals(statusLine.getStatusCode(), 200);
    Assert.assertEquals(statusLine.getReason(), "OK");
    List<Header> headers = response.getHeaders();
    Assert.assertNotNull(headers);
    Assert.assertEquals(headers.size(), 2);
    int contentLength = Headers.getContentLength(headers);
    Assert.assertEquals(contentLength, 12);
    byte[] entity = response.getEntity();
    Assert.assertEquals(new String(entity), "Hello World!");
    Assert.assertEquals(response.getCharset(), Charset.UTF_8);
  }
View Full Code Here

    Assert.assertEquals(response.getCharset(), Charset.UTF_8);
  }
 
  @Test
  public void parseChunked() throws IOException {
    Response response = parser.parse(new ByteArrayInputStream(chunked));
    Assert.assertNotNull(response);
    StatusLine statusLine = response.getStatusLine();
    Assert.assertNotNull(statusLine);
    Assert.assertEquals(statusLine.getVersion(), HTTP.HTTP_1_1);
    Assert.assertEquals(statusLine.getStatusCode(), 200);
    Assert.assertEquals(statusLine.getReason(), "OK");
    List<Header> headers = response.getHeaders();
    Assert.assertNotNull(headers);
    Assert.assertEquals(headers.size(), 2);
    Assert.assertTrue(Headers.isChunked(headers));
    byte[] entity = response.getEntity();
    Assert.assertEquals(new String(entity), "Hello World!-from http4j.author:guilin.zhang@hotmail.com");
    Assert.assertEquals(response.getCharset(), Charset.GBK);
  }
View Full Code Here

    Assert.assertEquals(response.getCharset(), Charset.GBK);
  }
 
  @Test
  public void parseChunkedWithTrailers() throws IOException {
    Response response = parser.parse(new ByteArrayInputStream(chunkedWithTrailers));
    Assert.assertNotNull(response);
    StatusLine statusLine = response.getStatusLine();
    Assert.assertNotNull(statusLine);
    Assert.assertEquals(statusLine.getVersion(), HTTP.HTTP_1_1);
    Assert.assertEquals(statusLine.getStatusCode(), 200);
    Assert.assertEquals(statusLine.getReason(), "OK");
    List<Header> headers = response.getHeaders();
    Assert.assertNotNull(headers);
    Assert.assertEquals(headers.size(), 3);
    Assert.assertTrue(Headers.isChunked(headers));
    Assert.assertEquals(Headers.getValueByName(headers, Headers.CONNECTION), "Keep-Alive");
    byte[] entity = response.getEntity();
    Assert.assertEquals(new String(entity), "Hello World!-from http4j.author:guilin.zhang@hotmail.com");
    Assert.assertEquals(response.getCharset(), Charset.GBK);
  }
View Full Code Here

    Assert.assertEquals(response.getCharset(), Charset.GBK);
  }
 
  @Test
  public void parseNoEntity() throws IOException {
    Response response = parser.parse(new ByteArrayInputStream(noEntity));
    Assert.assertNotNull(response);
    StatusLine statusLine = response.getStatusLine();
    Assert.assertNotNull(statusLine);
    Assert.assertEquals(statusLine.getVersion(), HTTP.HTTP_1_0);
    Assert.assertEquals(statusLine.getStatusCode(), 304);
    Assert.assertEquals(statusLine.getReason(), "Not Modified");
    List<Header> headers = response.getHeaders();
    Assert.assertNotNull(headers);
    Assert.assertEquals(headers.size(), 2);
    int contentLength = Headers.getContentLength(headers);
    Assert.assertEquals(contentLength, 12);
    Assert.assertNull(response.getEntity());
    Assert.assertEquals(response.getCharset(), Charset.UTF_8);
  }
View Full Code Here

  public Response execute(Request request) throws InterruptedException, IOException {
    ThreadLocalMetricsRecorder.getInstance().reset();
    Connection connection = connectionManager.acquire(request.getHost());
    try {
      send(connection.getOutputStream(), request);
      Response response = receive(connection.getInputStream());
      afterResponse(request, response, connection);
      return response;
    } catch (IOException e) {
      connection.close();
      throw e;
View Full Code Here

    response.setMetrics(ThreadLocalMetricsRecorder.getInstance().captureMetrics());
    cookieCache.set(request.getURI(), response.getHeaders());
  }

  protected Response receive(InputStream in) throws IOException {
    Response response = responseParser.parse(in);
    ThreadLocalMetricsRecorder.getInstance().getResponseTimer().stop();
    return response;
  }
View Full Code Here

    client = new BasicClient().followRedirect(true);
  }
 
  @Test
  public void getSourceMetrics() throws InterruptedException, IOException, URISyntaxException {
    Response response = client.get("http://www.sun.com");// redirect to oracle.com
    Metrics oracle_us_sun_index = response.getMetrics();
    LOGGER.debug(oracle_us_sun_index.toString());
    Metrics oracle_us_sun = oracle_us_sun_index.getParentMetrics();
    LOGGER.debug(oracle_us_sun.toString());
    Assert.assertNotNull(oracle_us_sun);
    Metrics sun = oracle_us_sun.getParentMetrics();
View Full Code Here

    noEntity = "HTTP/1.0 304 Not Modified\r\nContent-Type:text/html; charset=UTF-8\r\nContent-Length:12\r\n\r\n".getBytes();
  }
 
  @Test
  public void parseIdentity() throws IOException {
    Response response = parser.parse(new ByteArrayInputStream(identity));
    Assert.assertNotNull(response);
    StatusLine statusLine = response.getStatusLine();
    Assert.assertNotNull(statusLine);
    Assert.assertEquals(statusLine.getVersion(), HTTP.HTTP_1_1);
    Assert.assertEquals(statusLine.getStatusCode(), 200);
    Assert.assertEquals(statusLine.getReason(), "OK");
    List<Header> headers = response.getHeaders();
    Assert.assertNotNull(headers);
    Assert.assertEquals(headers.size(), 2);
    int contentLength = Headers.getContentLength(headers);
    Assert.assertEquals(contentLength, 12);
    byte[] entity = response.getEntity();
    Assert.assertEquals(new String(entity), "Hello World!");
    Assert.assertEquals(response.getCharset(), Charset.UTF_8);
  }
View Full Code Here

    Assert.assertEquals(response.getCharset(), Charset.UTF_8);
  }
 
  @Test
  public void parseChunked() throws IOException {
    Response response = parser.parse(new ByteArrayInputStream(chunked));
    Assert.assertNotNull(response);
    StatusLine statusLine = response.getStatusLine();
    Assert.assertNotNull(statusLine);
    Assert.assertEquals(statusLine.getVersion(), HTTP.HTTP_1_1);
    Assert.assertEquals(statusLine.getStatusCode(), 200);
    Assert.assertEquals(statusLine.getReason(), "OK");
    List<Header> headers = response.getHeaders();
    Assert.assertNotNull(headers);
    Assert.assertEquals(headers.size(), 2);
    Assert.assertTrue(Headers.isChunked(headers));
    byte[] entity = response.getEntity();
    Assert.assertEquals(new String(entity), "Hello World!-from http4j.author:guilin.zhang@hotmail.com");
    Assert.assertEquals(response.getCharset(), Charset.GBK);
  }
View Full Code Here

TOP

Related Classes of com.google.code.http4j.Response

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.