List of usage examples for org.apache.http.conn.ssl SSLSocketFactory setHostnameVerifier
public void setHostnameVerifier(final X509HostnameVerifier hostnameVerifier)
From source file:com.cloudhopper.httpclient.util.HttpPostMain.java
static public void main(String[] args) throws Exception { ///*from w ww. ja v a 2 s. c o m*/ // target urls // String strURL = "http://209.226.31.233:9009/SendSmsService/b98183b99a1f473839ce569c78b84dbd"; // Username: Twitter // Password: Twitter123 TrustManager easyTrustManager = new X509TrustManager() { public void checkClientTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException { // allow all } public void checkServerTrusted(java.security.cert.X509Certificate[] arg0, String arg1) throws CertificateException { // allow all } public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } }; Scheme http = new Scheme("http", PlainSocketFactory.getSocketFactory(), 80); SSLContext sslcontext = SSLContext.getInstance("TLS"); sslcontext.init(null, new TrustManager[] { easyTrustManager }, null); SSLSocketFactory sf = new SSLSocketFactory(sslcontext); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); Scheme https = new Scheme("https", sf, 443); //SchemeRegistry sr = new SchemeRegistry(); //sr.register(http); //sr.register(https); // create and initialize scheme registry //SchemeRegistry schemeRegistry = new SchemeRegistry(); //schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); // create an HttpClient with the ThreadSafeClientConnManager. // This connection manager must be used if more than one thread will // be using the HttpClient. //ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(schemeRegistry); //cm.setMaxTotalConnections(1); DefaultHttpClient client = new DefaultHttpClient(); client.getConnectionManager().getSchemeRegistry().register(https); // for (int i = 0; i < 1; i++) { // // create a new ticket id // //String ticketId = TicketUtil.generate(1, System.currentTimeMillis()); /** StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") .append("<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">\n") .append(" <S:Header>\n") .append(" <ns3:TransactionID xmlns:ns4=\"http://vmp.vzw.com/schema\"\n") .append("xmlns:ns3=\"http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4\">" + ticketId + "</ns3:TransactionID>\n") .append(" </S:Header>\n") .append(" <S:Body>\n") .append(" <ns2:OptinReq xmlns:ns4=\"http://schemas.xmlsoap.org/soap/envelope/\"\n") .append("xmlns:ns3=\"http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-6-MM7-1-4\"\n") .append("xmlns:ns2=\"http://vmp.vzw.com/schema\">\n") .append(" <ns2:VASPID>twitter</ns2:VASPID>\n") .append(" <ns2:VASID>tm33t!</ns2:VASID>\n") .append(" <ns2:ShortCode>800080008001</ns2:ShortCode>\n") .append(" <ns2:Number>9257089093</ns2:Number>\n") .append(" <ns2:Source>provider</ns2:Source>\n") .append(" <ns2:Message/>\n") .append(" </ns2:OptinReq>\n") .append(" </S:Body>\n") .append("</S:Envelope>"); */ // simple send sms StringBuilder string1 = new StringBuilder(200).append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") .append("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:loc=\"http://www.csapi.org/schema/parlayx/sms/send/v2_3/local\">\n") .append(" <soapenv:Header/>\n").append(" <soapenv:Body>\n").append(" <loc:sendSms>\n") .append(" <loc:addresses>tel:+16472260233</loc:addresses>\n") .append(" <loc:senderName>6388</loc:senderName>\n") .append(" <loc:message>Test Message &</loc:message>\n").append(" </loc:sendSms>\n") .append(" </soapenv:Body>\n").append("</soapenv:Envelope>\n"); // startSmsNotification - place to deliver SMS to String req = string1.toString(); logger.debug("Request XML -> \n" + req); HttpPost post = new HttpPost(strURL); StringEntity postEntity = new StringEntity(req, "ISO-8859-1"); postEntity.setContentType("text/xml; charset=\"ISO-8859-1\""); post.addHeader("SOAPAction", "\"\""); post.setEntity(postEntity); long start = System.currentTimeMillis(); client.getCredentialsProvider().setCredentials(new AuthScope("209.226.31.233", AuthScope.ANY_PORT), new UsernamePasswordCredentials("Twitter", "Twitter123")); BasicHttpContext localcontext = new BasicHttpContext(); // Generate BASIC scheme object and stick it to the local // execution context BasicScheme basicAuth = new BasicScheme(); localcontext.setAttribute("preemptive-auth", basicAuth); // Add as the first request interceptor client.addRequestInterceptor(new PreemptiveAuth(), 0); HttpResponse httpResponse = client.execute(post, localcontext); HttpEntity responseEntity = httpResponse.getEntity(); // // was the request OK? // if (httpResponse.getStatusLine().getStatusCode() != 200) { logger.error("Request failed with StatusCode=" + httpResponse.getStatusLine().getStatusCode()); } // get an input stream String responseBody = EntityUtils.toString(responseEntity); long stop = System.currentTimeMillis(); logger.debug("----------------------------------------"); logger.debug("Response took " + (stop - start) + " ms"); logger.debug(responseBody); logger.debug("----------------------------------------"); // } // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources client.getConnectionManager().shutdown(); }
From source file:com.jonbanjo.ssl.JfSSLScheme.java
private static Scheme getDefaultScheme() { SSLSocketFactory sf = SSLSocketFactory.getSocketFactory(); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return new Scheme("https", sf, 443); }
From source file:com.prey.net.HttpUtils.java
public static HttpClient getNewHttpClient() { try {/*from w ww . jav a 2s. c o m*/ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = SSLSocketFactory.getSocketFactory(); sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:com.dealoka.lib.net.HttpUtils.java
public static HttpClient getNewHttpClient() { try {//from w ww .ja v a2 s . c o m KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new EasySSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:de.micromata.genome.gwiki.fssvn.SslUtils.java
public static SSLSocketFactory createEasySSLSocketFactory() { try {/*ww w . j av a 2 s . c o m*/ SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); return ssf; } catch (RuntimeException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.amazon.s3.http.ConnectionManagerFactory.java
public static ThreadSafeClientConnManager createThreadSafeClientConnManager(ClientConfiguration config, HttpParams httpClientParams) {/*w w w .j a va 2 s. co m*/ ConnManagerParams.setMaxConnectionsPerRoute(httpClientParams, new ConnPerRouteBean(20)); SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sslSocketFactory, 443)); return new ThreadSafeClientConnManager(httpClientParams, registry); }
From source file:org.apache.stratos.cli.WebClientWrapper.java
public static HttpClient wrapClient(HttpClient base) { try {/*from ww w .j ava2s . c o m*/ SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException { } public X509Certificate[] getAcceptedIssuers() { return null; } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx); ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = base.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", ssf, 443)); return new DefaultHttpClient(ccm, base.getParams()); } catch (Exception ex) { return null; } }
From source file:org.ale.scanner.zotero.web.HttpsClient.java
public static ThreadSafeClientConnManager setupSSLConnMan(HttpParams params) { SchemeRegistry registry = new SchemeRegistry(); PlainSocketFactory pf = PlainSocketFactory.getSocketFactory(); SSLSocketFactory sf = SSLSocketFactory.getSocketFactory(); sf.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); registry.register(new Scheme("http", pf, 80)); registry.register(new Scheme("https", (SocketFactory) sf, 443)); return new ThreadSafeClientConnManager(params, registry); }
From source file:ru.elifantiev.yandex.SSLHttpClientFactory.java
public static HttpClient getNewHttpClient() { try {//from w w w. j a va2 s.c o m KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new YandexSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { return new DefaultHttpClient(); } }
From source file:org.switchyard.quickstarts.rules.multi.RulesMultiThreadBindingUtils.java
/** * Gets the client./*w w w.j a va 2 s . c om*/ * * @return the client */ public static DefaultHttpClient getClient() { DefaultHttpClient ret = null; // sets up parameters HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, "utf-8"); params.setBooleanParameter("http.protocol.expect-continue", false); // registers schemes for both http and https SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory(); sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); registry.register(new Scheme("https", sslSocketFactory, 443)); ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry); ret = new DefaultHttpClient(manager, params); return ret; }