use of javax.ws.rs.client.ClientBuilder in project athenz by yahoo.
the class ZTSClient method initClient.
private void initClient(final String serverUrl, Principal identity, final String domainName, final String serviceName, final ServiceIdentityProvider siaProvider) {
ztsUrl = (serverUrl == null) ? confZtsUrl : serverUrl;
if (!isEmpty(ztsUrl)) {
if (!ztsUrl.endsWith("/zts/v1")) {
if (ztsUrl.charAt(ztsUrl.length() - 1) != '/') {
ztsUrl += '/';
}
ztsUrl += "zts/v1";
}
}
// determine to see if we need a host verifier for our ssl connections
HostnameVerifier hostnameVerifier = null;
if (!isEmpty(x509CertDNSName)) {
hostnameVerifier = new AWSHostNameVerifier(x509CertDNSName);
}
if (sslContext == null) {
sslContext = createSSLContext();
}
// setup our client config object with timeouts
final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
final ClientConfig config = new ClientConfig(jacksonJsonProvider);
PoolingHttpClientConnectionManager connManager = createConnectionManager(sslContext, hostnameVerifier);
if (connManager != null) {
config.property(ApacheClientProperties.CONNECTION_MANAGER, connManager);
}
config.connectorProvider(new ApacheConnectorProvider());
if (proxyUrl != null) {
config.property(ClientProperties.PROXY_URI, proxyUrl);
}
ClientBuilder builder = getClientBuilder();
if (sslContext != null) {
builder = builder.sslContext(sslContext);
enablePrefetch = true;
}
// JerseyClientBuilder::withConfig() replaces the existing config with the new client
// config. Hence the client config should be added to the builder before the timeouts.
// Otherwise the timeout settings would be overridden.
Client rsClient = builder.withConfig(config).hostnameVerifier(hostnameVerifier).readTimeout(reqReadTimeout, TimeUnit.MILLISECONDS).connectTimeout(reqConnectTimeout, TimeUnit.MILLISECONDS).build();
ztsClient = new ZTSRDLGeneratedClient(ztsUrl, rsClient);
principal = identity;
domain = domainName;
service = serviceName;
this.siaProvider = siaProvider;
if (principal != null) {
domain = principal.getDomain();
service = principal.getName();
ztsClient.addCredentials(identity.getAuthority().getHeader(), identity.getCredentials());
}
}
use of javax.ws.rs.client.ClientBuilder in project cxf by apache.
the class JAXRS20HttpsBookTest method testGetBook.
@Test
public void testGetBook() throws Exception {
ClientBuilder builder = ClientBuilder.newBuilder();
try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Truststore.jks", this.getClass())) {
KeyStore trustStore = loadStore(keystore, "password");
builder.trustStore(trustStore);
}
builder.hostnameVerifier(new AllowAllHostnameVerifier());
try (InputStream keystore = ClassLoaderUtils.getResourceAsStream("keys/Morpit.jks", this.getClass())) {
KeyStore keyStore = loadStore(keystore, "password");
builder.keyStore(keyStore, "password");
}
Client client = builder.build();
client.register(new LoggingFeature());
WebTarget target = client.target("https://localhost:" + PORT + "/bookstore/securebooks/123");
Book b = target.request().accept(MediaType.APPLICATION_XML_TYPE).get(Book.class);
assertEquals(123, b.getId());
}
use of javax.ws.rs.client.ClientBuilder in project cxf by apache.
the class JAXRS20HttpsBookTest method testGetBookSslContext.
@Test
public void testGetBookSslContext() throws Exception {
ClientBuilder builder = ClientBuilder.newBuilder();
SSLContext sslContext = createSSLContext();
builder.sslContext(sslContext);
builder.hostnameVerifier(new AllowAllHostnameVerifier());
Client client = builder.build();
WebTarget target = client.target("https://localhost:" + PORT + "/bookstore/securebooks/123");
Book b = target.request().accept(MediaType.APPLICATION_XML_TYPE).get(Book.class);
assertEquals(123, b.getId());
}
use of javax.ws.rs.client.ClientBuilder in project camel by apache.
the class BonitaAPIBuilder method build.
public static BonitaAPI build(BonitaAPIConfig bonitaAPIConfig) {
if (bonitaAPIConfig == null) {
throw new IllegalArgumentException("bonitaApiConfig is null");
}
ClientConfig clientConfig = new ClientConfig();
clientConfig.register(JacksonJsonProvider.class);
ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig);
Client client = clientBuilder.build();
client.register(new BonitaAuthFilter(bonitaAPIConfig));
WebTarget webTarget = client.target(bonitaAPIConfig.getBaseBonitaURI()).path("/API/bpm");
return new BonitaAPI(bonitaAPIConfig, webTarget);
}
use of javax.ws.rs.client.ClientBuilder in project nifi by apache.
the class TlsToolkitGetStatus method get.
public void get(final GetStatusConfig config) {
final SSLContext sslContext = config.getSslContext();
final ClientBuilder clientBuilder = ClientBuilder.newBuilder();
if (sslContext != null) {
clientBuilder.sslContext(sslContext);
}
final ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 10000);
clientConfig.property(ClientProperties.READ_TIMEOUT, 10000);
clientBuilder.withConfig(clientConfig);
final Client client = clientBuilder.build();
final WebTarget target = client.target(config.getUrl());
final Response response = target.request().get();
System.out.println("Response Code - " + response.getStatus());
}
Aggregations