Search in sources :

Example 11 with JerseyClientBuilder

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

the class DropwizardSSLConnectionSocketFactoryTest method shouldErrorIfHostnameVerificationOnAndServerHostnameMatchesAndFailVerifierSpecified.

@Test
public void shouldErrorIfHostnameVerificationOnAndServerHostnameMatchesAndFailVerifierSpecified() throws Exception {
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).using(new FailVerifier()).build("bad_host_broken_fail_verifier");
    final Throwable exn = catchThrowable(() -> client.target(String.format("https://localhost:%d", TLS_APP_RULE.getLocalPort())).request().get());
    assertThat(exn).hasCauseExactlyInstanceOf(SSLPeerUnverifiedException.class);
    assertThat(exn.getCause()).hasMessage("Certificate for <localhost> doesn't match any of the subject alternative names: []");
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 12 with JerseyClientBuilder

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

the class DropwizardSSLConnectionSocketFactoryTest method shouldErrorIfHostnameVerificationOnAndServerHostnameDoesntMatch.

@Test
public void shouldErrorIfHostnameVerificationOnAndServerHostnameDoesntMatch() throws Exception {
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("bad_host_broken");
    final Throwable exn = catchThrowable(() -> client.target(String.format("https://localhost:%d", TLS_APP_RULE.getPort(3))).request().get());
    assertThat(exn).hasCauseExactlyInstanceOf(SSLPeerUnverifiedException.class);
    assertThat(exn.getCause()).hasMessage("Certificate for <localhost> doesn't match any of the subject alternative names: []");
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 13 with JerseyClientBuilder

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

the class DropwizardSSLConnectionSocketFactoryTest method shouldErrorIfClientAuthFails.

@Test
public void shouldErrorIfClientAuthFails() throws Exception {
    tlsConfiguration.setKeyStorePath(new File(ResourceHelpers.resourceFilePath("stores/server/self_sign_keycert.p12")));
    tlsConfiguration.setKeyStorePassword("password");
    tlsConfiguration.setKeyStoreType("PKCS12");
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).build("client_auth_broken");
    final Throwable exn = catchThrowable(() -> client.target(String.format("https://localhost:%d", TLS_APP_RULE.getPort(2))).request().get());
    assertThat(exn).isInstanceOf(ProcessingException.class);
    assertThat(exn.getCause()).isInstanceOfAny(SocketException.class, SSLHandshakeException.class);
}
Also used : Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) Client(javax.ws.rs.client.Client) File(java.io.File) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 14 with JerseyClientBuilder

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

the class DropwizardSSLConnectionSocketFactoryTest method shouldBeOkIfHostnameVerificationOnAndServerHostnameDoesntMatchAndNoopVerifierSpecified.

@Test
public void shouldBeOkIfHostnameVerificationOnAndServerHostnameDoesntMatchAndNoopVerifierSpecified() throws Exception {
    final Client client = new JerseyClientBuilder(TLS_APP_RULE.getEnvironment()).using(jerseyClientConfiguration).using(new NoopHostnameVerifier()).build("bad_host_noop_verifier_working");
    final Response response = client.target(String.format("https://localhost:%d", TLS_APP_RULE.getPort(3))).request().get();
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : ClientResponse(org.glassfish.jersey.client.ClientResponse) Response(javax.ws.rs.core.Response) NoopHostnameVerifier(org.apache.http.conn.ssl.NoopHostnameVerifier) Client(javax.ws.rs.client.Client) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Example 15 with JerseyClientBuilder

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

the class NewQueryPlanResourceTest method checkSampleEndpoint.

/**
     * Tests the query plan execution endpoint.
     */
@Test
public void checkSampleEndpoint() throws Exception {
    Client client = new JerseyClientBuilder(RULE.getEnvironment()).build("test client");
    client.property(ClientProperties.CONNECT_TIMEOUT, 5000);
    client.property(ClientProperties.READ_TIMEOUT, 5000);
    Response response = client.target(String.format(queryPlanEndpoint, RULE.getLocalPort())).request().post(Entity.entity(new ObjectMapper().writeValueAsString(getLogicalPlan1()), MediaType.APPLICATION_JSON));
    System.out.println("resposne is: " + response);
    assertThat(response.getStatus()).isEqualTo(200);
}
Also used : Response(javax.ws.rs.core.Response) Client(javax.ws.rs.client.Client) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JerseyClientBuilder(io.dropwizard.client.JerseyClientBuilder) Test(org.junit.Test)

Aggregations

JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)67 JerseyClientConfiguration (io.dropwizard.client.JerseyClientConfiguration)46 BeforeClass (org.junit.BeforeClass)45 Client (javax.ws.rs.client.Client)21 Test (org.junit.Test)21 Response (javax.ws.rs.core.Response)14 ClientResponse (org.glassfish.jersey.client.ClientResponse)7 File (java.io.File)4 ProcessingException (javax.ws.rs.ProcessingException)3 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)3 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 FormDataBodyPart (org.glassfish.jersey.media.multipart.FormDataBodyPart)2 FormDataMultiPart (org.glassfish.jersey.media.multipart.FormDataMultiPart)2 Ignore (org.junit.Ignore)2 RequestAndResponse (httpstub.RequestAndResponse)1 ErrorMessage (io.dropwizard.jersey.errors.ErrorMessage)1 NoopHostnameVerifier (org.apache.http.conn.ssl.NoopHostnameVerifier)1 FileDataBodyPart (org.glassfish.jersey.media.multipart.file.FileDataBodyPart)1 Before (org.junit.Before)1