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.hc.client5.http.socket;
29  
30  import java.io.IOException;
31  import java.net.InetSocketAddress;
32  import java.net.Proxy;
33  import java.net.Socket;
34  
35  import org.apache.hc.core5.annotation.Contract;
36  import org.apache.hc.core5.annotation.Internal;
37  import org.apache.hc.core5.annotation.ThreadingBehavior;
38  import org.apache.hc.core5.http.HttpHost;
39  import org.apache.hc.core5.http.protocol.HttpContext;
40  import org.apache.hc.core5.util.TimeValue;
41  import org.apache.hc.core5.util.Timeout;
42  
43  /**
44   * A factory for creating and connecting connection sockets.
45   *
46   * @deprecated Do not use.
47   */
48  @Contract(threading = ThreadingBehavior.STATELESS)
49  @Deprecated
50  public interface ConnectionSocketFactory {
51  
52      /**
53       * Creates new, unconnected socket. The socket should subsequently be passed to
54       * {@link #connectSocket(TimeValue, Socket, HttpHost, InetSocketAddress, InetSocketAddress,
55       *    HttpContext) connectSocket} method.
56       */
57      Socket createSocket(HttpContext context) throws IOException;
58  
59      /**
60       * Creates new, unconnected socket via a proxy (generally SOCKS is expected).
61       * The socket should subsequently be passed to {@link #connectSocket(TimeValue, Socket,
62       * HttpHost, InetSocketAddress, InetSocketAddress, HttpContext) connectSocket} method.
63       *
64       * @since 5.2
65       */
66      @Internal
67      default Socket createSocket(Proxy proxy, HttpContext context) throws IOException {
68          return createSocket(context);
69      }
70  
71      /**
72       * Connects the socket to the target host with the given resolved remote address.
73       *
74       * @param connectTimeout connect timeout.
75       * @param socket the socket to connect, as obtained from {@link #createSocket(HttpContext)}.
76       * {@code null} indicates that a new socket should be created and connected.
77       * @param host target host as specified by the caller (end user).
78       * @param remoteAddress the resolved remote address to connect to.
79       * @param localAddress the local address to bind the socket to, or {@code null} for any.
80       * @param context the actual HTTP context.
81       *
82       * @return  the connected socket. The returned object may be different
83       *          from the {@code sock} argument if this factory supports
84       *          a layered protocol.
85       *
86       * @throws IOException if an I/O error occurs
87       */
88      Socket connectSocket(
89          TimeValue connectTimeout,
90          Socket socket,
91          HttpHost host,
92          InetSocketAddress remoteAddress,
93          InetSocketAddress localAddress,
94          HttpContext context) throws IOException;
95  
96      /**
97       * Connects the socket to the target host with the given resolved remote address.
98       *
99       * @param socket the socket to connect, as obtained from {@link #createSocket(HttpContext)}.
100      * {@code null} indicates that a new socket should be created and connected.
101      * @param host target host as specified by the caller (end user).
102      * @param remoteAddress the resolved remote address to connect to.
103      * @param localAddress the local address to bind the socket to, or {@code null} for any.
104      * @param connectTimeout connect timeout.
105      * @param attachment connect request attachment.
106      * @param context the actual HTTP context.
107      *
108      * @return  the connected socket. The returned object may be different
109      *          from the {@code sock} argument if this factory supports
110      *          a layered protocol.
111      *
112      * @throws IOException if an I/O error occurs
113      *
114      * @since 5.2
115      */
116     default Socket connectSocket(
117             Socket socket,
118             HttpHost host,
119             InetSocketAddress remoteAddress,
120             InetSocketAddress localAddress,
121             Timeout connectTimeout,
122             Object attachment,
123             HttpContext context) throws IOException {
124         return connectSocket(connectTimeout, socket, host, remoteAddress, localAddress, context);
125     }
126 
127 }