View Javadoc

1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.http.conn.scheme;
29  
30  import java.io.IOException;
31  import java.net.InetSocketAddress;
32  import java.net.Socket;
33  import java.net.UnknownHostException;
34  
35  import org.apache.http.conn.ConnectTimeoutException;
36  import org.apache.http.params.HttpParams;
37  
38  /**
39   * A factory for creating, initializing and connecting sockets. The factory encapsulates the logic
40   * for establishing a socket connection.
41   *
42   * @since 4.1
43   *
44   * @deprecated (4.3) use {@link org.apache.http.conn.socket.ConnectionSocketFactory}
45   */
46  @Deprecated
47  public interface SchemeSocketFactory {
48  
49      /**
50       * Creates a new, unconnected socket. The socket should subsequently be passed to
51       * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}.
52       *
53       * @param params    Optional {@link HttpParams parameters}. In most cases these parameters
54       *                  will not be required and will have no effect, as usually socket
55       *                  initialization should take place in the
56       *                  {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}
57       *                  method. However, in rare cases one may want to pass additional parameters
58       *                  to this method in order to create a customized {@link Socket} instance,
59       *                  for instance bound to a SOCKS proxy server.
60       *
61       * @return  a new socket
62       *
63       * @throws IOException if an I/O error occurs while creating the socket
64       */
65      Socket createSocket(HttpParams params) throws IOException;
66  
67      /**
68       * Connects a socket to the target host with the given remote address.
69       * <p/>
70       * Please note that {@link org.apache.http.conn.HttpInetSocketAddress} class should
71       * be used in order to pass the target remote address along with the original
72       * {@link org.apache.http.HttpHost} value used to resolve the address. The use of
73       * {@link org.apache.http.conn.HttpInetSocketAddress} can also ensure that no reverse
74       * DNS lookup will be performed if the target remote address was specified
75       * as an IP address.
76       *
77       * @param sock      the socket to connect, as obtained from
78       *                  {@link #createSocket(HttpParams) createSocket}.
79       *                  <code>null</code> indicates that a new socket
80       *                  should be created and connected.
81       * @param remoteAddress the remote address to connect to.
82       * @param localAddress the local address to bind the socket to, or
83       *                  <code>null</code> for any
84       * @param params    additional {@link HttpParams parameters} for connecting
85       *
86       * @return  the connected socket. The returned object may be different
87       *          from the <code>sock</code> argument if this factory supports
88       *          a layered protocol.
89       *
90       * @throws IOException if an I/O error occurs
91       * @throws UnknownHostException if the IP address of the target host
92       *          can not be determined
93       * @throws ConnectTimeoutException if the socket cannot be connected
94       *          within the time limit defined in the <code>params</code>
95       *
96       * @see org.apache.http.conn.HttpInetSocketAddress
97       */
98      Socket connectSocket(
99          Socket sock,
100         InetSocketAddress remoteAddress,
101         InetSocketAddress localAddress,
102         HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException;
103 
104     /**
105      * Checks whether a socket provides a secure connection. The socket must be
106      * {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams) connected}
107      * by this factory. The factory will <i>not</i> perform I/O operations in this method.
108      * <p>
109      * As a rule of thumb, plain sockets are not secure and TLS/SSL sockets are secure. However,
110      * there may be application specific deviations. For example, a plain socket to a host in the
111      * same intranet ("trusted zone") could be considered secure. On the other hand, a TLS/SSL
112      * socket could be considered insecure based on the cipher suite chosen for the connection.
113      *
114      * @param sock      the connected socket to check
115      *
116      * @return  <code>true</code> if the connection of the socket
117      *          should be considered secure, or
118      *          <code>false</code> if it should not
119      *
120      * @throws IllegalArgumentException
121      *  if the argument is invalid, for example because it is
122      *  not a connected socket or was created by a different
123      *  socket factory.
124      *  Note that socket factories are <i>not</i> required to
125      *  check these conditions, they may simply return a default
126      *  value when called with an invalid socket argument.
127      */
128     boolean isSecure(Socket sock) throws IllegalArgumentException;
129 
130 }