Search in sources :

Example 1 with JerseyClientBuilder

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

the class Http2CIntegrationTest method testHttp11.

@Test
public void testHttp11() {
    final String hostname = "127.0.0.1";
    final int port = appRule.getLocalPort();
    final JerseyClient http11Client = new JerseyClientBuilder().build();
    final Response response = http11Client.target("http://" + hostname + ":" + port + "/api/test").request().get();
    assertThat(response.getHeaderString(HttpHeaders.CONTENT_TYPE)).isEqualTo(MediaType.APPLICATION_JSON);
    assertThat(response.readEntity(String.class)).isEqualTo(FakeApplication.HELLO_WORLD);
    http11Client.close();
}
Also used : Response(javax.ws.rs.core.Response) JerseyClient(org.glassfish.jersey.client.JerseyClient) JerseyClientBuilder(org.glassfish.jersey.client.JerseyClientBuilder) Test(org.junit.Test)

Example 2 with JerseyClientBuilder

use of org.glassfish.jersey.client.JerseyClientBuilder in project cals-api by ca-cwds.

the class RestClientTestRule method apply.

@Override
public Statement apply(Statement statement, Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            JerseyClientBuilder clientBuilder = new JerseyClientBuilder().property(ClientProperties.CONNECT_TIMEOUT, 5000).property(ClientProperties.READ_TIMEOUT, 60000).hostnameVerifier((hostName, sslSession) -> {
                // Just ignore host verification for test purposes
                return true;
            });
            client = clientBuilder.build();
            // Trust All certificates for test purposes
            TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }

                public void checkClientTrusted(X509Certificate[] certs, String authType) {
                }

                public void checkServerTrusted(X509Certificate[] certs, String authType) {
                }
            } };
            client.getSslContext().init(null, trustAllCerts, new SecureRandom());
            mapper = dropWizardApplication.getObjectMapper();
            client.register(new JacksonJsonProvider(mapper));
            prepareForTesting();
            statement.evaluate();
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) X509TrustManager(javax.net.ssl.X509TrustManager) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) SecureRandom(java.security.SecureRandom) X509Certificate(java.security.cert.X509Certificate) JerseyClientBuilder(org.glassfish.jersey.client.JerseyClientBuilder) TrustManager(javax.net.ssl.TrustManager) X509TrustManager(javax.net.ssl.X509TrustManager)

Example 3 with JerseyClientBuilder

use of org.glassfish.jersey.client.JerseyClientBuilder in project api-core by ca-cwds.

the class RestClientTestRule method apply.

@Override
public Statement apply(Statement statement, Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            JerseyClientBuilder clientBuilder = new JerseyClientBuilder().property(ClientProperties.CONNECT_TIMEOUT, 5000).property(ClientProperties.READ_TIMEOUT, 20000).hostnameVerifier((hostName, sslSession) -> {
                // Just ignore host verification for test purposes
                return true;
            });
            client = clientBuilder.build();
            client.register(new JacksonJsonProvider(mapper));
            client.getSslContext().init(null, TRUST_ALL_CERTS, new SecureRandom());
            mapper = dropWizardApplication.getObjectMapper();
            mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
            statement.evaluate();
        }
    };
}
Also used : Statement(org.junit.runners.model.Statement) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) SecureRandom(java.security.SecureRandom) JerseyClientBuilder(org.glassfish.jersey.client.JerseyClientBuilder)

Example 4 with JerseyClientBuilder

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

the class ClientDestroyTest method testLifecycleListenerProvider.

@Test
public void testLifecycleListenerProvider() {
    final JerseyClientBuilder builder = new JerseyClientBuilder();
    final JerseyClient client = builder.build();
    final BarListener filter = new BarListener();
    final BarListener filter2 = new BarListener2();
    // ClientRuntime initializes lazily, so it is forced by invoking a (dummy) request
    // instance registered into client
    client.register(filter2);
    // instance registration into target
    client.target(getBaseUri()).register(filter).request().get(String.class);
    assertTrue("Filter was expected to be already initialized.", filter.isInitialized());
    assertTrue("Filter2 was expected to be already initialized.", filter2.isInitialized());
    // class registration into target
    client.target(getBaseUri()).register(FooListener.class).request().get(String.class);
    assertTrue("Class-registered filter was expected to be already initialized", FooListener.isInitialized());
    assertFalse("Class-registered filter was expected to be still open.", FooListener.isClosed());
    assertFalse("Filter was expected to be still open.", filter.isClosed());
    assertFalse("Filter2 was expected to be still open.", filter2.isClosed());
    client.close();
    assertTrue("Class-registered filter was expected to be closed.", FooListener.isClosed());
    assertTrue("Filter was expected to be closed.", filter.isClosed());
    assertTrue("Filter2 was expected to be closed.", filter2.isClosed());
}
Also used : JerseyClient(org.glassfish.jersey.client.JerseyClient) JerseyClientBuilder(org.glassfish.jersey.client.JerseyClientBuilder) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 5 with JerseyClientBuilder

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

the class Http2IntegrationTest method testHttp11.

@Test
public void testHttp11() throws Exception {
    final String hostname = "localhost";
    final int port = appRule.getLocalPort();
    final JerseyClient http11Client = new JerseyClientBuilder().sslContext(sslContextFactory.getSslContext()).build();
    final Response response = http11Client.target("https://" + hostname + ":" + port + "/api/test").request().get();
    assertThat(response.getHeaderString(HttpHeaders.CONTENT_TYPE)).isEqualTo(MediaType.APPLICATION_JSON);
    assertThat(response.readEntity(String.class)).isEqualTo(FakeApplication.HELLO_WORLD);
    http11Client.close();
}
Also used : Response(javax.ws.rs.core.Response) JerseyClient(org.glassfish.jersey.client.JerseyClient) JerseyClientBuilder(org.glassfish.jersey.client.JerseyClientBuilder) Test(org.junit.Test)

Aggregations

JerseyClientBuilder (org.glassfish.jersey.client.JerseyClientBuilder)7 JerseyClient (org.glassfish.jersey.client.JerseyClient)3 Test (org.junit.Test)3 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)2 SecureRandom (java.security.SecureRandom)2 Response (javax.ws.rs.core.Response)2 Statement (org.junit.runners.model.Statement)2 X509Certificate (java.security.cert.X509Certificate)1 TrustManager (javax.net.ssl.TrustManager)1 X509TrustManager (javax.net.ssl.X509TrustManager)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1