Search in sources :

Example 6 with JerseyClientBuilder

use of io.dropwizard.client.JerseyClientBuilder 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);
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 7 with JerseyClientBuilder

use of io.dropwizard.client.JerseyClientBuilder 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);
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Example 8 with JerseyClientBuilder

use of io.dropwizard.client.JerseyClientBuilder 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);
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) File(java.io.File) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 9 with JerseyClientBuilder

use of io.dropwizard.client.JerseyClientBuilder in project dropwizard by dropwizard.

the class DropwizardSSLConnectionSocketFactoryTest method shouldErrorIfServerCertNotFoundInTruststore.

@Test
public void shouldErrorIfServerCertNotFoundInTruststore() throws Exception {
    tlsConfiguration.setTrustStorePath(new File(ResourceHelpers.resourceFilePath("stores/server/other_cert_truststore.ts")));
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("tls_broken_client");
    assertThatThrownBy(() -> client.target(String.format("https://localhost:%d", TLS_APP_RULE.getLocalPort())).request().get()).isInstanceOf(ProcessingException.class).hasCauseInstanceOf(SSLHandshakeException.class);
}
Also used : Client(javax.ws.rs.client.Client) File(java.io.File) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) ProcessingException(javax.ws.rs.ProcessingException) Test(org.junit.Test)

Example 10 with JerseyClientBuilder

use of io.dropwizard.client.JerseyClientBuilder in project dropwizard by dropwizard.

the class DropwizardSSLConnectionSocketFactoryTest method shouldNotErrorIfServerCertSelfSignedAndSelfSignedCertsAllowed.

@Test
public void shouldNotErrorIfServerCertSelfSignedAndSelfSignedCertsAllowed() throws Exception {
    tlsConfiguration.setTrustSelfSignedCertificates(true);
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("self_sign_permitted");
    final Response response = client.target(String.format("https://localhost:%d", TLS_APP_RULE.getTestSupport().getPort(1))).request().get();
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Aggregations

JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)19 Client (javax.ws.rs.client.Client)18 Test (org.junit.Test)18 Response (javax.ws.rs.core.Response)11 ClientResponse (org.glassfish.jersey.client.ClientResponse)7 File (java.io.File)3 ProcessingException (javax.ws.rs.ProcessingException)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)3 FormDataBodyPart (org.glassfish.jersey.media.multipart.FormDataBodyPart)2 FormDataMultiPart (org.glassfish.jersey.media.multipart.FormDataMultiPart)2 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 JerseyClientConfiguration (io.dropwizard.client.JerseyClientConfiguration)1 ErrorMessage (io.dropwizard.jersey.errors.ErrorMessage)1 NoopHostnameVerifier (org.apache.http.conn.ssl.NoopHostnameVerifier)1 Before (org.junit.Before)1