001/* 002 * ==================================================================== 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 * ==================================================================== 020 * 021 * This software consists of voluntary contributions made by many 022 * individuals on behalf of the Apache Software Foundation. For more 023 * information on the Apache Software Foundation, please see 024 * <http://www.apache.org/>. 025 * 026 */ 027 028package org.apache.http.conn.scheme; 029 030import java.io.IOException; 031import java.net.InetAddress; 032import java.net.InetSocketAddress; 033import java.net.Socket; 034import java.net.UnknownHostException; 035 036import org.apache.http.conn.ConnectTimeoutException; 037import org.apache.http.params.HttpParams; 038 039/** 040 * @deprecated (4.1) do not use 041 */ 042@Deprecated 043class SchemeSocketFactoryAdaptor implements SchemeSocketFactory { 044 045 private final SocketFactory factory; 046 047 SchemeSocketFactoryAdaptor(final SocketFactory factory) { 048 super(); 049 this.factory = factory; 050 } 051 052 @Override 053 public Socket connectSocket( 054 final Socket sock, 055 final InetSocketAddress remoteAddress, 056 final InetSocketAddress localAddress, 057 final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { 058 final String host = remoteAddress.getHostName(); 059 final int port = remoteAddress.getPort(); 060 InetAddress local = null; 061 int localPort = 0; 062 if (localAddress != null) { 063 local = localAddress.getAddress(); 064 localPort = localAddress.getPort(); 065 } 066 return this.factory.connectSocket(sock, host, port, local, localPort, params); 067 } 068 069 @Override 070 public Socket createSocket(final HttpParams params) throws IOException { 071 return this.factory.createSocket(); 072 } 073 074 @Override 075 public boolean isSecure(final Socket sock) throws IllegalArgumentException { 076 return this.factory.isSecure(sock); 077 } 078 079 public SocketFactory getFactory() { 080 return this.factory; 081 } 082 083 @Override 084 public boolean equals(final Object obj) { 085 if (obj == null) { 086 return false; 087 } 088 if (this == obj) { 089 return true; 090 } 091 if (obj instanceof SchemeSocketFactoryAdaptor) { 092 return this.factory.equals(((SchemeSocketFactoryAdaptor)obj).factory); 093 } else { 094 return this.factory.equals(obj); 095 } 096 } 097 098 @Override 099 public int hashCode() { 100 return this.factory.hashCode(); 101 } 102 103}