本文整理汇总了Java中org.apache.http.conn.ssl.NoopHostnameVerifier类的典型用法代码示例。如果您正苦于以下问题:Java NoopHostnameVerifier类的具体用法?Java NoopHostnameVerifier怎么用?Java NoopHostnameVerifier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NoopHostnameVerifier类属于org.apache.http.conn.ssl包,在下文中一共展示了NoopHostnameVerifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: notifyHunter
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
public String notifyHunter(byte[] content) throws IOException {
try {
String request = new String(content);
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (certificate, authType) -> true).build();
HttpClient httpclient = HttpClients.custom().setSSLContext(sslContext).setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
HttpPost httpPost = new HttpPost("https://api"+hunterDomain.substring(hunterDomain.indexOf("."))+"/api/record_injection");
String json = "{\"request\": \""+request.replace("\\", "\\\\").replace("\"", "\\\"").replace("\r\n", "\\n")+"\", \"owner_correlation_key\": \""+hunterKey+"\", \"injection_key\": \""+injectKey+"\"}";
StringEntity entity = new StringEntity(json);
entity.setContentType("applicaiton/json");
httpPost.setEntity(entity);
HttpResponse response = httpclient.execute(httpPost);
String responseString = new BasicResponseHandler().handleResponse(response);
return responseString;
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) {
Logger.getLogger(HunterRequest.class.getName()).log(Level.SEVERE, null, ex);
}
return "Error Notifying Probe Server!";
}
示例2: restTemplate
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的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: getChecksum
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
private String getChecksum(String defaultValue, String url,
String version) {
String result = defaultValue;
if (result == null && StringUtils.hasText(url)) {
CloseableHttpClient httpClient = HttpClients.custom()
.setSSLHostnameVerifier(new NoopHostnameVerifier())
.build();
HttpComponentsClientHttpRequestFactory requestFactory
= new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);
url = constructUrl(url, version);
try {
ResponseEntity<String> response
= new RestTemplate(requestFactory).exchange(
url, HttpMethod.GET, null, String.class);
if (response.getStatusCode().equals(HttpStatus.OK)) {
result = response.getBody();
}
}
catch (HttpClientErrorException httpException) {
// no action necessary set result to undefined
logger.debug("Didn't retrieve checksum because", httpException);
}
}
return result;
}
示例4: getHostnameVerifier
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
/**
* Creates the {@code HostnameVerifier} given the provided {@code verification}.
*
* @param verification The intended hostname verification action.
* @return A verifier for the request verification.
* @throws IllegalArgumentException if the provided verification cannot be handled.
*/
HostnameVerifier getHostnameVerifier(HostnameVerification verification) {
// Normally, the configuration logic would give us a default of STRICT if it was not
// provided by the user. It's easy for us to do a double-check.
if (verification == null) {
verification = HostnameVerification.STRICT;
}
switch (verification) {
case STRICT:
return SSLConnectionSocketFactory.getDefaultHostnameVerifier();
case NONE:
return NoopHostnameVerifier.INSTANCE;
default:
throw new IllegalArgumentException("Unhandled HostnameVerification: "
+ hostnameVerification);
}
}
示例5: HttpFederationClient
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
public HttpFederationClient(HomeserverState global, FederationDomainResolver resolver) {
this.global = global;
this.resolver = resolver;
try {
SocketConfig sockConf = SocketConfig.custom().setSoTimeout(30000).build();
// FIXME properly handle SSL context by validating certificate hostname
SSLContext sslContext = SSLContextBuilder.create().loadTrustMaterial(new TrustAllStrategy()).build();
HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
this.client = HttpClientBuilder.create()
.disableAuthCaching()
.disableAutomaticRetries()
.disableCookieManagement()
.disableRedirectHandling()
.setDefaultSocketConfig(sockConf)
.setSSLSocketFactory(sslSocketFactory)
.setUserAgent(global.getAppName() + "/" + global.getAppVersion())
.build();
} catch (KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) {
throw new RuntimeException(e);
}
}
示例6: DefaultAbsSender
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
protected DefaultAbsSender(DefaultBotOptions options) {
super();
this.exe = Executors.newFixedThreadPool(options.getMaxThreads());
this.options = options;
httpclient = HttpClientBuilder.create()
.setSSLHostnameVerifier(new NoopHostnameVerifier())
.setConnectionTimeToLive(70, TimeUnit.SECONDS)
.setMaxConnTotal(100)
.build();
requestConfig = options.getRequestConfig();
if (requestConfig == null) {
requestConfig = RequestConfig.copy(RequestConfig.custom().build())
.setSocketTimeout(SOCKET_TIMEOUT)
.setConnectTimeout(SOCKET_TIMEOUT)
.setConnectionRequestTimeout(SOCKET_TIMEOUT).build();
}
}
示例7: start
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
@Override
public synchronized void start() {
httpclient = HttpClientBuilder.create()
.setSSLHostnameVerifier(new NoopHostnameVerifier())
.setConnectionTimeToLive(70, TimeUnit.SECONDS)
.setMaxConnTotal(100)
.build();
requestConfig = options.getRequestConfig();
exponentialBackOff = options.getExponentialBackOff();
if (exponentialBackOff == null) {
exponentialBackOff = new ExponentialBackOff();
}
if (requestConfig == null) {
requestConfig = RequestConfig.copy(RequestConfig.custom().build())
.setSocketTimeout(SOCKET_TIMEOUT)
.setConnectTimeout(SOCKET_TIMEOUT)
.setConnectionRequestTimeout(SOCKET_TIMEOUT).build();
}
super.start();
}
示例8: getCustomClient
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
/**
* custom http client for server with SSL errors
*
* @return
*/
public final CloseableHttpClient getCustomClient() {
try {
HttpClientBuilder builder = HttpClientBuilder.create().useSystemProperties();
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null,
(TrustStrategy) (X509Certificate[] arg0, String arg1) -> true).build();
builder.setSSLContext(sslContext);
HostnameVerifier hostnameVerifier = new NoopHostnameVerifier();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslSocketFactory)
.build();
PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
builder.setConnectionManager(connMgr);
return builder.build();
} catch (Exception ex) {
LOG.log(Level.SEVERE, ex.getMessage(), ex);
}
return getSystemClient();
}
示例9: testHostnameVerification
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
@Test public void testHostnameVerification() throws Exception {
AvaticaCommonsHttpClientImpl client = mock(AvaticaCommonsHttpClientImpl.class);
// Call the real method
when(client.getHostnameVerifier(nullable(HostnameVerification.class)))
.thenCallRealMethod();
// No verification should give the default (strict) verifier
HostnameVerifier actualVerifier = client.getHostnameVerifier(null);
assertNotNull(actualVerifier);
assertTrue(actualVerifier instanceof DefaultHostnameVerifier);
actualVerifier = client.getHostnameVerifier(HostnameVerification.STRICT);
assertNotNull(actualVerifier);
assertTrue(actualVerifier instanceof DefaultHostnameVerifier);
actualVerifier = client.getHostnameVerifier(HostnameVerification.NONE);
assertNotNull(actualVerifier);
assertTrue(actualVerifier instanceof NoopHostnameVerifier);
}
示例10: sendApiMethod
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
private Serializable sendApiMethod(BotApiMethod method) throws TelegramApiException {
String responseContent;
try {
CloseableHttpClient httpclient = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
String url = getBaseUrl() + method.getPath();
HttpPost httppost = new HttpPost(url);
httppost.addHeader("charset", StandardCharsets.UTF_8.name());
httppost.setEntity(new StringEntity(method.toJson().toString(), ContentType.APPLICATION_JSON));
CloseableHttpResponse response = httpclient.execute(httppost);
HttpEntity ht = response.getEntity();
BufferedHttpEntity buf = new BufferedHttpEntity(ht);
responseContent = EntityUtils.toString(buf, StandardCharsets.UTF_8);
} catch (IOException e) {
throw new TelegramApiException("Unable to execute " + method.getPath() + " method", e);
}
JSONObject jsonObject = new JSONObject(responseContent);
if (!jsonObject.getBoolean(Constants.RESPONSEFIELDOK)) {
throw new TelegramApiException("Error at " + method.getPath(), jsonObject.getString("description"));
}
return method.deserializeResponse(jsonObject);
}
示例11: configureHttpClient
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
CloseableHttpClient configureHttpClient(boolean enableSslVerify) {
HttpClientBuilder builder = HttpClientBuilder.create();
if (enableSslVerify) {
return builder.build();
}
SSLContext sslContext = null;
try {
sslContext =
new SSLContextBuilder().loadTrustMaterial(null, (x509Certificates, s) -> true).build();
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
LOG.error("Could not create ssl context", e);
}
builder.setSSLHostnameVerifier(new NoopHostnameVerifier()).setSSLContext(sslContext);
return builder.build();
}
示例12: getHttpsClient
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
private CloseableHttpClient getHttpsClient()
{
try
{
RequestConfig config = RequestConfig.custom().setSocketTimeout( 5000 ).setConnectTimeout( 5000 ).build();
SSLContextBuilder sslContextBuilder = new SSLContextBuilder();
sslContextBuilder.loadTrustMaterial( null, ( TrustStrategy ) ( x509Certificates, s ) -> true );
SSLConnectionSocketFactory sslSocketFactory =
new SSLConnectionSocketFactory( sslContextBuilder.build(), NoopHostnameVerifier.INSTANCE );
return HttpClients.custom().setDefaultRequestConfig( config ).setSSLSocketFactory( sslSocketFactory )
.build();
}
catch ( Exception e )
{
LOGGER.error( e.getMessage() );
}
return HttpClients.createDefault();
}
示例13: createHttpClient
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
/**
* Create the HTTP clean with basic authentication mechanism using specified
* credentials
*
* @param username
* Authentication username
* @param password
* Authentication password
* @return
*/
protected static CloseableHttpClient createHttpClient(String username, String password) {
SSLContext sslContext = createSslContext();
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
Header header = new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json");
List<Header> headers = Arrays.asList(header);
return HttpClients.custom()
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.setSSLSocketFactory(sslSocketFactory)
.setDefaultCredentialsProvider(credentialsProvider)
.setDefaultHeaders(headers)
.build();
}
示例14: getHttpClient
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
/**
* Initializes and returns the httpClient with NoopHostnameVerifier
*
* @return CloseableHttpAsyncClient
*/
@Override
public CloseableHttpAsyncClient getHttpClient() {
// Trust own CA and all self-signed certs
SSLContext sslcontext = NonValidatingSSLSocketFactory.getSSLContext();
// Allow TLSv1 protocol only
SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(sslcontext, new String[] { "TLSv1" }, null,
new NoopHostnameVerifier());
List<Header> headers = LogInsightClient.getDefaultHeaders();
asyncHttpClient = HttpAsyncClients.custom().setSSLStrategy(sslSessionStrategy).setDefaultHeaders(headers)
.build();
asyncHttpClient.start();
return asyncHttpClient;
}
示例15: getSSLAcceptingClient
import org.apache.http.conn.ssl.NoopHostnameVerifier; //导入依赖的package包/类
/**
* Creates {@link HttpClient} that trusts any SSL certificate
*
* @return prepared HTTP client
*/
protected HttpClient getSSLAcceptingClient() {
final TrustStrategy trustAllStrategy = (final X509Certificate[] chain, final String authType) -> true;
try {
final SSLContext sslContext = SSLContexts.custom().loadTrustMaterial(null, trustAllStrategy).build();
sslContext.init(null, getTrustManager(), new SecureRandom());
final SSLConnectionSocketFactory connectionSocketFactory = new SSLConnectionSocketFactory(sslContext,
new NoopHostnameVerifier());
return HttpClients.custom().setSSLSocketFactory(connectionSocketFactory).build();
} catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException error) {
ConsoleUtils.printError(error.getMessage());
throw new IllegalStateException(ErrorMessage.CANNOT_CREATE_SSL_SOCKET, error);
}
}