Package org.apache.http

Examples of org.apache.http.HttpResponse


    HttpParams params = new BasicHttpParams();
    params.setParameter("http.default-headers", headers);

    HttpClient httpclient = new DefaultHttpClient(params);
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/capturing/1911");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
    String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
    assertEquals("/capturing/1911", payLoad);
  }
View Full Code Here


    HttpParams params = new BasicHttpParams();
    params.setParameter("http.default-headers", headers);

    HttpClient httpclient = new DefaultHttpClient(params);
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/capturing/r1911");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(404, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("Not Found", response.getStatusLine().getReasonPhrase());
    String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
    assertEquals("Requested URL: /capturing/r1911 was not found", payLoad);
  }
View Full Code Here

  }

  private void doKeepAliveRequestTest(DefaultHttpClient httpclient)
  throws IOException, ClientProtocolException {
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
    assertEquals(5, response.getAllHeaders().length);
    String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
    assertEquals(expectedPayload, payLoad);
  }
View Full Code Here

  public void HTTP_1_0_noConnectionHeaderTest() throws ClientProtocolException, IOException {
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, new ProtocolVersion("HTTP", 1, 0));
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
    assertEquals(5, response.getAllHeaders().length);
    String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
    assertEquals(expectedPayload, payLoad);
  }
View Full Code Here

  @Test
  public void httpExceptionTest() throws ClientProtocolException, IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/throw");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(500, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("Internal Server Error", response.getStatusLine().getReasonPhrase());
    assertEquals(5, response.getAllHeaders().length);
    String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
    assertEquals("exception message", payLoad);
  }
View Full Code Here

  @Test
  public void asyncHttpExceptionTest() throws ClientProtocolException, IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/async_throw");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(500, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("Internal Server Error", response.getStatusLine().getReasonPhrase());
    assertEquals(5, response.getAllHeaders().length);
    String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
    assertEquals("exception message", payLoad);
  }
View Full Code Here

  @Test
  public void staticFileRequestTest() throws ClientProtocolException, IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/src/test/resources/test.txt");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
    assertEquals(7, response.getAllHeaders().length);
    String payLoad = convertStreamToString(response.getEntity().getContent()).trim();
    assertEquals("test.txt", payLoad);
  }
View Full Code Here

  @Test
  public void pictureStaticFileRequestTest() throws ClientProtocolException, IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/src/test/resources/n792205362_2067.jpg");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
    assertEquals(7, response.getAllHeaders().length);
    assertEquals("54963", response.getFirstHeader("Content-Length").getValue());
    assertEquals("image/jpeg", response.getFirstHeader("Content-Type").getValue());
    assertNotNull(response.getFirstHeader("Last-Modified"));
  }
View Full Code Here

 
  @Test
  public void pictureStaticLargeFileRequestTest() throws ClientProtocolException, IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/src/test/resources/f4_impact_1_original.jpg");
    HttpResponse response = httpclient.execute(httpget);

    assertNotNull(response);
    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());
    assertEquals(7, response.getAllHeaders().length);
    //assertEquals("2145094", response.getFirstHeader("Content-Length").getValue()); // my mb says 2145066, imac says 2145094
    assertEquals("image/jpeg", response.getFirstHeader("Content-Type").getValue());
    assertNotNull(response.getFirstHeader("Last-Modified"));
    // TODO RS 101026 Verify that the actual body/entity is 2145094 bytes big (when we have support for "large" file)
  }
View Full Code Here

  @Test
  public void noBodyRequest() throws ClientProtocolException, IOException {
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet("http://localhost:" + PORT + "/no_body");
    HttpResponse response = httpclient.execute(httpget);
    List<String> expectedHeaders = Arrays.asList(new String[] {"Server", "Date", "Content-Length", "Connection"});

    assertEquals(200, response.getStatusLine().getStatusCode());
    assertEquals(new ProtocolVersion("HTTP", 1, 1), response.getStatusLine().getProtocolVersion());
    assertEquals("OK", response.getStatusLine().getReasonPhrase());

    assertEquals(expectedHeaders.size(), response.getAllHeaders().length);

    for (String header : expectedHeaders) {
      assertTrue(response.getFirstHeader(header) != null);
    }

    assertEquals("", convertStreamToString(response.getEntity().getContent()).trim());
    assertEquals("0", response.getFirstHeader("Content-Length").getValue());
  }
View Full Code Here

TOP

Related Classes of org.apache.http.HttpResponse

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.