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();
}
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();
}
};
}
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();
}
};
}
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());
}
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();
}
Aggregations