Example usage for org.apache.commons.httpclient.params HttpConnectionParams getParameter

List of usage examples for org.apache.commons.httpclient.params HttpConnectionParams getParameter

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.params HttpConnectionParams getParameter.

Prototype

public Object getParameter(String paramString) 

Source Link

Usage

From source file:com.eviware.soapui.impl.wsdl.support.http.SoapUIEasySSLProtocolSocketFactory.java

@Override
public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException {
    String sslConfig = (String) params.getParameter(SoapUIHostConfiguration.SOAPUI_SSL_CONFIG);

    if (StringUtils.isNullOrEmpty(sslConfig)) {
        return enableSocket((SSLSocket) super.createSocket(host, port, localAddress, localPort, params));
    }//from   ww  w .  j av  a2  s .c  o m

    EasySSLProtocolSocketFactory factory = factoryMap.get(sslConfig);
    if (factory != null) {
        return enableSocket((SSLSocket) factory.createSocket(host, port, localAddress, localPort, params));
    }
    try {
        // try to create new factory for specified config
        factory = new EasySSLProtocolSocketFactory();

        int ix = sslConfig.lastIndexOf(' ');
        String keyStore = sslConfig.substring(0, ix);
        String pwd = sslConfig.substring(ix + 1);

        factory.setKeyMaterial(new KeyMaterial(keyStore, pwd.toCharArray()));
        factoryMap.put(sslConfig, factory);

        return enableSocket((SSLSocket) factory.createSocket(host, port, localAddress, localPort, params));
    } catch (Exception gse) {
        SoapUI.logError(gse);
        return enableSocket((SSLSocket) super.createSocket(host, port, localAddress, localPort, params));
    }
}

From source file:com.cyberway.issue.crawler.fetcher.HeritrixSSLProtocolSocketFactory.java

public synchronized Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException, UnknownHostException {
    // Below code is from the DefaultSSLProtocolSocketFactory#createSocket
    // method only it has workarounds to deal with pre-1.4 JVMs.  I've
    // cut these out.
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }/*from w  w  w. j av  a2s  .c  o m*/
    Socket socket = null;
    int timeout = params.getConnectionTimeout();
    if (timeout == 0) {
        socket = createSocket(host, port, localAddress, localPort);
    } else {
        SSLSocketFactory factory = (SSLSocketFactory) params.getParameter(FetchHTTP.SSL_FACTORY_KEY);
        SSLSocketFactory f = (factory != null) ? factory : this.sslDefaultFactory;
        socket = f.createSocket();
        ServerCache cache = (ServerCache) params.getParameter(FetchHTTP.SERVER_CACHE_KEY);
        InetAddress hostAddress = (cache != null) ? HeritrixProtocolSocketFactory.getHostAddress(cache, host)
                : null;
        InetSocketAddress address = (hostAddress != null) ? new InetSocketAddress(hostAddress, port)
                : new InetSocketAddress(host, port);
        socket.bind(new InetSocketAddress(localAddress, localPort));
        try {
            socket.connect(address, timeout);
        } catch (SocketTimeoutException e) {
            // Add timeout info. to the exception.
            throw new SocketTimeoutException(
                    e.getMessage() + ": timeout set at " + Integer.toString(timeout) + "ms.");
        }
        assert socket.isConnected() : "Socket not connected " + host;
    }
    return socket;
}

From source file:com.cyberway.issue.crawler.fetcher.HeritrixProtocolSocketFactory.java

