use of javax.ws.rs.client.ClientBuilder in project ats-framework by Axway.
the class RestClient method constructThirdPartyConnectorInvocationBuilder.
private void constructThirdPartyConnectorInvocationBuilder(String descriptionToken, boolean suppressHttpComplianceValidation) {
// create the client config object
ClientConfig clientConfig = createClientConfig(suppressHttpComplianceValidation);
// create the client builder
ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig);
// handle HTTPS requests
if (isHttps()) {
// configure Trust-all SSL context
checkSupportedProtocols();
SSLContext sslContext = SslUtils.getSSLContext(clientConfigurator.getCertificateFileName(), clientConfigurator.getCertificateFilePassword(), supportedProtocols[0]);
clientBuilder = clientBuilder.sslContext(sslContext).hostnameVerifier(new SslUtils.DefaultHostnameVerifier());
}
// now create the client
createClient(clientBuilder);
createInvocationBuilder(descriptionToken);
}
use of javax.ws.rs.client.ClientBuilder in project Payara by payara.
the class TestServlet method newClientBuilder.
static ClientBuilder newClientBuilder() {
SSLContext sslContext = null;
try {
if (!hasTLS13Support()) {
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, null, null);
}
} catch (NoSuchAlgorithmException | KeyManagementException ex) {
throw new IllegalStateException(ex);
}
ClientBuilder builder = ClientBuilder.newBuilder();
if (sslContext != null) {
builder.sslContext(sslContext);
}
return builder;
}
use of javax.ws.rs.client.ClientBuilder in project syndesis-qe by syndesisio.
the class EndpointClient method getInsecureClient.
public static Client getInsecureClient() throws RestClientException {
ClientBuilder clientBuilder = ClientBuilder.newBuilder();
clientBuilder.connectTimeout(120, TimeUnit.SECONDS);
clientBuilder.readTimeout(120, TimeUnit.SECONDS);
final Client client = clientBuilder.build();
client.register(new ErrorLogger());
return client;
}
use of javax.ws.rs.client.ClientBuilder in project pravega by pravega.
the class ControllerCommand method createContext.
/**
* Creates a context for child classes consisting of a REST client to execute calls against the Controller.
*
* @return REST client.
*/
protected Context createContext() {
CLIConfig config = getCLIControllerConfig();
ClientConfig clientConfig = new ClientConfig();
clientConfig.register(JacksonJsonProvider.class);
clientConfig.property("sun.net.http.allowRestrictedHeaders", "true");
ClientBuilder builder = ClientBuilder.newBuilder().withConfig(clientConfig);
// If TLS parameters are configured, set them in client.
if (config.isTlsEnabled()) {
SSLContext tlsContext;
try {
KeyStore ks = createTrustStore(config.getTruststore());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(ks);
tlsContext = SSLContext.getInstance("TLS");
tlsContext.init(null, tmf.getTrustManagers(), null);
} catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException | KeyManagementException e) {
String message = String.format("Encountered exception while trying to use the given truststore: %s", config.getTruststore());
log.error(message, e);
return null;
}
builder.sslContext(tlsContext);
}
Client client = builder.build();
// If authorization parameters are configured, set them in the client.
if (config.isAuthEnabled()) {
HttpAuthenticationFeature auth = HttpAuthenticationFeature.basic(config.getUserName(), config.getPassword());
client = client.register(auth);
}
return new Context(client);
}
use of javax.ws.rs.client.ClientBuilder in project athenz by yahoo.
the class ZMSClient method initClient.
/**
* Initialize the client for class constructors
*
* @param url ZMS Server url
* @param sslContext SSLContext for service authentication
*/
private void initClient(String url, SSLContext sslContext) {
if (url == null) {
zmsUrl = lookupZMSUrl();
} else {
zmsUrl = url;
}
if (zmsUrl != null && !zmsUrl.isEmpty()) {
if (!zmsUrl.endsWith("/zms/v1")) {
if (zmsUrl.charAt(zmsUrl.length() - 1) != '/') {
zmsUrl += '/';
}
zmsUrl += "zms/v1";
}
}
/* determine our read and connect timeouts */
int readTimeout = Integer.parseInt(System.getProperty(ZMS_CLIENT_PROP_READ_TIMEOUT, "30000"));
int connectTimeout = Integer.parseInt(System.getProperty(ZMS_CLIENT_PROP_CONNECT_TIMEOUT, "30000"));
if (sslContext == null) {
sslContext = createSSLContext();
}
ClientBuilder builder = getClientBuilder();
if (sslContext != null) {
builder = builder.sslContext(sslContext);
}
final JacksonJsonProvider jacksonJsonProvider = new JacksonJaxbJsonProvider().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
ClientConfig clientConfig = new ClientConfig(jacksonJsonProvider);
clientConfig.connectorProvider(new ApacheConnectorProvider());
// 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(clientConfig).connectTimeout(connectTimeout, TimeUnit.MILLISECONDS).readTimeout(readTimeout, TimeUnit.MILLISECONDS).build();
client = new ZMSRDLGeneratedClient(zmsUrl, rsClient);
}
Aggregations