Search in sources :

Example 96 with WebTarget

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

the class InterceptorGzipTest method testGzipInterceptorOnServerandClient.

@Test
public void testGzipInterceptorOnServerandClient() throws IOException {
    client().register(GZIPReaderTestInterceptor.class).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));
    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 97 with WebTarget

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

the class BasicClientTest method testSyncClientInvocationErrorResponse.

@Test
public void testSyncClientInvocationErrorResponse() throws InterruptedException, ExecutionException {
    final WebTarget errorResource = target().path("resource").path("error");
    Response r1 = errorResource.request().get();
    assertEquals(404, r1.getStatus());
    assertEquals("error", r1.readEntity(String.class));
    try {
        errorResource.request().get(String.class);
        fail("ExecutionException expected.");
    } catch (WebApplicationException ex) {
        final Response r = ex.getResponse();
        assertEquals(404, r.getStatus());
        assertEquals("error", r.readEntity(String.class));
    }
    try {
        target().path("resource").path("errorlist").request().get(new GenericType<List<String>>() {
        });
        fail("ExecutionException expected.");
    } catch (WebApplicationException ex) {
        final Response r = ex.getResponse();
        assertEquals(404, r.getStatus());
        assertEquals("error", r.readEntity(String.class));
    }
}
Also used : Response(javax.ws.rs.core.Response) WebApplicationException(javax.ws.rs.WebApplicationException) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 98 with WebTarget

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

the class BufferingTest method makeRequest.

private void makeRequest(ClientConfig cc, String entity, String expected) {
    Client client = ClientBuilder.newClient(cc);
    WebTarget target = client.target(UriBuilder.fromUri(getBaseUri()).path("resource").build());
    Response response = target.request().post(Entity.entity(entity, MediaType.TEXT_PLAIN_TYPE));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(expected, response.readEntity(String.class));
}
Also used : Response(javax.ws.rs.core.Response) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 99 with WebTarget

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

the class BufferingTest method testWithChunkEncodingPerRequest.

/**
     * Tests that {@link org.glassfish.jersey.client.ClientProperties#REQUEST_ENTITY_PROCESSING} can be defined
     * per request with different values.
     */
private void testWithChunkEncodingPerRequest(ClientConfig cc) {
    cc.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.CHUNKED);
    cc.property(ClientProperties.CHUNKED_ENCODING_SIZE, 3000);
    Client client = ClientBuilder.newClient(cc);
    WebTarget target = client.target(UriBuilder.fromUri(getBaseUri()).path("resource").build());
    String entity = getVeryLongString();
    Response response = target.request().post(Entity.entity(entity, MediaType.TEXT_PLAIN_TYPE));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("chunked", response.readEntity(String.class));
    response = target.property(ClientProperties.REQUEST_ENTITY_PROCESSING, RequestEntityProcessing.BUFFERED).request().post(Entity.entity(entity, MediaType.TEXT_PLAIN_TYPE));
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals(String.valueOf(entity.length()), response.readEntity(String.class));
}
Also used : Response(javax.ws.rs.core.Response) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client)

Example 100 with WebTarget

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

the class ClientPreInitTest method testReusingPreinitializedConfig.

@Test
public void testReusingPreinitializedConfig() {
    Client client = ClientBuilder.newClient();
    client.register(TestReader.class);
    final WebTarget target = client.target(super.getBaseUri()).path("resource");
    target.register(MyResponseFilter.class);
    ((JerseyWebTarget) target).preInitialize();
    assertTrue(TestReader.initialized);
    final WebTarget childTarget = target.path("child");
    final Response response = childTarget.request().get();
    checkResponse(response, "child:<null>");
    final Response resourceResponse = target.request().get();
    checkResponse(resourceResponse, "resource:<null>");
}
Also used : Response(javax.ws.rs.core.Response) JerseyWebTarget(org.glassfish.jersey.client.JerseyWebTarget) JerseyWebTarget(org.glassfish.jersey.client.JerseyWebTarget) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) JerseyClient(org.glassfish.jersey.client.JerseyClient) 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