/**
 * Attempts to get a new socket connection to the given host within the
 * given time limit./* ww  w.  j a v a  2s.  co m*/
 * <p>
 * This method employs several techniques to circumvent the limitations
 * of older JREs that do not support connect timeout. When running in
 * JRE 1.4 or above reflection is used to call
 * Socket#connect(SocketAddress endpoint, int timeout) method. When
 * executing in older JREs a controller thread is executed. The
 * controller thread attempts to create a new socket within the given
 * limit of time. If socket constructor does not return until the
 * timeout expires, the controller terminates and throws an
 * {@link ConnectTimeoutException}
 * </p>
 *
 * @param host the host name/IP
 * @param port the port on the host
 * @param localAddress the local host name/IP to bind the socket to
 * @param localPort the port on the local machine
 * @param params {@link HttpConnectionParams Http connection parameters}
 *
 * @return Socket a new socket
 *
 * @throws IOException if an I/O error occurs while creating the socket
 * @throws UnknownHostException if the IP address of the host cannot be
 * @throws IOException if an I/O error occurs while creating the socket
 * @throws UnknownHostException if the IP address of the host cannot be
 * determined
 * @throws ConnectTimeoutException if socket cannot be connected within the
 *  given time limit
 *
 * @since 3.0
 */
public Socket createSocket(final String host, final int port, final InetAddress localAddress,
        final int localPort, final HttpConnectionParams params)
        throws IOException, UnknownHostException, ConnectTimeoutException {
    // Below code is from the DefaultSSLProtocolSocketFactory#createSocket
    // method only it has workarounds to deal with pre-1.4 JVMs.  I've
    // cut these out.
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }
    Socket socket = null;
    int timeout = params.getConnectionTimeout();
    if (timeout == 0) {
        socket = createSocket(host, port, localAddress, localPort);
    } else {
        socket = new Socket();
        ServerCache cache = (ServerCache) params.getParameter(FetchHTTP.SERVER_CACHE_KEY);
        InetAddress hostAddress = (cache != null) ? getHostAddress(cache, host) : null;
        InetSocketAddress address = (hostAddress != null) ? new InetSocketAddress(hostAddress, port)
                : new InetSocketAddress(host, port);
        socket.bind(new InetSocketAddress(localAddress, localPort));
        try {
            socket.connect(address, timeout);
        } catch (SocketTimeoutException e) {
            // Add timeout info. to the exception.
            throw new SocketTimeoutException(
                    e.getMessage() + ": timeout set at " + Integer.toString(timeout) + "ms.");
        }
        assert socket.isConnected() : "Socket not connected " + host;
    }
    return socket;
}

From source file:org.archive.modules.fetcher.HeritrixSSLProtocolSocketFactory.java

public synchronized Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException, UnknownHostException {
    // Below code is from the DefaultSSLProtocolSocketFactory#createSocket
    // method only it has workarounds to deal with pre-1.4 JVMs.  I've
    // cut these out.
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null");
    }//from   w  w w . ja va  2 s .c om
    Socket socket = null;
    int timeout = params.getConnectionTimeout();
    if (timeout == 0) {
        socket = createSocket(host, port, localAddress, localPort);
    } else {
        SSLSocketFactory factory = (SSLSocketFactory) params.getParameter(FetchHTTP.SSL_FACTORY_KEY);
        SSLSocketFactory f = (factory != null) ? factory : this.sslDefaultFactory;
        socket = f.createSocket();

        Thread current = Thread.currentThread();
        InetAddress hostAddress;
        if (current instanceof HostResolver) {
            HostResolver resolver = (HostResolver) current;
            hostAddress = resolver.resolve(host);
        } else {
            hostAddress = null;
        }
        InetSocketAddress address = (hostAddress != null) ? new InetSocketAddress(hostAddress, port)
                : new InetSocketAddress(host, port);
        socket.bind(new InetSocketAddress(localAddress, localPort));
        try {
            socket.connect(address, timeout);
        } catch (SocketTimeoutException e) {
            // Add timeout info. to the exception.
            throw new SocketTimeoutException(
                    e.getMessage() + ": timeout set at " + Integer.toString(timeout) + "ms.");
        }
        assert socket.isConnected() : "Socket not connected " + host;
    }
    return socket;
}

From source file:org.globus.axis.transport.commons.CommonsSSLSocketFactory.java

