    001/*
    002 * $HeadURL: http://juliusdavies.ca/svn/not-yet-commons-ssl/tags/commons-ssl-0.3.15/src/java/org/apache/commons/ssl/HttpSecureProtocol.java $
    003 * $Revision: 165 $
    004 * $Date: 2014-04-24 16:48:09 -0700 (Thu, 24 Apr 2014) $
    005 *
    006 * ====================================================================
    007 * Licensed to the Apache Software Foundation (ASF) under one
    008 * or more contributor license agreements.  See the NOTICE file
    009 * distributed with this work for additional information
    010 * regarding copyright ownership.  The ASF licenses this file
    011 * to you under the Apache License, Version 2.0 (the
    012 * "License"); you may not use this file except in compliance
    013 * with the License.  You may obtain a copy of the License at
    014 *
    015 *   http://www.apache.org/licenses/LICENSE-2.0
    016 *
    017 * Unless required by applicable law or agreed to in writing,
    018 * software distributed under the License is distributed on an
    019 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    020 * KIND, either express or implied.  See the License for the
    021 * specific language governing permissions and limitations
    022 * under the License.
    023 * ====================================================================
    024 *
    025 * This software consists of voluntary contributions made by many
    026 * individuals on behalf of the Apache Software Foundation.  For more
    027 * information on the Apache Software Foundation, please see
    028 * <http://www.apache.org/>.
    029 *
    030 */
    031
    032package org.apache.commons.ssl;
    033
    034import org.apache.commons.httpclient.params.HttpConnectionParams;
    035import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
    036
    037import java.io.IOException;
    038import java.net.InetAddress;
    039import java.net.Socket;
    040import java.security.GeneralSecurityException;
    041
    042/**
    043 * Hook into HttpClient.
    044 *
    045 * @author Credit Union Central of British Columbia
    046 * @author <a href="http://www.cucbc.com/">www.cucbc.com</a>
    047 * @author <a href="mailto:juliusdavies@cucbc.com">juliusdavies@cucbc.com</a>
    048 * @since 5-May-2006
    049 */
    050public class HttpSecureProtocol extends SSLClient
    051    implements SecureProtocolSocketFactory {
    052
    053    public HttpSecureProtocol()
    054        throws GeneralSecurityException, IOException {
    055        super();
    056    }
    057
    058    /**
    059     * Attempts to get a new socket connection to the given host within the
    060     * given time limit.
    061     * <p/>
    062     * To circumvent the limitations of older JREs that do not support connect
    063     * timeout a controller thread is executed. The controller thread attempts
    064     * to create a new socket within the given limit of time. If socket
    065     * constructor does not return until the timeout expires, the controller
    066     * terminates and throws an
    067     * {@link org.apache.commons.httpclient.ConnectTimeoutException}
    068     * </p>
    069     *
    070     * @param host         the host name/IP
    071     * @param port         the port on the host
    072     * @param localAddress the local host name/IP to bind the socket to
    073     * @param localPort    the port on the local machine
    074     * @param params       {@link org.apache.commons.httpclient.params.HttpConnectionParams Http connection parameters}
    075     * @return Socket a new socket
    076     * @throws java.io.IOException           if an I/O error occurs while creating the socket
    077     * @throws java.net.UnknownHostException if the IP address of the host cannot be
    078     *                                       determined
    079     */
    080    public Socket createSocket(final String host,
    081                               final int port,
    082                               final InetAddress localAddress,
    083                               final int localPort,
    084                               final HttpConnectionParams params)
    085        throws IOException {
    086        if (params == null) {
    087            throw new IllegalArgumentException("Parameters may not be null");
    088        }
    089        int timeout = params.getConnectionTimeout();
    090        return super.createSocket(host, port, localAddress, localPort, timeout);
    091    }
    092
    093}