Search in sources :

Example 91 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class ManagedBeanWebAppTest method testExceptionMapper.

/**
     * Test exceptions are properly mapped.
     */
@Test
public void testExceptionMapper() {
    WebTarget singletonTarget = target().path("managedbean/singleton/exception");
    WebTarget perRequestTarget = target().path("managedbean/per-request/exception");
    _testExceptionOutput(singletonTarget, "singleton");
    _testExceptionOutput(perRequestTarget, "per-request");
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 92 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class VariantsTest method testGetLanguageEn.

@Test
public void testGetLanguageEn() throws IOException {
    WebTarget rp = target("/lvr");
    Response r = rp.request().header("Accept-Language", "en").get();
    assertEquals("en", r.readEntity(String.class));
    assertEquals("en", r.getLanguage().toString());
    String vary = r.getHeaderString("Vary");
    assertNotNull(vary);
    assertTrue(!contains(vary, "Accept"));
    assertTrue(contains(vary, "Accept-Language"));
}
Also used : Response(javax.ws.rs.core.Response) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 93 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class ClientTest method testContextHeaders.

@Test
public // Inspired by JERSEY-1502
void testContextHeaders() {
    final WebTarget target = target().path("headers").path("content");
    Invocation.Builder ib;
    Invocation i;
    Response r;
    String reqHeaders;
    ib = target.request("*/*");
    ib.header("custom-header", "custom-value");
    ib.header("content-encoding", "deflate");
    i = ib.build("POST", Entity.entity("aaa", MediaType.WILDCARD_TYPE));
    r = i.invoke();
    reqHeaders = r.readEntity(String.class).toLowerCase();
    for (final String expected : new String[] { "custom-header:[custom-value]", "custom-header:custom-value" }) {
        assertTrue(String.format("Request headers do not contain expected '%s' entry:\n%s", expected, reqHeaders), reqHeaders.contains(expected));
    }
    final String unexpected = "content-encoding";
    assertFalse(String.format("Request headers contains unexpected '%s' entry:\n%s", unexpected, reqHeaders), reqHeaders.contains(unexpected));
    ib = target.request("*/*");
    i = ib.build("POST", Entity.entity("aaa", Variant.mediaTypes(MediaType.WILDCARD_TYPE).encodings("deflate").build().get(0)));
    r = i.invoke();
    final String expected = "content-encoding:[deflate]";
    reqHeaders = r.readEntity(String.class).toLowerCase();
    assertTrue(String.format("Request headers do not contain expected '%s' entry:\n%s", expected, reqHeaders), reqHeaders.contains(expected));
}
Also used : Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 94 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class InterceptorCustomTest method testMoreInterceptorsAndFilter.

@Test
public void testMoreInterceptorsAndFilter() throws IOException {
    WebTarget target = target().path("test");
    Response response = target.request().put(Entity.entity(ENTITY, MediaType.TEXT_PLAIN_TYPE));
    String str = response.readEntity(String.class);
    assertEquals(ENTITY + FROM_RESOURCE, str);
}
Also used : Response(javax.ws.rs.core.Response) WebTarget(javax.ws.rs.client.WebTarget) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 95 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class InterceptorGzipTest method testGzipInterceptorOnlyOnServer.

@Test
public void testGzipInterceptorOnlyOnServer() throws IOException {
    client().register(GZIPWriterTestInterceptor.class);
    WebTarget target = target().path("test");
    String entity = "hello, this is text entity";
    Response response = target.request().put(Entity.entity(entity, MediaType.TEXT_PLAIN_TYPE));
    InputStream is = response.readEntity(InputStream.class);
    GZIPInputStream gzipIs = new GZIPInputStream(is);
    BufferedReader br = new BufferedReader(new InputStreamReader(gzipIs));
    String str = br.readLine();
    assertEquals(entity + FROM_RESOURCE, str);
}
Also used : Response(javax.ws.rs.core.Response) GZIPInputStream(java.util.zip.GZIPInputStream) InputStreamReader(java.io.InputStreamReader) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) WebTarget(javax.ws.rs.client.WebTarget) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

WebTarget (javax.ws.rs.client.WebTarget)1393 Response (javax.ws.rs.core.Response)712 Test (org.junit.Test)702 Client (javax.ws.rs.client.Client)318 JerseyTest (org.glassfish.jersey.test.JerseyTest)297 Invocation (javax.ws.rs.client.Invocation)106 List (java.util.List)76 ProcessingException (javax.ws.rs.ProcessingException)71 Builder (javax.ws.rs.client.Invocation.Builder)71 ClientBuilder (javax.ws.rs.client.ClientBuilder)69 GenericType (javax.ws.rs.core.GenericType)64 ArrayList (java.util.ArrayList)61 IOException (java.io.IOException)59 Message (com.remswork.project.alice.model.support.Message)58 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)58 InputStream (java.io.InputStream)52 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)52 ClientConfig (org.glassfish.jersey.client.ClientConfig)52 Form (javax.ws.rs.core.Form)42 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)42