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