use of javax.ws.rs.client.Client in project jersey by jersey.
the class SslConnectorConfigurationTest method testSSLAuth1.
/**
* Test to see that SSLHandshakeException is thrown when client don't have
* trusted key.
*
* @throws Exception in case of a test failure.
*/
@Test
public void testSSLAuth1() throws Exception {
final SSLContext sslContext = getSslContext();
final ClientConfig cc = new ClientConfig().connectorProvider(new ApacheConnectorProvider());
final Client client = ClientBuilder.newBuilder().withConfig(cc).sslContext(sslContext).build();
WebTarget target = client.target(Server.BASE_URI).register(LoggingFeature.class);
boolean caught = false;
try {
target.path("/").request().get(String.class);
} catch (Exception e) {
caught = true;
}
assertTrue(caught);
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class SslConnectorConfigurationTest method testSSLWithAuth.
/**
* Test to see that the correct Http status is returned.
*
* @throws Exception in case of a test failure.
*/
@Test
public void testSSLWithAuth() throws Exception {
final SSLContext sslContext = getSslContext();
final ClientConfig cc = new ClientConfig().connectorProvider(connectorProvider);
final Client client = ClientBuilder.newBuilder().withConfig(cc).sslContext(sslContext).build();
// client basic auth demonstration
client.register(HttpAuthenticationFeature.basic("user", "password"));
final WebTarget target = client.target(Server.BASE_URI).register(LoggingFeature.class);
final Response response = target.path("/").request().get(Response.class);
assertEquals(200, response.getStatus());
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class SslConnectorHostnameVerifierTest method testHostnameVerifierApplied.
/**
* Test to apply {@link HostnameVerifier} along with SSL in the predefined connectors
*
* @throws Exception in case of a test failure.
*/
@Test
public void testHostnameVerifierApplied() throws Exception {
// Grizzly and Jetty connectors don't support Hostname Verification
if (isExcluded(Arrays.asList(GrizzlyConnectorProvider.class, JettyConnectorProvider.class))) {
return;
}
final Client client = ClientBuilder.newBuilder().withConfig(new ClientConfig().connectorProvider(connectorProvider)).register(HttpAuthenticationFeature.basic("user", "password")).hostnameVerifier(new CustomHostnameVerifier()).sslContext(getSslContext()).build();
try {
client.target(Server.BASE_URI).request().get(Response.class);
fail("HostnameVerifier was not applied.");
} catch (ProcessingException pex) {
CustomHostnameVerifier.HostnameVerifierException hve = getHVE(pex);
if (hve != null) {
assertEquals(CustomHostnameVerifier.EX_VERIFIER_MESSAGE, hve.getMessage());
} else {
fail("Invalid wrapped exception.");
}
}
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class SslHttpUrlConnectorTest method testSSLWithCustomSocketFactory.
/**
* Test to see that the correct Http status is returned.
*
* @throws Exception in case of a test failure.
*/
@Test
public void testSSLWithCustomSocketFactory() throws Exception {
final SSLContext sslContext = getSslContext();
final CustomSSLSocketFactory socketFactory = new CustomSSLSocketFactory(sslContext);
final ClientConfig cc = new ClientConfig().connectorProvider(new HttpUrlConnectorProvider().connectionFactory(new HttpUrlConnectorProvider.ConnectionFactory() {
@Override
public HttpURLConnection getConnection(final URL url) throws IOException {
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setSSLSocketFactory(socketFactory);
return connection;
}
}));
final Client client = ClientBuilder.newBuilder().withConfig(cc).sslContext(sslContext).register(HttpAuthenticationFeature.basic("user", "password")).register(LoggingFeature.class).build();
final Response response = client.target(Server.BASE_URI).path("/").request().get();
assertEquals(200, response.getStatus());
assertTrue(socketFactory.isVisited());
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class ConstrainedToTest method testClientWithProviderClasses.
@Test
public void testClientWithProviderClasses() {
Client client = ClientBuilder.newClient(new ClientConfig(ClientFilterConstrainedToServer.class, ClientFilterConstrainedToClient.class, ClientFilter.class));
_testFilters(client);
}
Aggregations