Search in sources :

Example 16 with ClientConfig

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

the class MainTest method testSSLWithBasicAndSSLAuthGrizzlyConnector.

@Test
public void testSSLWithBasicAndSSLAuthGrizzlyConnector() {
    final ClientConfig clientConfig = getGrizzlyConfig();
    _testSSLWithBasicAndSSLAuth(clientConfig);
}
Also used : ClientConfig(org.glassfish.jersey.client.ClientConfig) Test(org.junit.Test)

Example 17 with ClientConfig

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

the class BasicClientTest method testCustomExecutorsSync.

@Test
public void testCustomExecutorsSync() throws ExecutionException, InterruptedException {
    ClientConfig jerseyConfig = new ClientConfig();
    jerseyConfig.register(CustomExecutorProvider.class).register(ThreadInterceptor.class);
    Client client = ClientBuilder.newClient(jerseyConfig);
    runCustomExecutorTestSync(client);
}
Also used : ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 18 with ClientConfig

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

the class ClientBufferingDisabledTest method testDisableBufferingWithFixedLengthViaMethod.

/**
     * Test that buffering can be disabled with {@link HttpURLConnection}. By default, the
     * {@code HttpURLConnection} buffers the output entity in order to calculate the
     * Content-length request attribute. This cause problems for large entities.
     * <p>
     * This test uses {@link HttpUrlConnectorProvider#useFixedLengthStreaming()} to enable
     * fix length streaming on {@code HttpURLConnection}.
     */
@Test
public void testDisableBufferingWithFixedLengthViaMethod() {
    postLatch = new CountDownLatch(1);
    // This IS sends out 10 chunks and waits whether they were received on the server. This tests
    // whether the buffering is disabled.
    InputStream is = getInputStream();
    final HttpUrlConnectorProvider connectorProvider = new HttpUrlConnectorProvider().useFixedLengthStreaming();
    ClientConfig clientConfig = new ClientConfig().connectorProvider(connectorProvider);
    Client client = ClientBuilder.newClient(clientConfig);
    final Response response = client.target(getBaseUri()).path("resource").request().header(HttpHeaders.CONTENT_LENGTH, LENGTH).post(Entity.entity(is, MediaType.APPLICATION_OCTET_STREAM));
    Assert.assertEquals(200, response.getStatus());
    final long count = response.readEntity(long.class);
    Assert.assertEquals("Unexpected content length received.", LENGTH, count);
}
Also used : Response(javax.ws.rs.core.Response) HttpUrlConnectorProvider(org.glassfish.jersey.client.HttpUrlConnectorProvider) InputStream(java.io.InputStream) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 19 with ClientConfig

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

the class ClientBufferingDisabledTest method testDisableBufferingWithFixedLengthViaProperty.

/**
     * Test that buffering can be disabled with {@link HttpURLConnection}. By default, the
     * {@code HttpURLConnection} buffers the output entity in order to calculate the
     * Content-length request attribute. This cause problems for large entities.
     * <p>
     * This test uses {@link HttpUrlConnectorProvider#USE_FIXED_LENGTH_STREAMING} to enable
     * fix length streaming on {@code HttpURLConnection}.
     */
@Test
public void testDisableBufferingWithFixedLengthViaProperty() {
    postLatch = new CountDownLatch(1);
    // This IS sends out 10 chunks and waits whether they were received on the server. This tests
    // whether the buffering is disabled.
    InputStream is = getInputStream();
    final HttpUrlConnectorProvider connectorProvider = new HttpUrlConnectorProvider();
    ClientConfig clientConfig = new ClientConfig().connectorProvider(connectorProvider);
    clientConfig.property(HttpUrlConnectorProvider.USE_FIXED_LENGTH_STREAMING, true);
    Client client = ClientBuilder.newClient(clientConfig);
    final Response response = client.target(getBaseUri()).path("resource").request().header(HttpHeaders.CONTENT_LENGTH, LENGTH).post(Entity.entity(is, MediaType.APPLICATION_OCTET_STREAM));
    Assert.assertEquals(200, response.getStatus());
    final long count = response.readEntity(long.class);
    Assert.assertEquals("Unexpected content length received.", LENGTH, count);
}
Also used : Response(javax.ws.rs.core.Response) HttpUrlConnectorProvider(org.glassfish.jersey.client.HttpUrlConnectorProvider) InputStream(java.io.InputStream) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 20 with ClientConfig

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

the class ClientBufferingDisabledTest method testDisableBufferingWithChunkEncoding.

/**
     * Test that buffering can be disabled with {@link HttpURLConnection}. By default, the
     * {@code HttpURLConnection} buffers the output entity in order to calculate the
     * Content-length request attribute. This cause problems for large entities.
     * <p>
     * In Jersey 1.x chunk encoding with {@code HttpURLConnection} was causing bugs
     * which occurred from time to time. This looks to be a case also in Jersey 2.x. This test
     * has failed unpredictably on some machines. Therefore it is disabled now.
     * </p>
     */
@Test
@Ignore("fails unpredictable (see javadoc)")
public void testDisableBufferingWithChunkEncoding() {
    postLatch = new CountDownLatch(1);
    // This IS sends out 10 chunks and waits whether they were received on the server. This tests
    // whether the buffering is disabled.
    InputStream is = getInputStream();
    final HttpUrlConnectorProvider connectorProvider = new HttpUrlConnectorProvider().chunkSize(CHUNK);
    ClientConfig clientConfig = new ClientConfig().connectorProvider(connectorProvider);
    Client client = ClientBuilder.newClient(clientConfig);
    final Response response = client.target(getBaseUri()).path("resource").request().post(Entity.entity(is, MediaType.APPLICATION_OCTET_STREAM));
    Assert.assertEquals(200, response.getStatus());
    final long count = response.readEntity(long.class);
    Assert.assertEquals("Unexpected content length received.", LENGTH, count);
}
Also used : Response(javax.ws.rs.core.Response) HttpUrlConnectorProvider(org.glassfish.jersey.client.HttpUrlConnectorProvider) InputStream(java.io.InputStream) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) Ignore(org.junit.Ignore) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

ClientConfig (org.glassfish.jersey.client.ClientConfig)94 Test (org.junit.Test)77 Client (javax.ws.rs.client.Client)74 JerseyTest (org.glassfish.jersey.test.JerseyTest)51 WebTarget (javax.ws.rs.client.WebTarget)46 Response (javax.ws.rs.core.Response)33 ClientResponse (org.glassfish.jersey.client.ClientResponse)12 Invocation (javax.ws.rs.client.Invocation)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)7 CredentialsProvider (org.apache.http.client.CredentialsProvider)7 JerseyClient (org.glassfish.jersey.client.JerseyClient)6 SSLContext (javax.net.ssl.SSLContext)5 ProcessingException (javax.ws.rs.ProcessingException)5 ClientBuilder (javax.ws.rs.client.ClientBuilder)5 ApacheConnectorProvider (org.glassfish.jersey.apache.connector.ApacheConnectorProvider)5 IOException (java.io.IOException)4 HttpUrlConnectorProvider (org.glassfish.jersey.client.HttpUrlConnectorProvider)4 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)4 Ignore (org.junit.Ignore)4