summaryrefslogtreecommitdiffstats
path: root/src/org/apache/http/conn/scheme
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-03 18:28:18 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-03 18:28:18 -0800
commite5d9544310b857f3ee9ec172bdbff8077323f9a1 (patch)
tree4b825dc642cb6eb9a060e54bf8d69288fbee4904 /src/org/apache/http/conn/scheme
parent8b7d40049e7f35f9770fc024363a9fa6e88dff15 (diff)
downloadexternal_apache-http-e5d9544310b857f3ee9ec172bdbff8077323f9a1.zip
external_apache-http-e5d9544310b857f3ee9ec172bdbff8077323f9a1.tar.gz
external_apache-http-e5d9544310b857f3ee9ec172bdbff8077323f9a1.tar.bz2
auto import from //depot/cupcake/@135843
Diffstat (limited to 'src/org/apache/http/conn/scheme')
-rw-r--r--src/org/apache/http/conn/scheme/HostNameResolver.java41
-rw-r--r--src/org/apache/http/conn/scheme/LayeredSocketFactory.java72
-rw-r--r--src/org/apache/http/conn/scheme/PlainSocketFactory.java182
-rw-r--r--src/org/apache/http/conn/scheme/Scheme.java223
-rw-r--r--src/org/apache/http/conn/scheme/SchemeRegistry.java187
-rw-r--r--src/org/apache/http/conn/scheme/SocketFactory.java138
6 files changed, 0 insertions, 843 deletions
diff --git a/src/org/apache/http/conn/scheme/HostNameResolver.java b/src/org/apache/http/conn/scheme/HostNameResolver.java
deleted file mode 100644
index ca6615c..0000000
--- a/src/org/apache/http/conn/scheme/HostNameResolver.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * $HeadURL:$
- * $Revision:$
- * $Date:$
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.http.conn.scheme;
-
-import java.io.IOException;
-import java.net.InetAddress;
-
-public interface HostNameResolver {
-
- InetAddress resolve (String hostname) throws IOException;
-
-}
diff --git a/src/org/apache/http/conn/scheme/LayeredSocketFactory.java b/src/org/apache/http/conn/scheme/LayeredSocketFactory.java
deleted file mode 100644
index 8dc6c6c..0000000
--- a/src/org/apache/http/conn/scheme/LayeredSocketFactory.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/LayeredSocketFactory.java $
- * $Revision: 645850 $
- * $Date: 2008-04-08 04:08:52 -0700 (Tue, 08 Apr 2008) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.http.conn.scheme;
-
-import java.io.IOException;
-import java.net.Socket;
-import java.net.UnknownHostException;
-
-/**
- * A {@link SocketFactory SocketFactory} for layered sockets (SSL/TLS).
- * See there for things to consider when implementing a socket factory.
- *
- * @author Michael Becke
- * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
- * @since 4.0
- */
-public interface LayeredSocketFactory extends SocketFactory {
-
- /**
- * Returns a socket connected to the given host that is layered over an
- * existing socket. Used primarily for creating secure sockets through
- * proxies.
- *
- * @param socket the existing socket
- * @param host the host name/IP
- * @param port the port on the host
- * @param autoClose a flag for closing the underling socket when the created
- * socket is closed
- *
- * @return Socket a new socket
- *
- * @throws IOException if an I/O error occurs while creating the socket
- * @throws UnknownHostException if the IP address of the host cannot be
- * determined
- */
- Socket createSocket(
- Socket socket,
- String host,
- int port,
- boolean autoClose
- ) throws IOException, UnknownHostException;
-
-}
diff --git a/src/org/apache/http/conn/scheme/PlainSocketFactory.java b/src/org/apache/http/conn/scheme/PlainSocketFactory.java
deleted file mode 100644
index acc13f7..0000000
--- a/src/org/apache/http/conn/scheme/PlainSocketFactory.java
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/PlainSocketFactory.java $
- * $Revision: 659194 $
- * $Date: 2008-05-22 11:33:47 -0700 (Thu, 22 May 2008) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.http.conn.scheme;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Socket;
-
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-
-/**
- * The default class for creating sockets.
- *
- * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
- * @author Michael Becke
- */
-public final class PlainSocketFactory implements SocketFactory {
-
- /**
- * The factory singleton.
- */
- private static final
- PlainSocketFactory DEFAULT_FACTORY = new PlainSocketFactory();
-
- private final HostNameResolver nameResolver;
-
- /**
- * Gets the singleton instance of this class.
- * @return the one and only plain socket factory
- */
- public static PlainSocketFactory getSocketFactory() {
- return DEFAULT_FACTORY;
- }
-
- public PlainSocketFactory(final HostNameResolver nameResolver) {
- super();
- this.nameResolver = nameResolver;
- }
-
-
- public PlainSocketFactory() {
- this(null);
- }
-
- // non-javadoc, see interface org.apache.http.conn.SocketFactory
- public Socket createSocket() {
- return new Socket();
- }
-
- // non-javadoc, see interface org.apache.http.conn.SocketFactory
- public Socket connectSocket(Socket sock, String host, int port,
- InetAddress localAddress, int localPort,
- HttpParams params)
- throws IOException {
-
- if (host == null) {
- throw new IllegalArgumentException("Target host may not be null.");
- }
- if (params == null) {
- throw new IllegalArgumentException("Parameters may not be null.");
- }
-
- if (sock == null)
- sock = createSocket();
-
- if ((localAddress != null) || (localPort > 0)) {
-
- // we need to bind explicitly
- if (localPort < 0)
- localPort = 0; // indicates "any"
-
- InetSocketAddress isa =
- new InetSocketAddress(localAddress, localPort);
- sock.bind(isa);
- }
-
- int timeout = HttpConnectionParams.getConnectionTimeout(params);
-
- InetSocketAddress remoteAddress;
- if (this.nameResolver != null) {
- remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port);
- } else {
- remoteAddress = new InetSocketAddress(host, port);
- }
-
- sock.connect(remoteAddress, timeout);
-
- return sock;
-
- } // connectSocket
-
-
- /**
- * Checks whether a socket connection is secure.
- * This factory creates plain socket connections
- * which are not considered secure.
- *
- * @param sock the connected socket
- *
- * @return <code>false</code>
- *
- * @throws IllegalArgumentException if the argument is invalid
- */
- public final boolean isSecure(Socket sock)
- throws IllegalArgumentException {
-
- if (sock == null) {
- throw new IllegalArgumentException("Socket may not be null.");
- }
- // This class check assumes that createSocket() calls the constructor
- // directly. If it was using javax.net.SocketFactory, we couldn't make
- // an assumption about the socket class here.
- if (sock.getClass() != Socket.class) {
- throw new IllegalArgumentException
- ("Socket not created by this factory.");
- }
- // This check is performed last since it calls a method implemented
- // by the argument object. getClass() is final in java.lang.Object.
- if (sock.isClosed()) {
- throw new IllegalArgumentException("Socket is closed.");
- }
-
- return false;
-
- } // isSecure
-
-
- /**
- * Compares this factory with an object.
- * There is only one instance of this class.
- *
- * @param obj the object to compare with
- *
- * @return iff the argument is this object
- */
- @Override
- public boolean equals(Object obj) {
- return (obj == this);
- }
-
- /**
- * Obtains a hash code for this object.
- * All instances of this class have the same hash code.
- * There is only one instance of this class.
- */
- @Override
- public int hashCode() {
- return PlainSocketFactory.class.hashCode();
- }
-
-}
diff --git a/src/org/apache/http/conn/scheme/Scheme.java b/src/org/apache/http/conn/scheme/Scheme.java
deleted file mode 100644
index 590d59d..0000000
--- a/src/org/apache/http/conn/scheme/Scheme.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/Scheme.java $
- * $Revision: 652950 $
- * $Date: 2008-05-02 16:49:48 -0700 (Fri, 02 May 2008) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.http.conn.scheme;
-
-import java.util.Locale;
-
-import org.apache.http.util.LangUtils;
-
-/**
- * Encapsulates specifics of a protocol scheme such as "http" or "https".
- * Schemes are identified by lowercase names.
- * Supported schemes are typically collected in a
- * {@link SchemeRegistry SchemeRegistry}.
- *
- * <p>
- * For example, to configure support for "https://" URLs,
- * you could write code like the following:
- * </p>
- * <pre>
- * Scheme https = new Scheme("https", new MySecureSocketFactory(), 443);
- * SchemeRegistry.DEFAULT.register(https);
- * </pre>
- *
- * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
- * @author Michael Becke
- * @author Jeff Dever
- * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
- */
-public final class Scheme {
-
- /** The name of this scheme, in lowercase. (e.g. http, https) */
- private final String name;
-
- /** The socket factory for this scheme */
- private final SocketFactory socketFactory;
-
- /** The default port for this scheme */
- private final int defaultPort;
-
- /** Indicates whether this scheme allows for layered connections */
- private final boolean layered;
-
-
- /** A string representation, for {@link #toString toString}. */
- private String stringRep;
-
-
- /**
- * Creates a new scheme.
- * Whether the created scheme allows for layered connections
- * depends on the class of <code>factory</code>.
- *
- * @param name the scheme name, for example "http".
- * The name will be converted to lowercase.
- * @param factory the factory for creating sockets for communication
- * with this scheme
- * @param port the default port for this scheme
- */
- public Scheme(final String name,
- final SocketFactory factory,
- final int port) {
-
- if (name == null) {
- throw new IllegalArgumentException
- ("Scheme name may not be null");
- }
- if (factory == null) {
- throw new IllegalArgumentException
- ("Socket factory may not be null");
- }
- if ((port <= 0) || (port > 0xffff)) {
- throw new IllegalArgumentException
- ("Port is invalid: " + port);
- }
-
- this.name = name.toLowerCase(Locale.ENGLISH);
- this.socketFactory = factory;
- this.defaultPort = port;
- this.layered = (factory instanceof LayeredSocketFactory);
- }
-
-
- /**
- * Obtains the default port.
- *
- * @return the default port for this scheme
- */
- public final int getDefaultPort() {
- return defaultPort;
- }
-
-
- /**
- * Obtains the socket factory.
- * If this scheme is {@link #isLayered layered}, the factory implements
- * {@link LayeredSocketFactory LayeredSocketFactory}.
- *
- * @return the socket factory for this scheme
- */
- public final SocketFactory getSocketFactory() {
- return socketFactory;
- }
-
-
- /**
- * Obtains the scheme name.
- *
- * @return the name of this scheme, in lowercase
- */
- public final String getName() {
- return name;
- }
-
-
- /**
- * Indicates whether this scheme allows for layered connections.
- *
- * @return <code>true</code> if layered connections are possible,
- * <code>false</code> otherwise
- */
- public final boolean isLayered() {
- return layered;
- }
-
-
- /**
- * Resolves the correct port for this scheme.
- * Returns the given port if it is valid, the default port otherwise.
- *
- * @param port the port to be resolved,
- * a negative number to obtain the default port
- *
- * @return the given port or the defaultPort
- */
- public final int resolvePort(int port) {
- return ((port <= 0) || (port > 0xffff)) ? defaultPort : port;
- }
-
-
- /**
- * Return a string representation of this object.
- *
- * @return a human-readable string description of this scheme
- */
- @Override
- public final String toString() {
- if (stringRep == null) {
- StringBuilder buffer = new StringBuilder();
- buffer.append(this.name);
- buffer.append(':');
- buffer.append(Integer.toString(this.defaultPort));
- stringRep = buffer.toString();
- }
- return stringRep;
- }
-
-
- /**
- * Compares this scheme to an object.
- *
- * @param obj the object to compare with
- *
- * @return <code>true</code> iff the argument is equal to this scheme
- */
- @Override
- public final boolean equals(Object obj) {
- if (obj == null) return false;
- if (this == obj) return true;
- if (!(obj instanceof Scheme)) return false;
-
- Scheme s = (Scheme) obj;
- return (name.equals(s.name) &&
- defaultPort == s.defaultPort &&
- layered == s.layered &&
- socketFactory.equals(s.socketFactory)
- );
- } // equals
-
-
- /**
- * Obtains a hash code for this scheme.
- *
- * @return the hash code
- */
- @Override
- public int hashCode() {
- int hash = LangUtils.HASH_SEED;
- hash = LangUtils.hashCode(hash, this.defaultPort);
- hash = LangUtils.hashCode(hash, this.name);
- hash = LangUtils.hashCode(hash, this.layered);
- hash = LangUtils.hashCode(hash, this.socketFactory);
- return hash;
- }
-
-} // class Scheme
diff --git a/src/org/apache/http/conn/scheme/SchemeRegistry.java b/src/org/apache/http/conn/scheme/SchemeRegistry.java
deleted file mode 100644
index 2ee8685..0000000
--- a/src/org/apache/http/conn/scheme/SchemeRegistry.java
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/SchemeRegistry.java $
- * $Revision: 648356 $
- * $Date: 2008-04-15 10:57:53 -0700 (Tue, 15 Apr 2008) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-package org.apache.http.conn.scheme;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.http.HttpHost;
-
-/**
- * A set of supported protocol {@link Scheme schemes}.
- * Schemes are identified by lowercase names.
- *
- * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
- *
- *
- * <!-- empty lines to avoid svn diff problems -->
- * @version $Revision: 648356 $ $Date: 2008-04-15 10:57:53 -0700 (Tue, 15 Apr 2008) $
- *
- * @since 4.0
- */
-public final class SchemeRegistry {
-
- /** The available schemes in this registry. */
- private final Map<String,Scheme> registeredSchemes;
-
-
- /**
- * Creates a new, empty scheme registry.
- */
- public SchemeRegistry() {
- super();
- registeredSchemes = new LinkedHashMap<String,Scheme>();
- }
-
-
- /**
- * Obtains a scheme by name.
- *
- * @param name the name of the scheme to look up (in lowercase)
- *
- * @return the scheme, never <code>null</code>
- *
- * @throws IllegalStateException
- * if the scheme with the given name is not registered
- */
- public synchronized final Scheme getScheme(String name) {
- Scheme found = get(name);
- if (found == null) {
- throw new IllegalStateException
- ("Scheme '"+name+"' not registered.");
- }
- return found;
- }
-
-
- /**
- * Obtains the scheme for a host.
- * Convenience method for <code>getScheme(host.getSchemeName())</pre>
- *
- * @param host the host for which to obtain the scheme
- *
- * @return the scheme for the given host, never <code>null</code>
- *
- * @throws IllegalStateException
- * if a scheme with the respective name is not registered
- */
- public synchronized final Scheme getScheme(HttpHost host) {
- if (host == null) {
- throw new IllegalArgumentException("Host must not be null.");
- }
- return getScheme(host.getSchemeName());
- }
-
-
- /**
- * Obtains a scheme by name, if registered.
- *
- * @param name the name of the scheme to look up (in lowercase)
- *
- * @return the scheme, or
- * <code>null</code> if there is none by this name
- */
- public synchronized final Scheme get(String name) {
- if (name == null)
- throw new IllegalArgumentException("Name must not be null.");
-
- // leave it to the caller to use the correct name - all lowercase
- //name = name.toLowerCase();
- Scheme found = registeredSchemes.get(name);
- return found;
- }
-
-
- /**
- * Registers a scheme.
- * The scheme can later be retrieved by its name
- * using {@link #getScheme(String) getScheme} or {@link #get get}.
- *
- * @param sch the scheme to register
- *
- * @return the scheme previously registered with that name, or
- * <code>null</code> if none was registered
- */
- public synchronized final Scheme register(Scheme sch) {
- if (sch == null)
- throw new IllegalArgumentException("Scheme must not be null.");
-
- Scheme old = registeredSchemes.put(sch.getName(), sch);
- return old;
- }
-
-
- /**
- * Unregisters a scheme.
- *
- * @param name the name of the scheme to unregister (in lowercase)
- *
- * @return the unregistered scheme, or
- * <code>null</code> if there was none
- */
- public synchronized final Scheme unregister(String name) {
- if (name == null)
- throw new IllegalArgumentException("Name must not be null.");
-
- // leave it to the caller to use the correct name - all lowercase
- //name = name.toLowerCase();
- Scheme gone = registeredSchemes.remove(name);
- return gone;
- }
-
-
- /**
- * Obtains the names of the registered schemes in their default order.
- *
- * @return List containing registered scheme names.
- */
- public synchronized final List<String> getSchemeNames() {
- return new ArrayList<String>(registeredSchemes.keySet());
- }
-
- /**
- * Populates the internal collection of registered {@link Scheme protocol schemes}
- * with the content of the map passed as a parameter.
- *
- * @param map protocol schemes
- */
- public synchronized void setItems(final Map<String, Scheme> map) {
- if (map == null) {
- return;
- }
- registeredSchemes.clear();
- registeredSchemes.putAll(map);
- }
-
-} // class SchemeRegistry
-
diff --git a/src/org/apache/http/conn/scheme/SocketFactory.java b/src/org/apache/http/conn/scheme/SocketFactory.java
deleted file mode 100644
index bb553b2..0000000
--- a/src/org/apache/http/conn/scheme/SocketFactory.java
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/scheme/SocketFactory.java $
- * $Revision: 645850 $
- * $Date: 2008-04-08 04:08:52 -0700 (Tue, 08 Apr 2008) $
- *
- * ====================================================================
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- * ====================================================================
- *
- * This software consists of voluntary contributions made by many
- * individuals on behalf of the Apache Software Foundation. For more
- * information on the Apache Software Foundation, please see
- * <http://www.apache.org/>.
- *
- */
-
-package org.apache.http.conn.scheme;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.net.UnknownHostException;
-
-import org.apache.http.conn.ConnectTimeoutException;
-import org.apache.http.params.HttpParams;
-
-/**
- * A factory for creating and connecting sockets.
- * The factory encapsulates the logic for establishing a socket connection.
- * <br/>
- * Both {@link java.lang.Object#equals(java.lang.Object) Object.equals()}
- * and {@link java.lang.Object#hashCode() Object.hashCode()}
- * must be overridden for the correct operation of some connection managers.
- *
- * @author <a href="mailto:rolandw at apache.org">Roland Weber</a>
- * @author Michael Becke
- * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
- */
-public interface SocketFactory {
-
- /**
- * Creates a new, unconnected socket.
- * The socket should subsequently be passed to
- * {@link #connectSocket connectSocket}.
- *
- * @return a new socket
- *
- * @throws IOException if an I/O error occurs while creating the socket
- */
- Socket createSocket()
- throws IOException
- ;
-
-
- /**
- * Connects a socket to the given host.
- *
- * @param sock the socket to connect, as obtained from
- * {@link #createSocket createSocket}.
- * <code>null</code> indicates that a new socket
- * should be created and connected.
- * @param host the host to connect to
- * @param port the port to connect to on the host
- * @param localAddress the local address to bind the socket to, or
- * <code>null</code> for any
- * @param localPort the port on the local machine,
- * 0 or a negative number for any
- * @param params additional {@link HttpParams parameters} for connecting
- *
- * @return the connected socket. The returned object may be different
- * from the <code>sock</code> argument if this factory supports
- * a layered protocol.
- *
- * @throws IOException if an I/O error occurs
- * @throws UnknownHostException if the IP address of the target host
- * can not be determined
- * @throws ConnectTimeoutException if the socket cannot be connected
- * within the time limit defined in the <code>params</code>
- */
- Socket connectSocket(
- Socket sock,
- String host,
- int port,
- InetAddress localAddress,
- int localPort,
- HttpParams params
- ) throws IOException, UnknownHostException, ConnectTimeoutException;
-
-
- /**
- * Checks whether a socket provides a secure connection.
- * The socket must be {@link #connectSocket connected}
- * by this factory.
- * The factory will <i>not</i> perform I/O operations
- * in this method.
- * <br/>
- * As a rule of thumb, plain sockets are not secure and
- * TLS/SSL sockets are secure. However, there may be
- * application specific deviations. For example, a plain
- * socket to a host in the same intranet ("trusted zone")
- * could be considered secure. On the other hand, a
- * TLS/SSL socket could be considered insecure based on
- * the cypher suite chosen for the connection.
- *
- * @param sock the connected socket to check
- *
- * @return <code>true</code> if the connection of the socket
- * should be considered secure, or
- * <code>false</code> if it should not
- *
- * @throws IllegalArgumentException
- * if the argument is invalid, for example because it is
- * not a connected socket or was created by a different
- * socket factory.
- * Note that socket factories are <i>not</i> required to
- * check these conditions, they may simply return a default
- * value when called with an invalid socket argument.
- */
- boolean isSecure(Socket sock)
- throws IllegalArgumentException
- ;
-
-}