use of javax.ws.rs.client.Client in project dropwizard by dropwizard.
the class JerseyClientBuilder method build.
private Client build(String name, ExecutorService threadPool, ObjectMapper objectMapper, Validator validator) {
if (!configuration.isGzipEnabled()) {
apacheHttpClientBuilder.disableContentCompression(true);
}
final Client client = ClientBuilder.newClient(buildConfig(name, threadPool, objectMapper, validator));
client.register(new JerseyIgnoreRequestUserAgentHeaderFilter());
// Tie the client to server lifecycle
if (environment != null) {
environment.lifecycle().manage(new Managed() {
@Override
public void start() throws Exception {
}
@Override
public void stop() throws Exception {
client.close();
}
});
}
if (configuration.isGzipEnabled()) {
client.register(new GZipDecoder());
client.register(new ConfiguredGZipEncoder(configuration.isGzipEnabledForRequests()));
}
return client;
}
use of javax.ws.rs.client.Client in project dropwizard by dropwizard.
the class DropwizardSSLConnectionSocketFactoryTest method shouldBeOkIfHostnameVerificationOffAndServerHostnameDoesntMatch.
@Test
public void shouldBeOkIfHostnameVerificationOffAndServerHostnameDoesntMatch() throws Exception {
tlsConfiguration.setVerifyHostname(false);
final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("bad_host_working");
final Response response = client.target(String.format("https://localhost:%d", TLS_APP_RULE.getPort(3))).request().get();
assertThat(response.getStatus()).isEqualTo(200);
}
use of javax.ws.rs.client.Client in project dropwizard by dropwizard.
the class DropwizardSSLConnectionSocketFactoryTest method shouldReturn200IfServerCertInTruststore.
@Test
public void shouldReturn200IfServerCertInTruststore() throws Exception {
final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("tls_working_client");
final Response response = client.target(String.format("https://localhost:%d", TLS_APP_RULE.getLocalPort())).request().get();
assertThat(response.getStatus()).isEqualTo(200);
}
use of javax.ws.rs.client.Client in project dropwizard by dropwizard.
the class DropwizardSSLConnectionSocketFactoryTest method shouldErrorIfServerCertSelfSignedAndSelfSignedCertsNotAllowed.
@Test
public void shouldErrorIfServerCertSelfSignedAndSelfSignedCertsNotAllowed() throws Exception {
final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("self_sign_failure");
assertThatThrownBy(() -> client.target(String.format("https://localhost:%d", TLS_APP_RULE.getPort(1))).request().get(ClientResponse.class)).isInstanceOf(ProcessingException.class).hasCauseInstanceOf(SSLHandshakeException.class);
}
use of javax.ws.rs.client.Client in project dropwizard by dropwizard.
the class DropwizardSSLConnectionSocketFactoryTest method shouldReturn200IfAbleToClientAuth.
@Test
public void shouldReturn200IfAbleToClientAuth() throws Exception {
tlsConfiguration.setKeyStorePath(new File(ResourceHelpers.resourceFilePath("stores/client/keycert.p12")));
tlsConfiguration.setKeyStorePassword("password");
tlsConfiguration.setKeyStoreType("PKCS12");
final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("client_auth_working");
final Response response = client.target(String.format("https://localhost:%d", TLS_APP_RULE.getPort(2))).request().get();
assertThat(response.getStatus()).isEqualTo(200);
}
Aggregations