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.InetAddress;
32  import java.net.InetSocketAddress;
33  import java.net.Socket;
34  import java.net.UnknownHostException;
35  
36  import org.apache.http.conn.ConnectTimeoutException;
37  import org.apache.http.params.BasicHttpParams;
38  import org.apache.http.params.HttpParams;
39  
40  /**
41   * @deprecated (4.1) do not use
42   */
43  @Deprecated
44  class SocketFactoryAdaptor implements SocketFactory {
45  
46      private final SchemeSocketFactory factory;
47  
48      SocketFactoryAdaptor(final SchemeSocketFactory factory) {
49          super();
50          this.factory = factory;
51      }
52  
53      public Socket createSocket() throws IOException {
54          final HttpParams params = new BasicHttpParams();
55          return this.factory.createSocket(params);
56      }
57  
58      public Socket connectSocket(
59              final Socket socket,
60              final String host, final int port,
61              final InetAddress localAddress, int localPort,
62              final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
63          InetSocketAddress local = null;
64          if (localAddress != null || localPort > 0) {
65              // we need to bind explicitly
66              if (localPort < 0) {
67                  localPort = 0; // indicates "any"
68              }
69              local = new InetSocketAddress(localAddress, localPort);
70          }
71          final InetAddress remoteAddress = InetAddress.getByName(host);
72          final InetSocketAddress remote = new InetSocketAddress(remoteAddress, port);
73          return this.factory.connectSocket(socket, remote, local, params);
74      }
75  
76      public boolean isSecure(final Socket socket) throws IllegalArgumentException {
77          return this.factory.isSecure(socket);
78      }
79  
80      public SchemeSocketFactory getFactory() {
81          return this.factory;
82      }
83  
84      @Override
85      public boolean equals(final Object obj) {
86          if (obj == null) {
87              return false;
88          }
89          if (this == obj) {
90              return true;
91          }
92          if (obj instanceof SocketFactoryAdaptor) {
93              return this.factory.equals(((SocketFactoryAdaptor)obj).factory);
94          } else {
95              return this.factory.equals(obj);
96          }
97      }
98  
99      @Override
100     public int hashCode() {
101         return this.factory.hashCode();
102     }
103 
104 }