Search in sources :

Example 36 with ClientConfig

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

the class JerseyClientBuilder method buildConfig.

private Configuration buildConfig(final String name, final ExecutorService threadPool, final ObjectMapper objectMapper, final Validator validator) {
    final ClientConfig config = new ClientConfig();
    for (Object singleton : this.singletons) {
        config.register(singleton);
    }
    for (Class<?> provider : this.providers) {
        config.register(provider);
    }
    config.register(new JacksonBinder(objectMapper));
    config.register(new HibernateValidationFeature(validator));
    for (Map.Entry<String, Object> property : this.properties.entrySet()) {
        config.property(property.getKey(), property.getValue());
    }
    config.register(new DropwizardExecutorProvider(threadPool, shutdownGracePeriod));
    if (connectorProvider == null) {
        final ConfiguredCloseableHttpClient apacheHttpClient = apacheHttpClientBuilder.buildWithDefaultRequestConfiguration(name);
        connectorProvider = (client, runtimeConfig) -> new DropwizardApacheConnector(apacheHttpClient.getClient(), apacheHttpClient.getDefaultRequestConfig(), configuration.isChunkedEncodingEnabled());
    }
    config.connectorProvider(connectorProvider);
    return config;
}
Also used : HibernateValidationFeature(io.dropwizard.jersey.validation.HibernateValidationFeature) JacksonBinder(io.dropwizard.jersey.jackson.JacksonBinder) ClientConfig(org.glassfish.jersey.client.ClientConfig) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 37 with ClientConfig

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

the class EncodingFilterTest method testContentEncodingSkippedForNoEntity.

@Test
public void testContentEncodingSkippedForNoEntity() {
    Client client = ClientBuilder.newClient(new ClientConfig(EncodingFilter.class, GZipEncoder.class, DeflateEncoder.class).property(ClientProperties.USE_ENCODING, "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 38 with ClientConfig

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

the class HttpBasicAuthFilterTest method testGet.

@Test
public void testGet() {
    Client client = ClientBuilder.newClient(new ClientConfig(HttpAuthenticationFeature.basic("Uzivatelske jmeno", "Heslo")).connectorProvider(new TestConnector()));
    Invocation.Builder invBuilder = client.target(UriBuilder.fromUri("/").build()).request();
    Response r = invBuilder.get();
    assertEquals("Basic " + Base64.encodeAsString("Uzivatelske jmeno:Heslo"), r.getHeaderString(HttpHeaders.AUTHORIZATION));
}
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 39 with ClientConfig

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

the class HttpBasicAuthFilterTest method testBlankUsernamePassword.

@Test
public void testBlankUsernamePassword() {
    Client client = ClientBuilder.newClient(new ClientConfig(HttpAuthenticationFeature.basic("", "")).connectorProvider(new TestConnector()));
    Invocation.Builder invBuilder = client.target(UriBuilder.fromUri("/").build()).request();
    Response r = invBuilder.get();
    assertEquals("Basic " + Base64.encodeAsString(":"), r.getHeaderString(HttpHeaders.AUTHORIZATION));
}
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 40 with ClientConfig

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

the class CsrfProtectionFilterTest method setUp.

@Before
public void setUp() {
    Client client = ClientBuilder.newClient(new ClientConfig(CsrfProtectionFilter.class).connectorProvider(new TestConnector()));
    invBuilder = client.target(UriBuilder.fromUri("/").build()).request();
}
Also used : Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig) Before(org.junit.Before)

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