use of org.glassfish.jersey.client.ClientConfig in project dropwizard by dropwizard.
the class Resource method before.
public void before() throws Throwable {
DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.put(configuration.getId(), configuration);
test = new JerseyTest(configuration.testContainerFactory) {
@Override
protected URI getBaseUri() {
forceSet(TestProperties.CONTAINER_PORT, "0");
return super.getBaseUri();
}
@Override
protected DeploymentContext configureDeployment() {
return ServletDeploymentContext.builder(new DropwizardTestResourceConfig(configuration)).initParam(ServletProperties.JAXRS_APPLICATION_CLASS, DropwizardTestResourceConfig.class.getName()).initParam(DropwizardTestResourceConfig.CONFIGURATION_ID, configuration.getId()).build();
}
@Override
protected void configureClient(ClientConfig clientConfig) {
final JacksonJsonProvider jsonProvider = new JacksonJsonProvider();
jsonProvider.setMapper(configuration.mapper);
configuration.clientConfigurator.accept(clientConfig);
clientConfig.register(jsonProvider);
}
};
test.setUp();
}
use of org.glassfish.jersey.client.ClientConfig in project openstack4j by ContainX.
the class ClientFactory method buildClientFromConfig.
private static Client buildClientFromConfig(Config config) {
ClientConfig clientConfig = new ClientConfig();
if (config.getProxy() != null) {
addProxy(clientConfig, config);
}
ClientBuilder cb = ClientBuilder.newBuilder().withConfig(clientConfig).property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, "true").register(JacksonFeature.class).register(RESOLVER).register(new RequestFilter());
if (config.getSslContext() != null)
cb.sslContext(config.getSslContext());
else if (config.isIgnoreSSLVerification())
cb.sslContext(UntrustedSSL.getSSLContext());
if (config.getHostNameVerifier() != null)
cb.hostnameVerifier(config.getHostNameVerifier());
else if (config.isIgnoreSSLVerification())
cb.hostnameVerifier(UntrustedSSL.getHostnameVerifier());
if (config.getReadTimeout() > 0)
cb.property(ClientProperties.READ_TIMEOUT, config.getReadTimeout());
if (config.getConnectTimeout() > 0)
cb.property(ClientProperties.CONNECT_TIMEOUT, config.getConnectTimeout());
return cb.build();
}
use of org.glassfish.jersey.client.ClientConfig 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 org.glassfish.jersey.client.ClientConfig 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 org.glassfish.jersey.client.ClientConfig 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