public Socket createSocket(String host, int port, InetAddress localAddress, int localPort,
        HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    SSLContextHelper helper = null;// www . ja  v  a2  s.  c  o m
    Authorization authz = null;
    Boolean anonymous = null;
    GSSCredential cred = null;
    Integer protection = null;
    TrustedCertificates trustedCerts = null;

    if (params != null) {
        authz = (Authorization) params.getParameter(GSIHTTPTransport.GSI_AUTHORIZATION);

        anonymous = (Boolean) params.getParameter(GSIHTTPTransport.GSI_ANONYMOUS);

        cred = (GSSCredential) params.getParameter(GSIHTTPTransport.GSI_CREDENTIALS);

        protection = (Integer) params.getParameter(GSIConstants.GSI_TRANSPORT);

        trustedCerts = (TrustedCertificates) params.getParameter(GSIHTTPTransport.TRUSTED_CERTIFICATES);
    }

    try {
        helper = new SSLContextHelper(host, port, authz, anonymous, cred, protection, trustedCerts);
    } catch (GSSException e) {
        throw new ChainedIOException("Failed to initialize security context", e);
    }

    Socket socket = defaultSocketFactory.createSocket(host, port, localAddress, localPort);
    return helper.wrapSocket(socket);
}

From source file:ucar.nc2.util.net.EasySSLProtocolSocketFactory.java

private SSLContext createSSLContext(HttpConnectionParams params, String host, int port) throws HTTPException {
    SSLContext sslcontext = null;
    KeyManager[] keymanagers = null;
    KeyStore keystore = null;/*from w ww . j  a v  a  2 s  .c o  m*/
    KeyStore truststore = null;
    TrustManager[] trustmanagers = null;

    String keypassword = null;
    String keypath = null;
    String trustpassword = null;
    String trustpath = null;

    try {

        // Get the HTTPAuthProvider
        HTTPAuthProvider provider;
        provider = (HTTPAuthProvider) params.getParameter(CredentialsProvider.PROVIDER);
        if (provider == null)
            return stdauthenticate();

        // Abuse the getCredentials() api
        Credentials creds = null;
        try {
            creds = provider.getCredentials(HTTPSSLScheme.Default, null, 0, false);
            if (creds == null)
                return stdauthenticate();
        } catch (CredentialsNotAvailableException e) {
            return stdauthenticate();
        }

        HTTPSSLProvider sslprovider = (creds == null ? null : (HTTPSSLProvider) creds);
        if (sslprovider == null)
            return stdauthenticate();

        keypath = (String) sslprovider.getKeystore();
        keypassword = (String) sslprovider.getKeypassword();
        trustpath = (String) sslprovider.getTruststore();
        trustpassword = (String) sslprovider.getTrustpassword();

        keystore = buildstore(keypath, keypassword, "key");
        if (keystore != null) {
            KeyManagerFactory kmfactory = KeyManagerFactory.getInstance("SunX509");
            kmfactory.init(keystore, keypassword.toCharArray());
            keymanagers = kmfactory.getKeyManagers();
        }

        truststore = buildstore(trustpath, trustpassword, "trust");
        if (truststore != null) {
            //TrustManagerFactory trfactory = TrustManagerFactory.getInstance("SunX509");
            //trfactory.init(truststore, trustpassword.toCharArray());
            //trustmanagers = trfactory.getTrustManagers();
            trustmanagers = new TrustManager[] { new EasyX509TrustManager(truststore) };
        } else {
            trustmanagers = new TrustManager[] { new EasyX509TrustManager(null) };
        }

        sslcontext = SSLContext.getInstance("SSL");
        sslcontext.init(keymanagers, trustmanagers, null);

        return sslcontext;

    } catch (KeyManagementException e) {
        throw new HTTPException("Key Management exception: " + e.getMessage());
    } catch (NoSuchAlgorithmException e) {
        throw new HTTPException("Unsupported algorithm exception: " + e.getMessage());
    } catch (KeyStoreException e) {
        throw new HTTPException("Keystore exception: " + e.getMessage());
    } catch (GeneralSecurityException e) {
        throw new HTTPException("Key management exception: " + e.getMessage());
    } catch (IOException e) {
        throw new HTTPException("I/O error reading keystore/truststore file: " + e.getMessage());
    }
}