當前位置: 首頁>>代碼示例>>Java>>正文


Java NoopHostnameVerifier類代碼示例

本文整理匯總了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!";
}
 
開發者ID:mystech7,項目名稱:Burp-Hunter,代碼行數:20,代碼來源:HunterRequest.java

示例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);
}
 
開發者ID:borysfan,項目名稱:websocket-poc,代碼行數:20,代碼來源:App.java

示例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;
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-skipper,代碼行數:27,代碼來源:AboutController.java

示例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);
  }
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:24,代碼來源:AvaticaCommonsHttpClientImpl.java

示例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);
    }
}
 
開發者ID:kamax-io,項目名稱:mxhsd,代碼行數:24,代碼來源:HttpFederationClient.java

示例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();
    }
}
 
開發者ID:samurayrj,項目名稱:rubenlagus-TelegramBots,代碼行數:20,代碼來源:DefaultAbsSender.java

示例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();
}
 
開發者ID:samurayrj,項目名稱:rubenlagus-TelegramBots,代碼行數:24,代碼來源:DefaultBotSession.java

示例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();
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:26,代碼來源:AbstractHttpClient.java

示例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);
}
 
開發者ID:apache,項目名稱:calcite-avatica,代碼行數:20,代碼來源:AvaticaCommonsHttpClientImplTest.java

示例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);
}
 
開發者ID:gomgomdev,項目名稱:telegram-bot_misebot,代碼行數:24,代碼來源:AbsSender.java

示例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();
  }
 
開發者ID:reflectoring,項目名稱:infiniboard,代碼行數:21,代碼來源:UrlSourceJob.java

示例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();
}
 
開發者ID:subutai-io,項目名稱:base,代碼行數:22,代碼來源:RestServiceImpl.java

示例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();
}
 
開發者ID:device42,項目名稱:rundeck-device42-nodes-plugin,代碼行數:29,代碼來源:AbstractAsynchronousRestClient.java

示例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;
}
 
開發者ID:vmware,項目名稱:loginsight-java-api,代碼行數:22,代碼來源:AsyncLogInsightConnectionStrategy.java

示例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);
	}
}
 
開發者ID:SAP,項目名稱:hybris-commerce-eclipse-plugin,代碼行數:21,代碼來源:AbstractHACCommunicationManager.java


注:本文中的org.apache.http.conn.ssl.NoopHostnameVerifier類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。