Search in sources :

Example 96 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class DisableContentEncodingTest method testDefaultEncoding.

@Test
public void testDefaultEncoding() {
    ClientConfig cc = new ClientConfig(GZipEncoder.class);
    cc.connectorProvider(new ApacheConnectorProvider());
    Client client = ClientBuilder.newClient(cc);
    WebTarget r = client.target(getBaseUri());
    String enc = r.request().get().readEntity(String.class);
    assertEquals("gzip,deflate", enc);
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 97 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class CachingConnectorProviderTest method testCachingConnector.

@Test
public void testCachingConnector() {
    final ReferenceCountingNullConnector connectorProvider = new ReferenceCountingNullConnector();
    final CachingConnectorProvider cachingConnectorProvider = new CachingConnectorProvider(connectorProvider);
    final ClientConfig configuration = new ClientConfig().connectorProvider(cachingConnectorProvider).getConfiguration();
    Client client1 = ClientBuilder.newClient(configuration);
    try {
        client1.target(UriBuilder.fromUri("/").build()).request().get();
    } catch (ProcessingException ce) {
        assertEquals("test", ce.getMessage());
        assertEquals(1, connectorProvider.getCount());
    }
    try {
        client1.target(UriBuilder.fromUri("/").build()).request().async().get();
    } catch (ProcessingException ce) {
        assertEquals("test-async", ce.getMessage());
        assertEquals(1, connectorProvider.getCount());
    }
    Client client2 = ClientBuilder.newClient(configuration);
    try {
        client2.target(UriBuilder.fromUri("/").build()).request().get();
    } catch (ProcessingException ce) {
        assertEquals("test", ce.getMessage());
        assertEquals(1, connectorProvider.getCount());
    }
    try {
        client2.target(UriBuilder.fromUri("/").build()).request().async().get();
    } catch (ProcessingException ce) {
        assertEquals("test-async", ce.getMessage());
        assertEquals(1, connectorProvider.getCount());
    }
}
Also used : ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Example 98 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class EncodingFilterTest method testAcceptEncoding.

@Test
public void testAcceptEncoding() {
    Client client = ClientBuilder.newClient(new ClientConfig(EncodingFilter.class, GZipEncoder.class, DeflateEncoder.class).connectorProvider(new TestConnector()));
    Invocation.Builder invBuilder = client.target(UriBuilder.fromUri("/").build()).request();
    Response r = invBuilder.get();
    assertEquals("deflate,gzip,x-gzip", r.getHeaderString(ACCEPT_ENCODING));
    assertNull(r.getHeaderString(CONTENT_ENCODING));
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) Test(org.junit.Test)

Example 99 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class EncodingFilterTest method testUnsupportedContentEncoding.

@Test
public void testUnsupportedContentEncoding() {
    Client client = ClientBuilder.newClient(new ClientConfig(EncodingFilter.class, GZipEncoder.class, DeflateEncoder.class).property(ClientProperties.USE_ENCODING, "non-gzip").connectorProvider(new TestConnector()));
    Invocation.Builder invBuilder = client.target(UriBuilder.fromUri("/").build()).request();
    Response r = invBuilder.get();
    assertEquals("deflate,gzip,x-gzip", r.getHeaderString(ACCEPT_ENCODING));
    assertNull(r.getHeaderString(CONTENT_ENCODING));
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) Response(javax.ws.rs.core.Response) DeflateEncoder(org.glassfish.jersey.message.DeflateEncoder) Invocation(javax.ws.rs.client.Invocation) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) GZipEncoder(org.glassfish.jersey.message.GZipEncoder) Test(org.junit.Test)

Example 100 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class EncodingFilterTest method testClosingClientResponseStreamRetrievedByValueOnError.

/**
     * Reproducer for JERSEY-2028.
     *
     * @see #testClosingClientResponseStreamRetrievedByResponseOnError
     */
@Test
public void testClosingClientResponseStreamRetrievedByValueOnError() {
    final TestInputStream responseStream = new TestInputStream();
    Client client = ClientBuilder.newClient(new ClientConfig().connectorProvider(new TestConnector() {

        @Override
        public ClientResponse apply(ClientRequest requestContext) throws ProcessingException {
            final ClientResponse responseContext = new ClientResponse(Response.Status.OK, requestContext);
            responseContext.header(CONTENT_ENCODING, "gzip");
            responseContext.setEntityStream(responseStream);
            return responseContext;
        }
    }).register(new EncodingFeature(GZipEncoder.class, DeflateEncoder.class)));
    try {
        client.target(UriBuilder.fromUri("/").build()).request().get(String.class);
        fail("Exception caused by invalid gzip stream expected.");
    } catch (ProcessingException ex) {
        assertTrue("Response input stream not closed when exception is thrown.", responseStream.isClosed);
    }
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) ClientRequest(org.glassfish.jersey.client.ClientRequest) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Aggregations

ClientConfig (org.glassfish.jersey.client.ClientConfig)169 Client (javax.ws.rs.client.Client)129 Test (org.junit.Test)85 Response (javax.ws.rs.core.Response)66 JerseyTest (org.glassfish.jersey.test.JerseyTest)52 WebTarget (javax.ws.rs.client.WebTarget)48 ClientBuilder (javax.ws.rs.client.ClientBuilder)17 SSLContext (javax.net.ssl.SSLContext)12 Invocation (javax.ws.rs.client.Invocation)12 ClientResponse (org.glassfish.jersey.client.ClientResponse)12 ApacheConnectorProvider (org.glassfish.jersey.apache.connector.ApacheConnectorProvider)10 IOException (java.io.IOException)9 IntegrationTest (com.hortonworks.streamline.common.test.IntegrationTest)8 URI (java.net.URI)7 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)7 CredentialsProvider (org.apache.http.client.CredentialsProvider)7 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 JerseyClient (org.glassfish.jersey.client.JerseyClient)6 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)5