List of usage examples for org.apache.http.conn.ssl SSLConnectionSocketFactory BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
X509HostnameVerifier BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
To view the source code for org.apache.http.conn.ssl SSLConnectionSocketFactory BROWSER_COMPATIBLE_HOSTNAME_VERIFIER.
Click Source Link
From source file:org.sonatype.nexus.internal.httpclient.HttpClientFactoryImpl.java
private ManagedClientConnectionManager createClientConnectionManager(final List<SSLContextSelector> selectors) { final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", new NexusSSLConnectionSocketFactory( (javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault(), SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER, selectors)) .build();/*from ww w . j av a2 s. c om*/ final ManagedClientConnectionManager connManager = new ManagedClientConnectionManager(registry); final int maxConnectionCount = SystemPropertiesHelper.getInteger(CONNECTION_POOL_MAX_SIZE_KEY, CONNECTION_POOL_MAX_SIZE_DEFAULT); final int poolSize = SystemPropertiesHelper.getInteger(CONNECTION_POOL_SIZE_KEY, CONNECTION_POOL_SIZE_DEFAULT); final int perRouteConnectionCount = Math.min(poolSize, maxConnectionCount); connManager.setMaxTotal(maxConnectionCount); connManager.setDefaultMaxPerRoute(perRouteConnectionCount); return connManager; }
From source file:co.paralleluniverse.fibers.dropwizard.FiberHttpClientBuilder.java
private static Registry<SchemeIOSessionStrategy> convertRegistry(final SchemeRegistry oldRegistry) throws SSLInitializationException { SchemeRegistry baseRegistry = oldRegistry; //TODO: use values from old registry; Registry<SchemeIOSessionStrategy> defaultRegistry = RegistryBuilder.<SchemeIOSessionStrategy>create() .register("http", NoopIOSessionStrategy.INSTANCE) .register("https", new SSLIOSessionStrategy(SSLContexts.createDefault(), null, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER)) .build();/*from ww w .ja va2 s . c om*/ return defaultRegistry; }
From source file:br.com.intercomex.ws.GnreLoteRecepcao.java
/** * This is a sample web service operation *///from w w w . jav a2 s . com @WebMethod(operationName = "processar") public br.gov.pe.gnre.TRetLoteGNRE processar(@WebParam(name = "gnreDadosMsg") TLoteGNRE TLoteGNRE) { br.gov.pe.gnre.TRetLoteGNRE retorno = null; try { loadConfig(); XmlUtil util = new XmlUtil(); //<TConsultaConfigUf xmlns=\"http://www.gnre.pe.gov.br\"><ambiente>1</ambiente><uf>MG</uf><receita>100048</receita></TConsultaConfigUf> String gnreDadosMsgSTR = util.convertToXml(TLoteGNRE, br.gov.pe.gnre.TLoteGNRE.class); //System.out.println("PARAMETRO envio ==== "+TLoteGNRE); //String gnreDadosMsgSTR= util.nodeToString((Node)TLoteGNRE); String XML_DATA = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:gnr=\"http://www.gnre.pe.gov.br/webservice/GnreLoteRecepcao\">" + "<soap:Header><gnr:gnreCabecMsg><gnr:versaoDados>1.00</gnr:versaoDados></gnr:gnreCabecMsg></soap:Header>" + "<soap:Body><gnr:gnreDadosMsg>" + gnreDadosMsgSTR + "</gnr:gnreDadosMsg></soap:Body></soap:Envelope>"; System.out.println("PARAMETRO envio ==== " + XML_DATA); HttpPost httpPost = new HttpPost(url); httpPost.setHeader(new BasicHeader("Content-Type", "application/soap+xml;charset=UTF-8")); httpPost.setHeader(new BasicHeader("SOAPAction", action)); StringEntity s = new StringEntity(XML_DATA, "UTF-8"); httpPost.setEntity(s); FileInputStream instream = null; FileInputStream instreamTrust = null; KeyStore keyStore = KeyStore.getInstance("PKCS12"); instream = new FileInputStream(new File(caminhoDoCertificadoDoCliente)); keyStore.load(instream, senhaDoCertificadoDoCliente.toCharArray()); KeyStore trustStore = KeyStore.getInstance("JKS"); instreamTrust = new FileInputStream(new File(arquivoCacertsGeradoParaCadaEstado)); trustStore.load(instreamTrust, senhaDoCertificadoDoCliente.toCharArray()); SSLContextBuilder builder = SSLContexts.custom().loadTrustMaterial(trustStore); builder.loadKeyMaterial(keyStore, senhaDoCertificadoDoCliente.toCharArray()); SSLContext sslcontext = builder.build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpclientSLL = HttpClients.custom().setSSLSocketFactory(sslsf).build(); System.out.println("executing request" + httpPost.getRequestLine()); HttpResponse response = httpclientSLL.execute(httpPost); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); String retornoStr = EntityUtils.toString(entity); System.out.println("Response " + retornoStr); retorno = util.getTRetLoteGNRE(retornoStr); } if (entity != null) { entity.consumeContent(); } httpclient.getConnectionManager().shutdown(); } catch (UnsupportedEncodingException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (KeyStoreException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (CertificateException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (UnrecoverableKeyException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (KeyManagementException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } return retorno; }
From source file:br.com.intercomex.ws.EnviarLoteService.java
private String processarServico(Object TLoteGNRE, String urlParam, String actionParam) { br.gov.pe.gnre.TRetLoteGNRE retorno = null; String recibo = null;// w w w . j av a 2 s. co m try { loadConfig(); XmlUtil util = new XmlUtil(); //<TConsultaConfigUf xmlns=\"http://www.gnre.pe.gov.br\"><ambiente>1</ambiente><uf>MG</uf><receita>100048</receita></TConsultaConfigUf> System.out.println("PARAMETRO envio ==== " + TLoteGNRE); //String gnreDadosMsgSTR= util.convertToXml(TLoteGNRE, br.gov.pe.gnre.TLoteGNRE.class); //String gnreDadosMsgSTR= TLoteGNRE; String gnreDadosMsgSTR = util.nodeToString((Node) TLoteGNRE); String XML_DATA = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:gnr=\"http://www.gnre.pe.gov.br/webservice/GnreLoteRecepcao\">" + "<soap:Header><gnr:gnreCabecMsg><gnr:versaoDados>1.00</gnr:versaoDados></gnr:gnreCabecMsg></soap:Header>" + "<soap:Body><gnr:gnreDadosMsg>" + gnreDadosMsgSTR + "</gnr:gnreDadosMsg></soap:Body></soap:Envelope>"; System.out.println("PARAMETRO envio ==== " + XML_DATA); HttpPost httpPost = new HttpPost(urlParam); httpPost.setHeader(new BasicHeader("Content-Type", "application/soap+xml;charset=UTF-8")); httpPost.setHeader(new BasicHeader("SOAPAction", actionParam)); StringEntity s = new StringEntity(XML_DATA, "UTF-8"); httpPost.setEntity(s); FileInputStream instream = null; FileInputStream instreamTrust = null; KeyStore keyStore = KeyStore.getInstance("PKCS12"); instream = new FileInputStream(new File(caminhoDoCertificadoDoCliente)); keyStore.load(instream, senhaDoCertificadoDoCliente.toCharArray()); KeyStore trustStore = KeyStore.getInstance("JKS"); instreamTrust = new FileInputStream(new File(arquivoCacertsGeradoParaCadaEstado)); trustStore.load(instreamTrust, senhaDoCertificadoDoCliente.toCharArray()); SSLContextBuilder builder = SSLContexts.custom().loadTrustMaterial(trustStore); builder.loadKeyMaterial(keyStore, senhaDoCertificadoDoCliente.toCharArray()); SSLContext sslcontext = builder.build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); CloseableHttpClient httpclientSLL = HttpClients.custom().setSSLSocketFactory(sslsf).build(); System.out.println("executing request" + httpPost.getRequestLine()); HttpResponse response = httpclientSLL.execute(httpPost); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); String retornoStr = EntityUtils.toString(entity); System.out.println("Response " + retornoStr); retorno = util.getTRetLoteGNRE(retornoStr); recibo = util.getRecibo(retornoStr); System.out.println("ResponseOBJ " + recibo); } if (entity != null) { entity.consumeContent(); } httpclient.getConnectionManager().shutdown(); } catch (UnsupportedEncodingException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (KeyStoreException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (CertificateException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (UnrecoverableKeyException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } catch (KeyManagementException ex) { Logger.getLogger(GnreConfigUF.class.getName()).log(Level.SEVERE, null, ex); } return recibo; }
From source file:com.zacwolf.commons.wbxcon.WBXCONorg.java
/** * Class <code>Contructor</code> initializes WBXCONorg instance for the given managed org (domain) instance. * As part of initialization the Constructor makes a call to establish orgID and namespaceID for the domain. * /*from w w w .j av a 2 s .co m*/ * The REST API calls are made via https GET and POST. As such, the <code>HTTPSCLIENT</code> needs to be * initialized via a certificate stored in a default keystore. Since the keystore contains a "static" * certificate provided by WebEx Connect, the keystore is generated "in source". If WebEx Connect modifies * their default https certificate, you will need to download the latest version of this package from:<br /> * <br /> * <a href="https://github.com/ZacWolf/com.zacwolf.commons">https://github.com/ZacWolf/com.zacwolf.commons</a> * * * Whatever user is specified for wapiUSER, the following special privileges need to be granted to the account: * * WBX:ManageDomain * WBX:ManageUsers * WBX:ManageRoles * * @param domain_name Name of the WebEx Connect Managed Org * @param wapiAUTHURL (optional) URL used to override the default URL used to generate the initial login token * @param wapiUSER WebEx UserName to use in making the REST calls * @param wapiPASS WebEx user password to use in making the REST calls * @throws WBXCONexception */ WBXCONorg(final String domain_name, final String wapiAUTHURL, final String wapiUSER, final String wapiPASS) throws WBXCONexception { if (HTTPSCLIENT == null) try { //Quiet the various apache http client loggers Logger.getLogger("org.apache.http").setLevel(Level.SEVERE); Logger.getLogger("org.apache.http.wire").setLevel(Level.SEVERE); Logger.getLogger("org.apache.http.headers").setLevel(Level.SEVERE); System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog"); System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true"); System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "ERROR"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "ERROR"); System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "ERROR"); final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(MAX_HTTP_REQUESTS); final KeyStore trustStore = KeyStore.getInstance("JCEKS"); // Use the default keystore that is in the same package directory final InputStream instream = WBXCONorg.class.getClassLoader().getResourceAsStream( WBXCONorg.class.getPackage().getName().replaceAll("\\.", "/") + "/" + TRUSTSTOREFILENAME); try { trustStore.load(instream, TRUSTSTOREPASS.toCharArray()); } finally { instream.close(); } final SSLContext sslcontext = SSLContexts.custom()// Trust own CA and all self-signed certs .loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()).build(); final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, // Allow TLSv1 protocol only null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); final RequestConfig config = RequestConfig.custom().setConnectTimeout(HTTP_TIMEOUT * 60000) .setConnectionRequestTimeout(HTTP_TIMEOUT * 60000).setSocketTimeout(HTTP_TIMEOUT * 60000) .build(); HTTPSCLIENT = HttpClients.custom().setConnectionManager(cm).setSSLSocketFactory(sslsf) .setDefaultRequestConfig(config).build(); } catch (final Exception e) { System.err.println(WBXCONorg.class.getCanonicalName() + " UNABLE TO ESTABLISH HTTPSCLIENT FOR WAPI CALLS. All WAPI CALLS WILL FAIL!!!"); e.printStackTrace(); //System.exit(2); } Runtime.getRuntime().addShutdownHook(new Thread("WBXCONorg shutdownhook") { @Override public void run() { try { finalize(); } catch (final Throwable e) { e.printStackTrace(); } } }); this.orgName = domain_name; this.wapiAUTHURL = wapiAUTHURL != null ? wapiAUTHURL : this.wapiAUTHURL; this.wapiUSER = wapiUSER + (!wapiUSER.endsWith("@" + domain_name) ? "@" + domain_name : ""); this.wapiPASS = wapiPASS; final Document dom; try { System.out.println("=============== 1"); final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); System.out.println("=============== 2"); factory.setValidating(false); System.out.println("=============== 3"); factory.setCoalescing(true); System.out.println("=============== 4"); final DocumentBuilder db = factory.newDocumentBuilder(); System.out.println("=============== 5"); final List<NameValuePair> params = new ArrayList<NameValuePair>(); System.out.println("=============== 6"); params.add(new BasicNameValuePair("cmd", "get")); System.out.println("=============== 7"); params.add(new BasicNameValuePair("type", "org")); System.out.println("=============== 8"); params.add(new BasicNameValuePair("select", "org/orgID:/org/namespaceID:ext/WBX/PWSRule")); System.out.println("=============== 9"); params.add(new BasicNameValuePair("id", "current")); System.out.println("=============== 10"); System.out.println("=============== getDomainCredToken() :" + getDomainCredToken()); params.add(new BasicNameValuePair("cred", getDomainCredToken())); System.out.println("=============== 11"); System.out.println("=============== params" + params.toString()); System.out.println("===============Before wapiURL :" + this.wapiURL); final HttpPost httpPost = new HttpPost(this.wapiURL); System.out.println("=============== after wapiURL :" + this.wapiURL); httpPost.setEntity(new UrlEncodedFormEntity(params, org.apache.http.Consts.UTF_8)); System.out.println("=============== 12"); final CloseableHttpResponse httpRes = HTTPSCLIENT.execute(httpPost, new BasicHttpContext()); System.out.println("=============== 13"); if (httpRes == null) { System.out.println("=============== httpRes is NULL"); } try { dom = db.parse(httpRes.getEntity().getContent()); System.out.println("=============== 14"); } finally { httpRes.close(); } } catch (final Exception e) { throw new WBXCONexception(e); } final NodeList result = dom.getElementsByTagName("result"); if (result == null || result.item(0) == null || !result.item(0).getTextContent().equalsIgnoreCase("success")) throw new WBXCONexception( "ERROR::WBXCONorg:constructor(\"" + domain_name + "\")::" + documentGetErrorString(dom)); this.orgID = dom.getElementsByTagName("orgID").item(0).getTextContent(); this.namespaceID = dom.getElementsByTagName("namespaceID").item(0).getTextContent(); this.passwordrule = new PWSRule(Integer.parseInt(documentGetTextContentByTagName(dom, "PWMinimumLength_9")), Integer.parseInt(documentGetTextContentByTagName(dom, "PWMinimumAlpha_9")), Integer.parseInt(documentGetTextContentByTagName(dom, "PWMinimumNumeric_9")), Integer.parseInt(documentGetTextContentByTagName(dom, "PWMinimumSpecial_9")), documentGetTextContentByTagName(dom, "PWRequireMixedCase_B").equalsIgnoreCase("true")); this.wapiUser = restapiAccountGet(this.wapiUSER); }
From source file:org.sonatype.nexus.apachehttpclient.Hc4ProviderImpl.java
protected ManagedClientConnectionManager createClientConnectionManager(final List<SSLContextSelector> selectors) throws IllegalStateException { final Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", new NexusSSLConnectionSocketFactory( (javax.net.ssl.SSLSocketFactory) javax.net.ssl.SSLSocketFactory.getDefault(), SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER, selectors)) .build();/*from www.j a va 2s . c o m*/ final ManagedClientConnectionManager connManager = new ManagedClientConnectionManager(registry); final int maxConnectionCount = getConnectionPoolMaxSize(); final int perRouteConnectionCount = Math.min(getConnectionPoolSize(), maxConnectionCount); connManager.setMaxTotal(maxConnectionCount); connManager.setDefaultMaxPerRoute(perRouteConnectionCount); return connManager; }
From source file:org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.java
private static PoolingHttpClientConnectionManager createConnManager() { String sslProtocolsStr = System.getProperty("https.protocols"); String cipherSuitesStr = System.getProperty("https.cipherSuites"); String[] sslProtocols = sslProtocolsStr != null ? sslProtocolsStr.split(" *, *") : null; String[] cipherSuites = cipherSuitesStr != null ? cipherSuitesStr.split(" *, *") : null; SSLConnectionSocketFactory sslConnectionSocketFactory; if (SSL_INSECURE) { try {/*from w ww. j av a 2 s .com*/ SSLContext sslContext = new SSLContextBuilder().useSSL() .loadTrustMaterial(null, new RelaxedTrustStrategy(IGNORE_SSL_VALIDITY_DATES)).build(); sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext, sslProtocols, cipherSuites, SSL_ALLOW_ALL ? SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER : SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); } catch (Exception ex) { throw new SSLInitializationException(ex.getMessage(), ex); } } else { sslConnectionSocketFactory = new SSLConnectionSocketFactory( HttpsURLConnection.getDefaultSSLSocketFactory(), sslProtocols, cipherSuites, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); } Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.INSTANCE) .register("https", sslConnectionSocketFactory).build(); PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(registry); if (PERSISTENT_POOL) { connManager.setDefaultMaxPerRoute(MAX_CONN_PER_ROUTE); connManager.setMaxTotal(MAX_CONN_TOTAL); } else { connManager.setMaxTotal(1); } return connManager; }
From source file:hello.MyPostHTTP.java
private Config getConfig(final String url, final ProcessContext context) { final String baseUrl = getBaseUrl(url); Config config = configMap.get(baseUrl); if (config != null) { return config; }/*from w w w . j a v a2s. c om*/ final PoolingHttpClientConnectionManager conMan; final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE) .asControllerService(SSLContextService.class); if (sslContextService == null) { conMan = new PoolingHttpClientConnectionManager(); } else { final SSLContext sslContext; try { sslContext = createSSLContext(sslContextService); } catch (final Exception e) { throw new ProcessException(e); } final SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); // Also use a plain socket factory for regular http connections (especially proxies) final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder .<ConnectionSocketFactory>create().register("https", sslsf) .register("http", PlainConnectionSocketFactory.getSocketFactory()).build(); conMan = new PoolingHttpClientConnectionManager(socketFactoryRegistry); } conMan.setDefaultMaxPerRoute(context.getMaxConcurrentTasks()); conMan.setMaxTotal(context.getMaxConcurrentTasks()); config = new Config(conMan); final Config existingConfig = configMap.putIfAbsent(baseUrl, config); return existingConfig == null ? config : existingConfig; }