use of javax.ws.rs.client.Client 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);
}
use of javax.ws.rs.client.Client in project dropwizard by dropwizard.
the class JerseyClientBuilderTest method usesTheGivenThreadPool.
@Test
public void usesTheGivenThreadPool() throws Exception {
final Client client = builder.using(executorService, objectMapper).build("test");
for (Object o : client.getConfiguration().getInstances()) {
if (o instanceof DropwizardExecutorProvider) {
final DropwizardExecutorProvider provider = (DropwizardExecutorProvider) o;
assertThat(provider.getExecutorService()).isSameAs(executorService);
}
}
}
use of javax.ws.rs.client.Client in project dropwizard by dropwizard.
the class JerseyClientBuilderTest method usesTheGivenThreadPoolAndEnvironmentsObjectMapper.
@Test
public void usesTheGivenThreadPoolAndEnvironmentsObjectMapper() throws Exception {
final Client client = builder.using(environment).using(executorService).build("test");
for (Object o : client.getConfiguration().getInstances()) {
if (o instanceof DropwizardExecutorProvider) {
final DropwizardExecutorProvider provider = (DropwizardExecutorProvider) o;
assertThat(provider.getExecutorService()).isSameAs(executorService);
}
}
}
use of javax.ws.rs.client.Client in project dropwizard by dropwizard.
the class JerseyClientIntegrationTest method testFilterOnAWebTarget.
/**
* Test for ConnectorProvider idempotency
*/
@Test
public void testFilterOnAWebTarget() {
httpServer.createContext("/test", httpExchange -> {
try {
httpExchange.getResponseHeaders().add(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN);
httpExchange.sendResponseHeaders(200, 0);
httpExchange.getResponseBody().write("Hello World!".getBytes(StandardCharsets.UTF_8));
} finally {
httpExchange.close();
}
});
httpServer.start();
ExecutorService executor = Executors.newSingleThreadExecutor();
Client jersey = new JerseyClientBuilder(new MetricRegistry()).using(executor, JSON_MAPPER).build("test-jersey-client");
String uri = "http://127.0.0.1:" + httpServer.getAddress().getPort() + "/test";
WebTarget target = jersey.target(uri);
target.register(new LoggingFeature());
String firstResponse = target.request().buildGet().invoke().readEntity(String.class);
assertThat(firstResponse).isEqualTo("Hello World!");
String secondResponse = jersey.target(uri).request().buildGet().invoke().readEntity(String.class);
assertThat(secondResponse).isEqualTo("Hello World!");
executor.shutdown();
jersey.close();
}
use of javax.ws.rs.client.Client in project dropwizard by dropwizard.
the class JerseyClientIntegrationTest method testGet.
@Test
public void testGet() {
httpServer.createContext("/player", httpExchange -> {
try {
assertThat(httpExchange.getRequestURI().getQuery()).isEqualTo("id=21");
httpExchange.getResponseHeaders().add(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON);
httpExchange.sendResponseHeaders(200, 0);
httpExchange.getResponseBody().write(JSON_MAPPER.createObjectNode().put("email", "john@doe.me").put("name", "John Doe").toString().getBytes(StandardCharsets.UTF_8));
} finally {
httpExchange.close();
}
});
httpServer.start();
ExecutorService executor = Executors.newSingleThreadExecutor();
Client jersey = new JerseyClientBuilder(new MetricRegistry()).using(executor, JSON_MAPPER).using(new JerseyClientConfiguration()).build("jersey-test");
Response response = jersey.target("http://127.0.0.1:" + httpServer.getAddress().getPort() + "/player?id=21").request().buildGet().invoke();
assertThat(response.getHeaderString(HttpHeaders.CONTENT_TYPE)).isEqualTo(APPLICATION_JSON);
assertThat(response.getHeaderString(TRANSFER_ENCODING)).isEqualTo(CHUNKED);
Person person = response.readEntity(Person.class);
assertThat(person.email).isEqualTo("john@doe.me");
assertThat(person.name).isEqualTo("John Doe");
executor.shutdown();
jersey.close();
}
Aggregations