1 /*
2  * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/SocketFactory.java $
3  * $Revision: 645850 $
4  * $Date: 2008-04-08 04:08:52 -0700 (Tue, 08 Apr 2008) $
5  *
6  * ====================================================================
7  * Licensed to the Apache Software Foundation (ASF) under one
8  * or more contributor license agreements.  See the NOTICE file
9  * distributed with this work for additional information
10  * regarding copyright ownership.  The ASF licenses this file
11  * to you under the Apache License, Version 2.0 (the
12  * "License"); you may not use this file except in compliance
13  * with the License.  You may obtain a copy of the License at
14  *
15  *   http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing,
18  * software distributed under the License is distributed on an
19  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20  * KIND, either express or implied.  See the License for the
21  * specific language governing permissions and limitations
22  * under the License.
23  * ====================================================================
24  *
25  * This software consists of voluntary contributions made by many
26  * individuals on behalf of the Apache Software Foundation.  For more
27  * information on the Apache Software Foundation, please see
28  * <http://www.apache.org/>.
29  *
30  */
31 
32 package org.apache.http.conn.scheme;
33 
34 import java.io.IOException;
35 import java.net.InetAddress;
36 import java.net.Socket;
37 import java.net.UnknownHostException;
38 
39 import org.apache.http.conn.ConnectTimeoutException;
40 import org.apache.http.params.HttpParams;
41 
42 /**
43  * A factory for creating and connecting sockets.
44  * The factory encapsulates the logic for establishing a socket connection.
45  * <br/>
46  * Both {@link java.lang.Object#equals(java.lang.Object) Object.equals()}
47  * and {@link java.lang.Object#hashCode() Object.hashCode()}
48  * must be overridden for the correct operation of some connection managers.
49  *
50  * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
51  * @author Michael Becke
52  * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
53  *
54  * @deprecated Please use {@link java.net.URL#openConnection} instead.
55  *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
56  *     for further details.
57  */
58 @Deprecated
59 public interface SocketFactory {
60 
61     /**
62      * Creates a new, unconnected socket.
63      * The socket should subsequently be passed to
64      * {@link #connectSocket connectSocket}.
65      *
66      * @return  a new socket
67      *
68      * @throws IOException if an I/O error occurs while creating the socket
69      */
createSocket()70     Socket createSocket()
71         throws IOException
72         ;
73 
74 
75     /**
76      * Connects a socket to the given host.
77      *
78      * @param sock      the socket to connect, as obtained from
79      *                  {@link #createSocket createSocket}.
80      *                  <code>null</code> indicates that a new socket
81      *                  should be created and connected.
82      * @param host      the host to connect to
83      * @param port      the port to connect to on the host
84      * @param localAddress the local address to bind the socket to, or
85      *                  <code>null</code> for any
86      * @param localPort the port on the local machine,
87      *                  0 or a negative number for any
88      * @param params    additional {@link HttpParams parameters} for connecting
89      *
90      * @return  the connected socket. The returned object may be different
91      *          from the <code>sock</code> argument if this factory supports
92      *          a layered protocol.
93      *
94      * @throws IOException if an I/O error occurs
95      * @throws UnknownHostException if the IP address of the target host
96      *          can not be determined
97      * @throws ConnectTimeoutException if the socket cannot be connected
98      *          within the time limit defined in the <code>params</code>
99      */
connectSocket( Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params )100     Socket connectSocket(
101         Socket sock,
102         String host,
103         int port,
104         InetAddress localAddress,
105         int localPort,
106         HttpParams params
107     ) throws IOException, UnknownHostException, ConnectTimeoutException;
108 
109 
110     /**
111      * Checks whether a socket provides a secure connection.
112      * The socket must be {@link #connectSocket connected}
113      * by this factory.
114      * The factory will <i>not</i> perform I/O operations
115      * in this method.
116      * <br/>
117      * As a rule of thumb, plain sockets are not secure and
118      * TLS/SSL sockets are secure. However, there may be
119      * application specific deviations. For example, a plain
120      * socket to a host in the same intranet ("trusted zone")
121      * could be considered secure. On the other hand, a
122      * TLS/SSL socket could be considered insecure based on
123      * the cypher suite chosen for the connection.
124      *
125      * @param sock      the connected socket to check
126      *
127      * @return  <code>true</code> if the connection of the socket
128      *          should be considered secure, or
129      *          <code>false</code> if it should not
130      *
131      * @throws IllegalArgumentException
132      *  if the argument is invalid, for example because it is
133      *  not a connected socket or was created by a different
134      *  socket factory.
135      *  Note that socket factories are <i>not</i> required to
136      *  check these conditions, they may simply return a default
137      *  value when called with an invalid socket argument.
138      */
isSecure(Socket sock)139     boolean isSecure(Socket sock)
140         throws IllegalArgumentException
141         ;
142 
143 }
144