本文整理了Java中javax.ws.rs.client.ClientBuilder.trustStore()
方法的一些代码示例,展示了ClientBuilder.trustStore()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ClientBuilder.trustStore()
方法的具体详情如下:
包路径:javax.ws.rs.client.ClientBuilder
类名称:ClientBuilder
方法名:trustStore
[英]Set the client-side trust store. Trust store is expected to contain certificates from other parties the client is you expect to communicate with, or from Certificate Authorities that are trusted to identify other parties.
Setting a trust store instance resets any #sslContext(javax.net.ssl.SSLContext)value previously specified.
In case a custom trust store or custom SSL context is not specified, the trust management will be configured to use the default Java runtime settings.
[中]设置客户端信任存储。信任存储应包含来自您希望与之通信的客户端的其他方的证书,或来自受信任以标识其他方的证书颁发机构的证书。
设置信任存储实例将重置以前指定的任何#sslContext(javax.net.ssl.sslContext)值。
如果未指定自定义信任存储或自定义SSL上下文,信任管理将配置为使用默认Java运行时设置。
代码示例来源:origin: Netflix/eureka
private void addSSLConfiguration(ClientBuilder clientBuilder) {
try {
if (systemSSL) {
clientBuilder.sslContext(SSLContext.getDefault());
} else if (trustStoreFileName != null) {
KeyStore trustStore = KeyStore.getInstance(KEY_STORE_TYPE);
FileInputStream fin = new FileInputStream(trustStoreFileName);
trustStore.load(fin, trustStorePassword.toCharArray());
clientBuilder.trustStore(trustStore);
} else if (sslContext != null) {
clientBuilder.sslContext(sslContext);
}
} catch (Exception ex) {
throw new IllegalArgumentException("Cannot setup SSL for Jersey2 client", ex);
}
}
代码示例来源:origin: io.bootique.jersey.client/bootique-jersey-client
public HttpClientBuilder trustStore(String trustStoreName) {
delegate.trustStore(namedTrustStore(trustStoreName));
return this;
}
}
代码示例来源:origin: com.github.jmnarloch/spring-jax-rs-client-proxy
/**
* Registers the trust store.
*
* @param trustStore the trust store
* @return the builder instance
*/
public ClientBuilderConfigurer trustStore(KeyStore trustStore) {
builder().trustStore(trustStore);
return this;
}
代码示例来源:origin: com.netflix.eureka/eureka-client-jersey2
private void addSSLConfiguration(ClientBuilder clientBuilder) {
try {
if (systemSSL) {
clientBuilder.sslContext(SSLContext.getDefault());
} else if (trustStoreFileName != null) {
KeyStore trustStore = KeyStore.getInstance(KEY_STORE_TYPE);
FileInputStream fin = new FileInputStream(trustStoreFileName);
trustStore.load(fin, trustStorePassword.toCharArray());
clientBuilder.trustStore(trustStore);
} else if (sslContext != null) {
clientBuilder.sslContext(sslContext);
}
} catch (Exception ex) {
throw new IllegalArgumentException("Cannot setup SSL for Jersey2 client", ex);
}
}
代码示例来源:origin: io.bootique.jersey.client/bootique-jersey-client
@Override
public HttpClientBuilder newBuilder() {
ClientBuilder builderDelegate = ClientBuilder.newBuilder().withConfig(config);
if (trustStore != null) {
builderDelegate.trustStore(trustStore);
}
return new DefaultHttpClientBuilder(builderDelegate);
}
代码示例来源:origin: org.symphonyoss.symphony/symphony-client
/**
* Create custom client with specific keystores.
*
* @param clientKeyStore Client (BOT) keystore file
* @param clientKeyStorePass Client (BOT) keystore password
* @param trustStore Truststore file
* @param trustStorePass Truststore password
* @return Custom HttpClient
* @throws Exception Generally IOExceptions thrown from instantiation.
*/
public static Client getClient(String clientKeyStore, String clientKeyStorePass, String trustStore, String trustStorePass) throws Exception {
KeyStore cks = KeyStore.getInstance("PKCS12");
KeyStore tks = KeyStore.getInstance("JKS");
loadKeyStore(cks, clientKeyStore, clientKeyStorePass);
loadKeyStore(tks, trustStore, trustStorePass);
return ClientBuilder.newBuilder().keyStore(cks, clientKeyStorePass.toCharArray()).trustStore(tks).build();
}
代码示例来源:origin: org.symphonyoss.symphony/symphony-client
/**
* Create custom client with specific keystores.
*
* @param clientKeyStore Client (BOT) keystore
* @param clientKeyStorePass Client (BOT) keystore password
* @param trustStore Truststore
* @param trustStorePass Truststore password
* @param clientConfig - HttpClient configuration to use when constructing the client
* @return Custom HttpClient
* @throws Exception Generally IOExceptions thrown from instantiation.
*/
public static Client getClient(KeyStore clientKeyStore, String clientKeyStorePass, KeyStore trustStore, String trustStorePass, ClientConfig clientConfig) throws Exception {
return ClientBuilder.newBuilder().keyStore(clientKeyStore, clientKeyStorePass.toCharArray()).trustStore(trustStore).withConfig(clientConfig).build();
}
代码示例来源:origin: symphonyoss/symphony-java-client
/**
* Create custom client with specific keystores.
*
* @param clientKeyStore Client (BOT) keystore file
* @param clientKeyStorePass Client (BOT) keystore password
* @param trustStore Truststore file
* @param trustStorePass Truststore password
* @return Custom HttpClient
* @throws Exception Generally IOExceptions thrown from instantiation.
*/
public static Client getClient(String clientKeyStore, String clientKeyStorePass, String trustStore, String trustStorePass) throws Exception {
KeyStore cks = KeyStore.getInstance("PKCS12");
KeyStore tks = KeyStore.getInstance("JKS");
loadKeyStore(cks, clientKeyStore, clientKeyStorePass);
loadKeyStore(tks, trustStore, trustStorePass);
return ClientBuilder.newBuilder().keyStore(cks, clientKeyStorePass.toCharArray()).trustStore(tks).build();
}
代码示例来源:origin: symphonyoss/symphony-java-client
/**
* Create custom client with specific keystores.
*
* @param clientKeyStore Client (BOT) keystore
* @param clientKeyStorePass Client (BOT) keystore password
* @param trustStore Truststore
* @param trustStorePass Truststore password
* @param clientConfig - HttpClient configuration to use when constructing the client
* @return Custom HttpClient
* @throws Exception Generally IOExceptions thrown from instantiation.
*/
public static Client getClient(KeyStore clientKeyStore, String clientKeyStorePass, KeyStore trustStore, String trustStorePass, ClientConfig clientConfig) throws Exception {
return ClientBuilder.newBuilder().keyStore(clientKeyStore, clientKeyStorePass.toCharArray()).trustStore(trustStore).withConfig(clientConfig).build();
}
代码示例来源:origin: wouterd/docker-maven-plugin
private static WebTarget createDockerTarget(final String dockerApiRoot) {
String encrypted = System.getenv(ENV_DOCKER_TLS_VERIFY);
if (!"1".equals(encrypted)) {
return ClientBuilder.newClient()
.target("http://" + dockerApiRoot);
}
Security.addProvider(new BouncyCastleProvider());
String certPath = System.getenv("DOCKER_CERT_PATH");
if (certPath == null) {
certPath = System.getProperty("USER_HOME") + File.separator + ".docker";
}
ensureThatCertificatesExist(certPath);
KeyStore keyStore;
KeyStore trustStore;
try {
keyStore = HttpsHelper.createKeyStore(certPath);
trustStore = HttpsHelper.createTrustStore(certPath);
} catch (Exception e) {
throw new DockerException("Can't load docker certificates", e);
}
return ClientBuilder.newBuilder()
.keyStore(keyStore, HttpsHelper.KEYSTORE_PWD)
.trustStore(trustStore)
.build()
.target("https://" + dockerApiRoot);
}
代码示例来源:origin: hopshadoop/hopsworks
public static <T> ClientWrapper<T> httpsInstance(KeyStore keystore, KeyStore truststore,
String password, HostnameVerifier hostnameVerifier, Class<T> resultClass) {
Client client = ClientBuilder.newBuilder().trustStore(truststore).keyStore(keystore, password.toCharArray()).
hostnameVerifier(hostnameVerifier).build();
return new ClientWrapper(client, resultClass);
}
代码示例来源:origin: dremio/dremio-oss
private void setTrustStore(ClientBuilder clientBuilder, DACConfig dacConfig)
throws IOException, GeneralSecurityException {
Optional<KeyStore> trustStore = Optional.empty();
if (checkCertificates) {
trustStore = new SSLConfigurator(dacConfig.getConfig(), DremioConfig.WEB_SSL_PREFIX, "web").getTrustStore();
if (trustStore.isPresent()) {
clientBuilder.trustStore(trustStore.get());
}
} else {
SSLContext sslContext = SSLHelper.newAllTrustingSSLContext("SSL");
HostnameVerifier verifier = SSLHelper.newAllValidHostnameVerifier();
clientBuilder.hostnameVerifier(verifier);
clientBuilder.sslContext(sslContext);
}
}
代码示例来源:origin: hopshadoop/hopsworks
.trustStore(trustStore)
.hostnameVerifier(InsecureHostnameVerifier.INSTANCE)
.build();
代码示例来源:origin: com.opentable.components/otj-server-jaxrs
@Before
public void createClient() throws Exception {
final KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(keystore.openStream(), PASSWORD.toCharArray());
client = JaxRsClientFactory.testBuilder()
.trustStore(trustStore)
.build();
}
代码示例来源:origin: enioka/jqm
bld.trustStore(trust);
代码示例来源:origin: dremio/dremio-oss
protected static void initClient(final String hostname) {
client = ClientBuilder.newBuilder()
.trustStore(currentDremioDaemon.getWebServer().getTrustStore())
.register(MultiPartFeature.class)
.build();
apiV2 = client
.target(String.format("https://%s:%d", hostname, currentDremioDaemon.getWebServer().getPort()))
.path("apiv2");
}
代码示例来源:origin: apache/cxf
@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());
}
内容来源于网络,如有侵权,请联系作者删除!