本文整理匯總了Java中org.apache.http.conn.ssl.TrustSelfSignedStrategy類的典型用法代碼示例。如果您正苦於以下問題:Java TrustSelfSignedStrategy類的具體用法?Java TrustSelfSignedStrategy怎麽用?Java TrustSelfSignedStrategy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
TrustSelfSignedStrategy類屬於org.apache.http.conn.ssl包,在下文中一共展示了TrustSelfSignedStrategy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getConnctionManager
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
public static PoolingHttpClientConnectionManager getConnctionManager(){
Registry<ConnectionSocketFactory> socketFactoryRegistry = null;
try {
SSLConnectionSocketFactory trustSelfSignedSocketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(),
new TrustAllHostNameVerifier());
socketFactoryRegistry = RegistryBuilder
.<ConnectionSocketFactory> create()
.register("http", new PlainConnectionSocketFactory())
.register("https", trustSelfSignedSocketFactory)
.build();
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
Data.logger.warn("", e);
}
PoolingHttpClientConnectionManager cm = (socketFactoryRegistry != null) ?
new PoolingHttpClientConnectionManager(socketFactoryRegistry):
new PoolingHttpClientConnectionManager();
// twitter specific options
cm.setMaxTotal(2000);
cm.setDefaultMaxPerRoute(200);
return cm;
}
示例2: restTemplate
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
@Bean
public RestTemplate restTemplate() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(null, new TrustSelfSignedStrategy())
.build();
SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, NoopHostnameVerifier.INSTANCE);
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLSocketFactory(sslConnectionSocketFactory)
.build();
HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
return new RestTemplate(requestFactory);
}
示例3: testHome
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
@Test
public void testHome() throws Exception {
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder()
.loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
.build();
TestRestTemplate testRestTemplate = new TestRestTemplate();
((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRequestFactory())
.setHttpClient(httpClient);
ResponseEntity<String> entity = testRestTemplate
.getForEntity("https://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertTrue( "Result is not Matched with Server Response",entity.getBody().contains("welcome to the application"));
}
示例4: createRestTemplate
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
private static RestTemplate createRestTemplate(String host, String username, String password, Set<ClientHttpRequestInterceptor> interceptors) throws GeneralSecurityException {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(host, 25555),
new UsernamePasswordCredentials(username, password));
SSLContext sslContext = SSLContexts.custom()
.loadTrustMaterial(null, new TrustSelfSignedStrategy())
.useTLS()
.build();
SSLConnectionSocketFactory connectionFactory = new SSLConnectionSocketFactory(sslContext, new AllowAllHostnameVerifier());
HttpClient httpClient = HttpClientBuilder.create()
.disableRedirectHandling()
.setDefaultCredentialsProvider(credentialsProvider)
.setSSLSocketFactory(connectionFactory)
.build();
RestTemplate restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory(httpClient));
restTemplate.getInterceptors().addAll(interceptors);
return restTemplate;
}
示例5: getSSLConnectionSocketFactory
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
private SSLConnectionSocketFactory getSSLConnectionSocketFactory() {
// Trust own CA and all self-signed certificates
SSLContext sslcontext = null;
try {
sslcontext = SSLContexts.custom()
.loadTrustMaterial(new File("sepa.jks"), "*sepa.jks*".toCharArray(),new TrustSelfSignedStrategy())
.build();
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException | CertificateException
| IOException e1) {
logger.error(e1.getMessage());
return null;
}
// Allow TLSv1 protocol only
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
sslcontext,
new String[] { "TLSv1" },
null,
new SEPAHostnameVerifier());
return sslsf;
}
示例6: init
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
public void init() {
try {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
/* 配置同時支持 HTTP 和 HTPPS */
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslsf).build();
/* 初始化連接管理器 */
poolConnManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
poolConnManager.setMaxTotal(maxTotal);
poolConnManager.setDefaultMaxPerRoute(defaultMaxPerRoute);
requestConfig = RequestConfig.custom().setConnectionRequestTimeout(connectionRequestTimeout)
.setSocketTimeout(socketTimeout).setConnectTimeout(connectTimeout).build();
httpClient = getConnection();
log.info("HttpConnectionManager初始化完成...");
} catch (Exception e) {
log.error("error", e);
}
}
示例7: triggerHttpGetWithCustomSSL
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
public static String triggerHttpGetWithCustomSSL(String requestUrl) {
String result = null;
try {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy() {
public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
return true;
}
});
@SuppressWarnings("deprecation")
HostnameVerifier hostnameVerifier = SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), hostnameVerifier);
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
HttpGet httpGet = new HttpGet("https://" + requestUrl);
CloseableHttpResponse response = httpclient.execute(httpGet);
try {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
result = EntityUtils.toString(entity);
log.debug("Received response: " + result);
} else {
log.error("Request not successful. StatusCode was " + response.getStatusLine().getStatusCode());
}
} finally {
response.close();
}
} catch (IOException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
log.error("Error executing the request.", e);
}
return result;
}
示例8: contextLoads
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
@Test
public void contextLoads() throws Exception {
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
((HttpComponentsClientHttpRequestFactory) restTemplate.getRestTemplate().getRequestFactory())
.setHttpClient(httpClient);
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<ExecutionStatus> response = restTemplate.exchange("https://localhost:"
+ this.port + this.contextRoot + this.jerseycontextRoot + "/execute?env=stage&key=PING",
HttpMethod.GET, entity, ExecutionStatus.class);
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
Assert.assertEquals(new Integer(0), response.getBody().getCode());
Assert.assertNotNull(response.getBody().getOutput());
httpClient.close();
}
示例9: hello
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
@Test
public void hello() throws Exception {
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
((HttpComponentsClientHttpRequestFactory) restTemplate.getRestTemplate().getRequestFactory())
.setHttpClient(httpClient);
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.TEXT_PLAIN));
HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<String> response = restTemplate.exchange("https://localhost:"
+ this.port + this.contextRoot + this.jerseycontextRoot + "/execute/hello",
HttpMethod.GET, entity, String.class);
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
Assert.assertNotNull(response.getBody());
httpClient.close();
}
示例10: executeCommands
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
@Test
public void executeCommands() throws Exception {
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
((HttpComponentsClientHttpRequestFactory) restTemplate.getRestTemplate().getRequestFactory())
.setHttpClient(httpClient);
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<HashMap<String, String>> requestEntity =
new HttpEntity<>(headers);
ResponseEntity<ExecutionStatus> response = restTemplate.exchange(
"https://localhost:" + this.port + this.contextRoot + this.jerseycontextRoot + "/execute"
+ "?key=DEPLOY&groupId=service.registration&name=assurantregistrationservice&version=2.1.6&clusterName=aebedx&env=stage",
HttpMethod.POST, requestEntity, ExecutionStatus.class);
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
httpClient.close();
}
示例11: executeCommands_Bounce
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
@Test
public void executeCommands_Bounce() throws Exception {
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
((HttpComponentsClientHttpRequestFactory) restTemplate.getRestTemplate().getRequestFactory())
.setHttpClient(httpClient);
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<HashMap<String, String>> requestEntity =
new HttpEntity<>(headers);
ResponseEntity<ExecutionStatus> response = restTemplate.exchange(
"https://localhost:" + this.port + this.contextRoot + this.jerseycontextRoot + "/execute"
+ "?key=BOUNCE&groupId=service.registration&name=assurantregistrationservice&version=2.1.6&clusterName=aebmobile&env=dev",
HttpMethod.POST, requestEntity, ExecutionStatus.class);
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
httpClient.close();
}
示例12: executeCommands_Status
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
@Test
public void executeCommands_Status() throws Exception {
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
((HttpComponentsClientHttpRequestFactory) restTemplate.getRestTemplate().getRequestFactory())
.setHttpClient(httpClient);
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<HashMap<String, String>> requestEntity =
new HttpEntity<>(headers);
ResponseEntity<ExecutionStatus> response = restTemplate.exchange(
"https://localhost:" + this.port + this.contextRoot + this.jerseycontextRoot + "/execute"
+ "?key=STATUS&groupId=service.registration&name=assurantregistrationservice&version=2.1.6&clusterName=aebedx&env=stage",
HttpMethod.POST, requestEntity, ExecutionStatus.class);
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
httpClient.close();
}
示例13: executeCommands_NoKey
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
@Test
public void executeCommands_NoKey() throws Exception {
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
((HttpComponentsClientHttpRequestFactory) restTemplate.getRestTemplate().getRequestFactory())
.setHttpClient(httpClient);
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<HashMap<String, String>> requestEntity =
new HttpEntity<>(headers);
ResponseEntity<Object> response = restTemplate.exchange(
"https://localhost:" + this.port + this.contextRoot + this.jerseycontextRoot + "/execute",
HttpMethod.POST, requestEntity, Object.class);
Assert.assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
Assert.assertNotNull(response.getBody());
httpClient.close();
}
示例14: init
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
public void init()
{
try
{
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
Unirest.setHttpClient(httpclient);
}
catch (Exception e)
{
System.out.println("Failed to start server: " + e.toString());
e.printStackTrace();
}
}
示例15: testWelcome
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; //導入依賴的package包/類
@Test
public void testWelcome() throws Exception {
SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
new SSLContextBuilder()
.loadTrustMaterial(null, new TrustSelfSignedStrategy()).build());
HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory)
.build();
TestRestTemplate testRestTemplate = new TestRestTemplate();
((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRequestFactory())
.setHttpClient(httpClient);
ResponseEntity<String> entity = testRestTemplate
.getForEntity("https://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode());
assertEquals("welcome to the application "+System.getProperty("user.name"), entity.getBody());
}