private SSLContext getSSLContext() throws IOException { if ( this.sslcontext == null ) { this.sslcontext = createEasySSLContext(); } return this.sslcontext; }
/** * @see org.apache.http.conn.scheme.SocketFactory#createSocket() */ public Socket createSocket() throws IOException { if ( log.isDebugEnabled() ) { log.debug( "create socket" ); } return getSSLContext().getSocketFactory().createSocket(); }
public void initialize() throws InitializationException { SchemeRegistry schemeRegistry = new SchemeRegistry(); // http scheme schemeRegistry.register( new Scheme( "http", PlainSocketFactory.getSocketFactory(), 80 ) ); // https scheme schemeRegistry.register( new Scheme( "https", new EasySSLSocketFactory(), 443 ) ); params = new BasicHttpParams(); // TODO put this values to a configuration way ??? params.setParameter( ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30 ); params.setParameter( ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean( 30 ) ); HttpProtocolParams.setVersion( params, HttpVersion.HTTP_1_1 ); cm = new ThreadSafeClientConnManager( params, schemeRegistry ); }
/** * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket, java.lang.String, int, java.net.InetAddress, int, org.apache.http.params.HttpParams) */ public Socket connectSocket( Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params ) throws IOException, UnknownHostException, ConnectTimeoutException { int connTimeout = HttpConnectionParams.getConnectionTimeout( params ); int soTimeout = HttpConnectionParams.getSoTimeout( params ); InetSocketAddress remoteAddress = new InetSocketAddress( host, port ); SSLSocket sslsock = (SSLSocket) ( ( sock != null ) ? sock : createSocket() ); if ( ( localAddress != null ) || ( localPort > 0 ) ) { // we need to bind explicitly if ( localPort < 0 ) { localPort = 0; // indicates "any" } InetSocketAddress isa = new InetSocketAddress( localAddress, localPort ); sslsock.bind( isa ); } sslsock.connect( remoteAddress, connTimeout ); sslsock.setSoTimeout( soTimeout ); return sslsock; }
/** * @see org.apache.http.conn.scheme.LayeredSocketFactory#createSocket(java.net.Socket, java.lang.String, int, boolean) */ public Socket createSocket( Socket socket, String host, int port, boolean autoClose ) throws IOException, UnknownHostException { if ( log.isDebugEnabled() ) { log.debug( "create socket host " + host + ", port " + port ); } return getSSLContext().getSocketFactory().createSocket(); }