Ejemplo n.º 1
0
  @Test
  public void testHead() throws Exception {
    startServer(Resource.class);

    Client client = ClientFactory.newClient();
    WebTarget r = client.target(getUri().path("/").build());

    Response cr = r.path("string").request("text/plain").head();
    assertEquals(200, cr.getStatus());
    assertEquals(MediaType.TEXT_PLAIN_TYPE, cr.getMediaType());
    assertFalse(cr.hasEntity());

    cr = r.path("byte").request("application/octet-stream").head();
    assertEquals(200, cr.getStatus());
    int length = cr.getLength();
    assertNotNull(length);
    // org.glassfish.jersey.server.model.HeadTest
    // TODO Uncomment once we implement outbound message payload buffering for determining proper
    // Content-Length value.
    //        assertEquals(3, length);
    assertEquals(MediaType.APPLICATION_OCTET_STREAM_TYPE, cr.getMediaType());
    assertFalse(cr.hasEntity());

    cr = r.path("ByteArrayInputStream").request("application/octet-stream").head();
    assertEquals(200, cr.getStatus());
    length = cr.getLength();
    assertNotNull(length);
    //        assertEquals(3, length);
    assertEquals(MediaType.APPLICATION_OCTET_STREAM_TYPE, cr.getMediaType());
    assertFalse(cr.hasEntity());
  }
Ejemplo n.º 2
0
 @Test
 public void testFooBarOptions() {
   Response response = target().path(ROOT_PATH).request().header("Accept", "foo/bar").options();
   assertEquals(200, response.getStatus());
   final String allowHeader = response.getHeaderString("Allow");
   _checkAllowContent(allowHeader);
   assertEquals("foo/bar", response.getMediaType().toString());
   assertEquals(0, response.getLength());
 }
 @Test
 public void testGetPomNPM() {
   for (String version : NPM_VERSIONS) {
     String path =
         "/org/nodejs/dist/npm-binaries/" + version + "/npm-binaries-" + version + ".pom";
     Response response = context.client().target(path).request().get();
     assertResponse(path, response, MediaType.APPLICATION_XML);
     assertTrue("Content length " + path, response.getLength() > 0);
     assertSHA1(path, response);
   }
 }
Ejemplo n.º 4
0
  protected <T> T readBody(
      Response r, Message outMessage, Class<T> cls, Type type, Annotation[] anns) {

    if (cls == Response.class) {
      return cls.cast(r);
    }

    int status = r.getStatus();
    if ((status < 200 || status == 204) && r.getLength() <= 0 || status >= 300) {
      return null;
    }
    return ((ResponseImpl) r).doReadEntity(cls, type, anns);
  }