org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory Java Examples

The following examples show how to use org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpClientTransmitterImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testSuccessfulVerifyTargetOverHttps() throws Exception
{
    
    //Stub HttpClient so that executeMethod returns a 200 response
    when(mockedHttpClient.executeMethod(any(HostConfiguration.class), any(HttpMethod.class), 
            any(HttpState.class))).thenReturn(200);

    target.setEndpointProtocol(HTTPS_PROTOCOL);
    target.setEndpointPort(HTTPS_PORT);
    
    //Call verifyTarget
    transmitter.verifyTarget(target);
    
    ArgumentCaptor<HostConfiguration> hostConfig = ArgumentCaptor.forClass(HostConfiguration.class);
    ArgumentCaptor<HttpMethod> httpMethod = ArgumentCaptor.forClass(HttpMethod.class);
    ArgumentCaptor<HttpState> httpState = ArgumentCaptor.forClass(HttpState.class);
    
    verify(mockedHttpClient).executeMethod(hostConfig.capture(), httpMethod.capture(), httpState.capture());
    
    assertEquals("port", HTTPS_PORT, hostConfig.getValue().getPort());
    assertTrue("socket factory", 
            hostConfig.getValue().getProtocol().getSocketFactory() instanceof SecureProtocolSocketFactory);
    assertEquals("protocol", HTTPS_PROTOCOL.toLowerCase(), 
            hostConfig.getValue().getProtocol().getScheme().toLowerCase());
}
 
Example #2
Source File: CommonsHttpTransport.java    From elasticsearch-hadoop with Apache License 2.0 6 votes vote down vote up
private HostConfiguration setupSSLIfNeeded(Settings settings, SecureSettings secureSettings, HostConfiguration hostConfig) {
    if (!sslEnabled) {
        return hostConfig;
    }

    // we actually have a socks proxy, let's start the setup
    if (log.isDebugEnabled()) {
        log.debug("SSL Connection enabled");
    }

    isSecure = true;

    //
    // switch protocol
    // due to how HttpCommons work internally this dance is best to be kept as is
    //
    String schema = "https";
    int port = 443;
    SecureProtocolSocketFactory sslFactory = new SSLSocketFactory(settings, secureSettings);

    replaceProtocol(sslFactory, schema, port);

    return hostConfig;
}
 
Example #3
Source File: HttpConnection.java    From http4e with Apache License 2.0 4 votes vote down vote up
/**
 * Instructs the proxy to establish a secure tunnel to the host. The socket will 
 * be switched to the secure socket. Subsequent communication is done via the secure 
 * socket. The method can only be called once on a proxied secure connection.
 *
 * @throws IllegalStateException if connection is not secure and proxied or
 * if the socket is already secure.
 * @throws IOException if an attempt to establish the secure tunnel results in an
 *   I/O error.
 */
public void tunnelCreated() throws IllegalStateException, IOException {
    LOG.trace("enter HttpConnection.tunnelCreated()");

    if (!isSecure() || !isProxied()) {
        throw new IllegalStateException(
            "Connection must be secure "
                + "and proxied to use this feature");
    }

    if (usingSecureSocket) {
        throw new IllegalStateException("Already using a secure socket");
    }
    
    if (LOG.isDebugEnabled()) {
        LOG.debug("Secure tunnel to " + this.hostName + ":" + this.portNumber);
    }

    SecureProtocolSocketFactory socketFactory =
        (SecureProtocolSocketFactory) protocolInUse.getSocketFactory();

    socket = socketFactory.createSocket(socket, hostName, portNumber, true);
    int sndBufSize = this.params.getSendBufferSize();
    if (sndBufSize >= 0) {
        socket.setSendBufferSize(sndBufSize);
    }        
    int rcvBufSize = this.params.getReceiveBufferSize();
    if (rcvBufSize >= 0) {
        socket.setReceiveBufferSize(rcvBufSize);
    }        
    int outbuffersize = socket.getSendBufferSize();
    if (outbuffersize > 2048) {
        outbuffersize = 2048;
    }
    int inbuffersize = socket.getReceiveBufferSize();
    if (inbuffersize > 2048) {
        inbuffersize = 2048;
    }
    inputStream = new BufferedInputStream(socket.getInputStream(), inbuffersize);
    outputStream = new BufferedOutputStream(socket.getOutputStream(), outbuffersize);
    usingSecureSocket = true;
    tunnelEstablished = true;
}
 
Example #4
Source File: HttpConnection.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Instructs the proxy to establish a secure tunnel to the host. The socket will 
 * be switched to the secure socket. Subsequent communication is done via the secure 
 * socket. The method can only be called once on a proxied secure connection.
 *
 * @throws IllegalStateException if connection is not secure and proxied or
 * if the socket is already secure.
 * @throws IOException if an attempt to establish the secure tunnel results in an
 *   I/O error.
 */
public void tunnelCreated() throws IllegalStateException, IOException {
    LOG.trace("enter HttpConnection.tunnelCreated()");

    if (!isSecure() || !isProxied()) {
        throw new IllegalStateException(
            "Connection must be secure "
                + "and proxied to use this feature");
    }

    if (usingSecureSocket) {
        throw new IllegalStateException("Already using a secure socket");
    }
    
    if (LOG.isDebugEnabled()) {
        LOG.debug("Secure tunnel to " + this.hostName + ":" + this.portNumber);
    }

    SecureProtocolSocketFactory socketFactory =
        (SecureProtocolSocketFactory) protocolInUse.getSocketFactory();

    socket = socketFactory.createSocket(socket, hostName, portNumber, true);
    int sndBufSize = this.params.getSendBufferSize();
    if (sndBufSize >= 0) {
        socket.setSendBufferSize(sndBufSize);
    }        
    int rcvBufSize = this.params.getReceiveBufferSize();
    if (rcvBufSize >= 0) {
        socket.setReceiveBufferSize(rcvBufSize);
    }        
    int outbuffersize = socket.getSendBufferSize();
    if (outbuffersize > 2048) {
        outbuffersize = 2048;
    }
    int inbuffersize = socket.getReceiveBufferSize();
    if (inbuffersize > 2048) {
        inbuffersize = 2048;
    }
    inputStream = new BufferedInputStream(socket.getInputStream(), inbuffersize);
    outputStream = new BufferedOutputStream(socket.getOutputStream(), outbuffersize);
    usingSecureSocket = true;
    tunnelEstablished = true;
}
 
Example #5
Source File: HttpClientBuilder.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Gets the protocol socket factory used for the https scheme.
 * 
 * @return protocol socket factory used for the https scheme
 */
public SecureProtocolSocketFactory getHttpsProtocolSocketFactory() {
    return httpsProtocolSocketFactory;
}
 
Example #6
Source File: HttpClientBuilder.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Sets the protocol socket factory used for the https scheme.
 * 
 * @param factory the httpsProtocolSocketFactory to set
 */
public void setHttpsProtocolSocketFactory(SecureProtocolSocketFactory factory) {
    httpsProtocolSocketFactory = factory;
}