本文整理匯總了Java中javax.ws.rs.client.ClientBuilder.sslContext方法的典型用法代碼示例。如果您正苦於以下問題:Java ClientBuilder.sslContext方法的具體用法?Java ClientBuilder.sslContext怎麽用?Java ClientBuilder.sslContext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.ws.rs.client.ClientBuilder
的用法示例。
在下文中一共展示了ClientBuilder.sslContext方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createClientFromConfig
import javax.ws.rs.client.ClientBuilder; //導入方法依賴的package包/類
private static Client createClientFromConfig(NiFiRegistryClientConfig registryClientConfig) {
final ClientConfig clientConfig = new ClientConfig();
clientConfig.register(jacksonJaxbJsonProvider());
final ClientBuilder clientBuilder = ClientBuilder.newBuilder().withConfig(clientConfig);
final SSLContext sslContext = registryClientConfig.getSslContext();
if (sslContext != null) {
clientBuilder.sslContext(sslContext);
}
final HostnameVerifier hostnameVerifier = registryClientConfig.getHostnameVerifier();
if (hostnameVerifier != null) {
clientBuilder.hostnameVerifier(hostnameVerifier);
}
return clientBuilder.build();
}
示例2: configure
import javax.ws.rs.client.ClientBuilder; //導入方法依賴的package包/類
@Override
public void configure(HttpConfig config, ScriptContext context) {
ClientConfig cc = new ClientConfig();
// support request body for DELETE (non-standard)
cc.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
if (!config.isFollowRedirects()) {
cc.property(ClientProperties.FOLLOW_REDIRECTS, false);
}
ClientBuilder clientBuilder = ClientBuilder.newBuilder()
.withConfig(cc)
.register(new LoggingInterceptor(context)) // must be first
.register(MultiPartFeature.class);
if (config.isSslEnabled()) {
SSLContext sslContext;
if (config.getSslTrustStore() != null) {
String trustStoreFile = config.getSslTrustStore();
String password = config.getSslTrustStorePassword();
char[] passwordChars = password == null ? null : password.toCharArray();
String algorithm = config.getSslAlgorithm();
String type = config.getSslTrustStoreType();
if (type == null) {
type = KeyStore.getDefaultType();
}
try {
KeyStore trustStore = KeyStore.getInstance(type);
InputStream is = FileUtils.getFileStream(trustStoreFile, context);
trustStore.load(is, passwordChars);
context.logger.debug("trust store key count: {}", trustStore.size());
sslContext = SslConfigurator.newInstance()
.securityProtocol(algorithm) // will default to TLS if null
.trustStore(trustStore)
// .keyStore(trustStore)
.createSSLContext();
} catch (Exception e) {
context.logger.error("ssl config failed: {}", e.getMessage());
throw new RuntimeException(e);
}
} else {
sslContext = HttpUtils.getSslContext(config.getSslAlgorithm());
}
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
clientBuilder.sslContext(sslContext);
clientBuilder.hostnameVerifier((host, session) -> true);
}
client = clientBuilder.build();
client.property(ClientProperties.CONNECT_TIMEOUT, config.getConnectTimeout());
client.property(ClientProperties.READ_TIMEOUT, config.getReadTimeout());
if (config.getProxyUri() != null) {
client.property(ClientProperties.PROXY_URI, config.getProxyUri());
if (config.getProxyUsername() != null && config.getProxyPassword() != null) {
client.property(ClientProperties.PROXY_USERNAME, config.getProxyUsername());
client.property(ClientProperties.PROXY_PASSWORD, config.getProxyPassword());
}
}
}
示例3: createBackup
import javax.ws.rs.client.ClientBuilder; //導入方法依賴的package包/類
public static BackupStats createBackup(DACConfig dacConfig, String userName, String password, KeyStore trustStore, URI uri) throws IOException {
final JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
provider.setMapper(JSONUtil.prettyMapper());
ClientBuilder clientBuilder = ClientBuilder.newBuilder()
.register(provider)
.register(MultiPartFeature.class);
if (trustStore != null) {
clientBuilder.trustStore(trustStore);
} else {
SSLContext sslContext = SSLHelper.newAllTrustingSSLContext("SSL");
HostnameVerifier verifier = SSLHelper.newAllValidHostnameVerifier();
clientBuilder.hostnameVerifier(verifier);
clientBuilder.sslContext(sslContext);
}
final Client client = clientBuilder.build();
WebTarget target = client.target(format("%s://%s:%d",
dacConfig.webSSLEnabled ? "https" : "http", dacConfig.masterNode, dacConfig.getHttpPort())).path("apiv2");
final UserLogin userLogin = new UserLogin(userName, password);
final UserLoginSession userLoginSession = readEntity(UserLoginSession.class, target.path("/login").request(JSON).buildPost(Entity.json(userLogin)));
return readEntity(BackupStats.class, target.path("/backup").request(JSON).header(HttpHeader.AUTHORIZATION.toString(),
TokenUtils.AUTH_HEADER_PREFIX + userLoginSession.getToken()).buildPost(Entity.json(uri.toString())));
}
示例4: JerseyNiFiRegistryClient
import javax.ws.rs.client.ClientBuilder; //導入方法依賴的package包/類
private JerseyNiFiRegistryClient(final NiFiRegistryClient.Builder builder) {
final NiFiRegistryClientConfig registryClientConfig = builder.getConfig();
if (registryClientConfig == null) {
throw new IllegalArgumentException("NiFiRegistryClientConfig cannot be null");
}
String baseUrl = registryClientConfig.getBaseUrl();
if (StringUtils.isBlank(baseUrl)) {
throw new IllegalArgumentException("Base URL cannot be blank");
}
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
}
if (!baseUrl.endsWith(NIFI_REGISTRY_CONTEXT)) {
baseUrl = baseUrl + "/" + NIFI_REGISTRY_CONTEXT;
}
try {
new URI(baseUrl);
} catch (final Exception e) {
throw new IllegalArgumentException("Invalid base URL: " + e.getMessage(), e);
}
final SSLContext sslContext = registryClientConfig.getSslContext();
final HostnameVerifier hostnameVerifier = registryClientConfig.getHostnameVerifier();
final ClientBuilder clientBuilder = ClientBuilder.newBuilder();
if (sslContext != null) {
clientBuilder.sslContext(sslContext);
}
if (hostnameVerifier != null) {
clientBuilder.hostnameVerifier(hostnameVerifier);
}
final int connectTimeout = registryClientConfig.getConnectTimeout() == null ? DEFAULT_CONNECT_TIMEOUT : registryClientConfig.getConnectTimeout();
final int readTimeout = registryClientConfig.getReadTimeout() == null ? DEFAULT_READ_TIMEOUT : registryClientConfig.getReadTimeout();
final ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.CONNECT_TIMEOUT, connectTimeout);
clientConfig.property(ClientProperties.READ_TIMEOUT, readTimeout);
clientConfig.register(jacksonJaxbJsonProvider());
clientBuilder.withConfig(clientConfig);
this.client = clientBuilder.build();
this.baseTarget = client.target(baseUrl);
this.bucketClient = new JerseyBucketClient(baseTarget);
this.flowClient = new JerseyFlowClient(baseTarget);
this.flowSnapshotClient = new JerseyFlowSnapshotClient(baseTarget);
this.itemsClient = new JerseyItemsClient(baseTarget);
}