use of javax.ws.rs.client.ClientBuilder in project vespa by vespa-engine.
the class JerseyJaxRsClientFactory method createClient.
/**
* Contains some workarounds for HTTP/JAX-RS/Jersey issues. See:
* https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/client/ClientProperties.html#SUPPRESS_HTTP_COMPLIANCE_VALIDATION
* https://jersey.java.net/apidocs/latest/jersey/org/glassfish/jersey/client/HttpUrlConnectorProvider.html#SET_METHOD_WORKAROUND
*/
@Override
public <T> T createClient(final Class<T> apiClass, final HostName hostName, final int port, final String pathPrefix, String scheme) {
final UriBuilder uriBuilder = UriBuilder.fromPath(pathPrefix).host(hostName.s()).port(port).scheme(scheme);
ClientBuilder builder = ClientBuilder.newBuilder().property(ClientProperties.CONNECT_TIMEOUT, connectTimeoutMs).property(ClientProperties.READ_TIMEOUT, readTimeoutMs).property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, // Allow empty PUT. TODO: Fix API.
true).property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, // Allow e.g. PATCH method.
true).property(ClientProperties.FOLLOW_REDIRECTS, true);
if (sslContext != null) {
builder.sslContext(sslContext);
}
if (hostnameVerifier != null) {
builder.hostnameVerifier(hostnameVerifier);
}
if (userAgent != null) {
builder.register((ClientRequestFilter) context -> context.getHeaders().put(HttpHeaders.USER_AGENT, Collections.singletonList(userAgent)));
}
final WebTarget target = builder.build().target(uriBuilder);
// TODO: Check if this fills up non-heap memory with loaded classes.
return WebResourceFactory.newResource(apiClass, target);
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class UndertowSSLv2HelloTestCase method testTwoWayElytronClientServerSupportsSSLv2Hello.
/**
* Two way SSL - RESTEasy client sends SSLv2Hello message and server supports the protocol.
* Handshake should succeed.
*/
@Test
public void testTwoWayElytronClientServerSupportsSSLv2Hello() throws Exception {
configureSSLContext(SSLV2HELLO_CONTEXT);
AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-sslv2hello.xml");
return ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI()).create();
} catch (Throwable t) {
throw new InvalidAuthenticationConfigurationException(t);
}
});
context.run(() -> {
ClientBuilder clientBuilder = ClientBuilder.newBuilder().hostnameVerifier((s, sslSession) -> true);
Client client = clientBuilder.build();
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals(200, response.getStatus());
});
restoreConfiguration();
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class UndertowSSLv2HelloTestCase method testTwoWayElytronClientNoSSLv2HelloSupport.
/**
* Two way SSL - Server supports SSLv2Hello, but client does not support SSLv2Hello.
* Handshake should succeed as they still share protocol TLSv1 in common.
*/
@Test
public void testTwoWayElytronClientNoSSLv2HelloSupport() throws Exception {
configureSSLContext(SSLV2HELLO_CONTEXT);
AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-no-sslv2hello.xml");
return ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI()).create();
} catch (Throwable t) {
throw new InvalidAuthenticationConfigurationException(t);
}
});
context.run(() -> {
ClientBuilder clientBuilder = ClientBuilder.newBuilder().hostnameVerifier((s, sslSession) -> true);
Client client = clientBuilder.build();
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals(200, response.getStatus());
});
restoreConfiguration();
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class UndertowTwoWaySslNeedClientAuthTestCase method testClientConfigProviderSSLContextIsSuccessfulWhenBasicSetOnRESTEasy.
/**
* Test situation when credentials are set on RESTEeasy client, but truststore is part of SSLContext configured for Elytron client.
* Test that Elytron SSLContext will be used successfully.
*/
@Test
public void testClientConfigProviderSSLContextIsSuccessfulWhenBasicSetOnRESTEasy() {
AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-correct-truststore.xml");
return ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI()).create();
} catch (Throwable t) {
throw new InvalidAuthenticationConfigurationException(t);
}
});
context.run(() -> {
ClientBuilder resteasyClientBuilder = ClientBuilder.newBuilder();
resteasyClientBuilder.hostnameVerifier((s, sslSession) -> true);
Client client = resteasyClientBuilder.build();
client.register(HttpAuthorization.basic("randomName", "randomPass"));
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals(200, response.getStatus());
});
}
use of javax.ws.rs.client.ClientBuilder in project wildfly by wildfly.
the class UndertowTwoWaySslNeedClientAuthTestCase method testClientConfigProviderSSLContextForDifferentHostWillNotWork.
/**
* Test that RESTEasy client does choose SSLContext from Elytron client based on destination of the request.
* In this case the truststore is set for different endpoint/server and so SSL handshake will fail.
*/
@Test(expected = ProcessingException.class)
public void testClientConfigProviderSSLContextForDifferentHostWillNotWork() {
AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-correct-truststore-different-host.xml");
return ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI()).create();
} catch (Throwable t) {
throw new InvalidAuthenticationConfigurationException(t);
}
});
context.run(() -> {
ClientBuilder resteasyClientBuilder = ClientBuilder.newBuilder().hostnameVerifier((s, sslSession) -> true);
Client client = resteasyClientBuilder.build();
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals(200, response.getStatus());
});
}
Aggregations