Search in sources :

Example 6 with SslConfigurator

use of org.glassfish.jersey.SslConfigurator in project jersey by jersey.

the class MainTest method _testSSLWithBasicAndSSLAuth.

/**
     * Test to see that the correct Http status is returned.
     */
private void _testSSLWithBasicAndSSLAuth(ClientConfig clientConfig) {
    SslConfigurator sslConfig = SslConfigurator.newInstance().trustStoreFile(TRUSTORE_CLIENT_FILE).trustStorePassword(TRUSTSTORE_CLIENT_PWD).keyStoreFile(KEYSTORE_CLIENT_FILE).keyPassword(KEYSTORE_CLIENT_PWD);
    final SSLContext sslContext = sslConfig.createSSLContext();
    Client client = ClientBuilder.newBuilder().withConfig(clientConfig).sslContext(sslContext).build();
    // client basic auth demonstration
    client.register(HttpAuthenticationFeature.basic("user", "password"));
    System.out.println("Client: GET " + Server.BASE_URI);
    WebTarget target = client.target(Server.BASE_URI);
    final Response response = target.path("/").request().get(Response.class);
    assertEquals(200, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) SSLContext(javax.net.ssl.SSLContext) WebTarget(javax.ws.rs.client.WebTarget) Client(javax.ws.rs.client.Client) SslConfigurator(org.glassfish.jersey.SslConfigurator)

Aggregations

SslConfigurator (org.glassfish.jersey.SslConfigurator)6 Client (javax.ws.rs.client.Client)3 WebTarget (javax.ws.rs.client.WebTarget)3 InputStream (java.io.InputStream)2 Response (javax.ws.rs.core.Response)2 InetSocketAddress (java.net.InetSocketAddress)1 ByteBuffer (java.nio.ByteBuffer)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 SSLContext (javax.net.ssl.SSLContext)1