diff options
Diffstat (limited to 'src/org/apache/http/conn')
49 files changed, 0 insertions, 6641 deletions
diff --git a/src/org/apache/http/conn/BasicEofSensorWatcher.java b/src/org/apache/http/conn/BasicEofSensorWatcher.java deleted file mode 100644 index 9a9f3c5..0000000 --- a/src/org/apache/http/conn/BasicEofSensorWatcher.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/BasicEofSensorWatcher.java $ - * $Revision $ - * $Date: 2008-06-27 12:49:20 -0700 (Fri, 27 Jun 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; - -import java.io.InputStream; -import java.io.IOException; - - -/** - * Basic implementation of {@link EofSensorWatcher EofSensorWatcher}. - * The underlying connection is released on close or EOF. - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 672367 $ - * - * @since 4.0 - */ -public class BasicEofSensorWatcher implements EofSensorWatcher { - - - /** The connection to auto-release. */ - protected ManagedClientConnection managedConn; - - /** Whether to keep the connection alive. */ - protected boolean attemptReuse; - - - - /** - * Creates a new watcher for auto-releasing a connection. - * - * @param conn the connection to auto-release - * @param reuse whether the connection should be re-used - */ - public BasicEofSensorWatcher(ManagedClientConnection conn, - boolean reuse) { - if (conn == null) - throw new IllegalArgumentException - ("Connection may not be null."); - - managedConn = conn; - attemptReuse = reuse; - } - - - // non-javadoc, see interface EofSensorWatcher - public boolean eofDetected(InputStream wrapped) - throws IOException { - - try { - if (attemptReuse) { - // there may be some cleanup required, such as - // reading trailers after the response body: - wrapped.close(); - managedConn.markReusable(); - } - } finally { - managedConn.releaseConnection(); - } - return false; - } - - - // non-javadoc, see interface EofSensorWatcher - public boolean streamClosed(InputStream wrapped) - throws IOException { - - try { - if (attemptReuse) { - // this assumes that closing the stream will - // consume the remainder of the response body: - wrapped.close(); - managedConn.markReusable(); - } - } finally { - managedConn.releaseConnection(); - } - return false; - } - - - // non-javadoc, see interface EofSensorWatcher - public boolean streamAbort(InputStream wrapped) - throws IOException { - - managedConn.abortConnection(); - return false; - } - -} // class BasicEofSensorWatcher diff --git a/src/org/apache/http/conn/BasicManagedEntity.java b/src/org/apache/http/conn/BasicManagedEntity.java deleted file mode 100644 index 9719e1a..0000000 --- a/src/org/apache/http/conn/BasicManagedEntity.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/BasicManagedEntity.java $ - * $Revision $ - * $Date: 2008-06-27 12:49:20 -0700 (Fri, 27 Jun 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; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.apache.http.HttpEntity; -import org.apache.http.entity.HttpEntityWrapper; - - -/** - * An entity that releases a {@link ManagedClientConnection connection}. - * A {@link ManagedClientConnection} will - * typically <i>not</i> return a managed entity, but you can replace - * the unmanaged entity in the response with a managed one. - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 672367 $ - * - * @since 4.0 - */ -public class BasicManagedEntity extends HttpEntityWrapper - implements ConnectionReleaseTrigger, EofSensorWatcher { - - /** The connection to release. */ - protected ManagedClientConnection managedConn; - - /** Whether to keep the connection alive. */ - protected final boolean attemptReuse; - - - /** - * Creates a new managed entity that can release a connection. - * - * @param entity the entity of which to wrap the content. - * Note that the argument entity can no longer be used - * afterwards, since the content will be taken by this - * managed entity. - * @param conn the connection to release - * @param reuse whether the connection should be re-used - */ - public BasicManagedEntity(HttpEntity entity, - ManagedClientConnection conn, - boolean reuse) { - super(entity); - - if (conn == null) - throw new IllegalArgumentException - ("Connection may not be null."); - - this.managedConn = conn; - this.attemptReuse = reuse; - } - - - // non-javadoc, see interface HttpEntity - @Override - public boolean isRepeatable() { - return false; - } - - - // non-javadoc, see interface HttpEntity - @Override - public InputStream getContent() throws IOException { - - return new EofSensorInputStream(wrappedEntity.getContent(), this); - } - - - // non-javadoc, see interface HttpEntity - @Override - public void consumeContent() throws IOException { - - if (managedConn == null) - return; - - try { - if (attemptReuse) { - // this will not trigger a callback from EofSensorInputStream - wrappedEntity.consumeContent(); - managedConn.markReusable(); - } - } finally { - releaseManagedConnection(); - } - } - - - // non-javadoc, see interface HttpEntity - @Override - public void writeTo(final OutputStream outstream) throws IOException { - super.writeTo(outstream); - consumeContent(); - } - - - // non-javadoc, see interface ConnectionReleaseTrigger - public void releaseConnection() - throws IOException { - - this.consumeContent(); - } - - - // non-javadoc, see interface ConnectionReleaseTrigger - public void abortConnection() - throws IOException { - - if (managedConn != null) { - try { - managedConn.abortConnection(); - } finally { - managedConn = null; - } - } - } - - - // non-javadoc, see interface EofSensorWatcher - public boolean eofDetected(InputStream wrapped) - throws IOException { - - try { - if (attemptReuse && (managedConn != null)) { - // there may be some cleanup required, such as - // reading trailers after the response body: - wrapped.close(); - managedConn.markReusable(); - } - } finally { - releaseManagedConnection(); - } - return false; - } - - - // non-javadoc, see interface EofSensorWatcher - public boolean streamClosed(InputStream wrapped) - throws IOException { - - try { - if (attemptReuse && (managedConn != null)) { - // this assumes that closing the stream will - // consume the remainder of the response body: - wrapped.close(); - managedConn.markReusable(); - } - } finally { - releaseManagedConnection(); - } - return false; - } - - - // non-javadoc, see interface EofSensorWatcher - public boolean streamAbort(InputStream wrapped) - throws IOException { - - if (managedConn != null) { - managedConn.abortConnection(); - } - return false; - } - - - /** - * Releases the connection gracefully. - * The connection attribute will be nullified. - * Subsequent invocations are no-ops. - * - * @throws IOException in case of an IO problem. - * The connection attribute will be nullified anyway. - */ - protected void releaseManagedConnection() - throws IOException { - - if (managedConn != null) { - try { - managedConn.releaseConnection(); - } finally { - managedConn = null; - } - } - } - -} // class BasicManagedEntity diff --git a/src/org/apache/http/conn/ClientConnectionManager.java b/src/org/apache/http/conn/ClientConnectionManager.java deleted file mode 100644 index e3375e1..0000000 --- a/src/org/apache/http/conn/ClientConnectionManager.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionManager.java $ - * $Revision: 671717 $ - * $Date: 2008-06-25 21:03:24 -0700 (Wed, 25 Jun 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; - - -import java.util.concurrent.TimeUnit; - -import org.apache.http.conn.routing.HttpRoute; -import org.apache.http.conn.scheme.SchemeRegistry; - -/** - * Management interface for {@link ManagedClientConnection client connections}. - * - * @author Michael Becke - * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 671717 $ - * - * @since 4.0 - */ -public interface ClientConnectionManager { - - /** - * Obtains the scheme registry used by this manager. - * - * @return the scheme registry, never <code>null</code> - */ - SchemeRegistry getSchemeRegistry() - ; - - - /** - * Returns a new {@link ClientConnectionRequest}, from which a - * {@link ManagedClientConnection} can be obtained or the request can be - * aborted. - */ - ClientConnectionRequest requestConnection(HttpRoute route, Object state) - ; - - - /** - * Releases a connection for use by others. - * You may optionally specify how long the connection is valid - * to be reused. Values <= 0 are considered to be valid forever. - * If the connection is not marked as reusable, the connection will - * not be reused regardless of the valid duration. - * - * If the connection has been released before, - * the call will be ignored. - * - * @param conn the connection to release - * @param validDuration the duration of time this connection is valid for reuse - * @param timeUnit the unit of time validDuration is measured in - * - * @see #closeExpiredConnections() - */ - void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit) - ; - - - /** - * Closes idle connections in the pool. - * Open connections in the pool that have not been used for the - * timespan given by the argument will be closed. - * Currently allocated connections are not subject to this method. - * Times will be checked with milliseconds precision - * - * All expired connections will also be closed. - * - * @param idletime the idle time of connections to be closed - * @param tunit the unit for the <code>idletime</code> - * - * @see #closeExpiredConnections() - */ - void closeIdleConnections(long idletime, TimeUnit tunit) - ; - - /** - * Closes all expired connections in the pool. - * Open connections in the pool that have not been used for - * the timespan defined when the connection was released will be closed. - * Currently allocated connections are not subject to this method. - * Times will be checked with milliseconds precision. - */ - void closeExpiredConnections(); - - /** - * Shuts down this connection manager and releases allocated resources. - * This includes closing all connections, whether they are currently - * used or not. - */ - void shutdown() - ; - - -} // interface ClientConnectionManager diff --git a/src/org/apache/http/conn/ClientConnectionManagerFactory.java b/src/org/apache/http/conn/ClientConnectionManagerFactory.java deleted file mode 100644 index 4bedc4e..0000000 --- a/src/org/apache/http/conn/ClientConnectionManagerFactory.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionManagerFactory.java $ - * $Revision: 652020 $ - * $Date: 2008-04-27 14:23:31 -0700 (Sun, 27 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; - -import org.apache.http.conn.scheme.SchemeRegistry; -import org.apache.http.params.HttpParams; - -/** - * A factory for creating new {@link ClientConnectionManager} instances. - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @since 4.0 - */ -public interface ClientConnectionManagerFactory { - - ClientConnectionManager newInstance( - HttpParams params, - SchemeRegistry schemeRegistry); - -} diff --git a/src/org/apache/http/conn/ClientConnectionOperator.java b/src/org/apache/http/conn/ClientConnectionOperator.java deleted file mode 100644 index 980b867..0000000 --- a/src/org/apache/http/conn/ClientConnectionOperator.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionOperator.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; - -import java.io.IOException; -import java.net.InetAddress; - -import org.apache.http.HttpHost; -import org.apache.http.conn.scheme.SocketFactory; -import org.apache.http.params.HttpParams; -import org.apache.http.protocol.HttpContext; - - - -/** - * Interface for opening {@link OperatedClientConnection connections}. - * This interface encapsulates the logic to create sockets and to - * open or update the connection with the new socket. - * Implementations will most likely make use of - * {@link SocketFactory socket factories}. - * <br/> - * The methods in this interface allow the creation of plain and layered - * sockets. Creating a tunnelled connection through a proxy, however, - * is not within the scope of the operator. - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 645850 $ $Date: 2008-04-08 04:08:52 -0700 (Tue, 08 Apr 2008) $ - * - * @since 4.0 - */ -public interface ClientConnectionOperator { - - - /** - * Creates a new connection that can be operated. - * - * @return a new, unopened connection for use with this operator - */ - OperatedClientConnection createConnection() - ; - - - /** - * Opens a connection to the given target host. - * - * @param conn the connection to open - * @param target the target host to connect to - * @param local the local address to route from, or - * <code>null</code> for the default - * @param context the context for the connection - * @param params the parameters for the connection - * - * @throws IOException in case of a problem - */ - void openConnection(OperatedClientConnection conn, - HttpHost target, - InetAddress local, - HttpContext context, - HttpParams params) - throws IOException - ; - - - /** - * Updates a connection with a layered secure connection. - * The typical use of this method is to update a tunnelled plain - * connection (HTTP) to a secure TLS/SSL connection (HTTPS). - * - * @param conn the open connection to update - * @param target the target host for the updated connection. - * The connection must already be open or tunnelled - * to the host and port, but the scheme of the target - * will be used to create a layered connection. - * @param context the context for the connection - * @param params the parameters for the updated connection - * - * @throws IOException in case of a problem - */ - void updateSecureConnection(OperatedClientConnection conn, - HttpHost target, - HttpContext context, - HttpParams params) - throws IOException - ; - - -} // interface ClientConnectionOperator - diff --git a/src/org/apache/http/conn/ClientConnectionRequest.java b/src/org/apache/http/conn/ClientConnectionRequest.java deleted file mode 100644 index 6ba02d0..0000000 --- a/src/org/apache/http/conn/ClientConnectionRequest.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ClientConnectionRequest.java $ - * $Revision: 651815 $ - * $Date: 2008-04-26 04:14:43 -0700 (Sat, 26 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; - -import java.util.concurrent.TimeUnit; - -/** - * Encapsulates a request for a {@link ManagedClientConnection}. - */ -public interface ClientConnectionRequest { - - /** - * Obtains a connection within a given time. - * This method will block until a connection becomes available, - * the timeout expires, or the connection manager is - * {@link ClientConnectionManager#shutdown() shut down}. - * Timeouts are handled with millisecond precision. - * - * If {@link #abortRequest()} is called while this is blocking or - * before this began, an {@link InterruptedException} will - * be thrown. - * - * @param timeout the timeout, 0 or negative for no timeout - * @param tunit the unit for the <code>timeout</code>, - * may be <code>null</code> only if there is no timeout - * - * @return a connection that can be used to communicate - * along the given route - * - * @throws ConnectionPoolTimeoutException - * in case of a timeout - * @throws InterruptedException - * if the calling thread is interrupted while waiting - */ - ManagedClientConnection getConnection(long timeout, TimeUnit tunit) - throws InterruptedException, ConnectionPoolTimeoutException; - - /** - * Aborts the call to {@link #getConnection(long, TimeUnit)}, - * causing it to throw an {@link InterruptedException}. - */ - void abortRequest(); - -} diff --git a/src/org/apache/http/conn/ConnectTimeoutException.java b/src/org/apache/http/conn/ConnectTimeoutException.java deleted file mode 100644 index 83a731a..0000000 --- a/src/org/apache/http/conn/ConnectTimeoutException.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ConnectTimeoutException.java $ - * $Revision: 617645 $ - * $Date: 2008-02-01 13:05:31 -0800 (Fri, 01 Feb 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; - -import java.io.InterruptedIOException; - -/** - * A timeout while connecting to an HTTP server or waiting for an - * available connection from an HttpConnectionManager. - * - * @author <a href="mailto:laura@lwerner.org">Laura Werner</a> - * - * @since 4.0 - */ -public class ConnectTimeoutException extends InterruptedIOException { - - private static final long serialVersionUID = -4816682903149535989L; - - /** - * Creates a ConnectTimeoutException with a <tt>null</tt> detail message. - */ - public ConnectTimeoutException() { - super(); - } - - /** - * Creates a ConnectTimeoutException with the specified detail message. - * - * @param message The exception detail message - */ - public ConnectTimeoutException(final String message) { - super(message); - } - -} diff --git a/src/org/apache/http/conn/ConnectionKeepAliveStrategy.java b/src/org/apache/http/conn/ConnectionKeepAliveStrategy.java deleted file mode 100644 index 27d56cb..0000000 --- a/src/org/apache/http/conn/ConnectionKeepAliveStrategy.java +++ /dev/null @@ -1,71 +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; - -import org.apache.http.ConnectionReuseStrategy; -import org.apache.http.HttpResponse; -import org.apache.http.protocol.HttpContext; - -/** - * Interface for deciding how long a connection can remain - * idle before being reused. - * - * @author <a href="mailto:sberlin at gmail.com">Sam Berlin</a> - * - * - * @version $Revision: $ - * - * @since 4.0 - */ -public interface ConnectionKeepAliveStrategy { - - /** - * Returns the duration of time which this connection can be safely kept - * idle. If the connection is left idle for longer than this period of time, - * it MUST not reused. A value of 0 or less may be returned to indicate that - * there is no suitable suggestion. - * - * When coupled with a {@link ConnectionReuseStrategy}, if - * {@link ConnectionReuseStrategy#keepAlive(HttpResponse, HttpContext) - * returns true, this allows you to control how long the reuse will last. If - * keepAlive returns false, this should have no meaningful impact - * - * @param response - * The last response received over the connection. - * @param context - * the context in which the connection is being used. - * - * @return the duration in ms for which it is safe to keep the connection - * idle, or <=0 if no suggested duration. - */ - long getKeepAliveDuration(HttpResponse response, HttpContext context); - -} diff --git a/src/org/apache/http/conn/ConnectionPoolTimeoutException.java b/src/org/apache/http/conn/ConnectionPoolTimeoutException.java deleted file mode 100644 index 7d4985e..0000000 --- a/src/org/apache/http/conn/ConnectionPoolTimeoutException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ConnectionPoolTimeoutException.java $ - * $Revision: 505684 $ - * $Date: 2007-02-10 04:40:02 -0800 (Sat, 10 Feb 2007) $ - * - * ==================================================================== - * 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; - -/** - * A timeout while waiting for an available connection - * from a connection manager. - * - * @author <a href="mailto:laura@lwerner.org">Laura Werner</a> - * - * @since 4.0 - */ -public class ConnectionPoolTimeoutException extends ConnectTimeoutException { - - private static final long serialVersionUID = -7898874842020245128L; - - /** - * Creates a ConnectTimeoutException with a <tt>null</tt> detail message. - */ - public ConnectionPoolTimeoutException() { - super(); - } - - /** - * Creates a ConnectTimeoutException with the specified detail message. - * - * @param message The exception detail message - */ - public ConnectionPoolTimeoutException(String message) { - super(message); - } - -} diff --git a/src/org/apache/http/conn/ConnectionReleaseTrigger.java b/src/org/apache/http/conn/ConnectionReleaseTrigger.java deleted file mode 100644 index a9ac12e..0000000 --- a/src/org/apache/http/conn/ConnectionReleaseTrigger.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ConnectionReleaseTrigger.java $ - * $Revision: 672367 $ - * $Date: 2008-06-27 12:49:20 -0700 (Fri, 27 Jun 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; - -import java.io.IOException; - - -/** - * Interface for releasing a connection. - * This can be implemented by various "trigger" objects which are - * associated with a connection, for example - * a {@link EofSensorInputStream stream} - * or an {@link BasicManagedEntity entity} - * or the {@link ManagedClientConnection connection} itself. - * <br/> - * The methods in this interface can safely be called multiple times. - * The first invocation releases the connection, subsequent calls - * are ignored. - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 672367 $ - * - * @since 4.0 - */ -public interface ConnectionReleaseTrigger { - - /** - * Releases the connection with the option of keep-alive. This is a - * "graceful" release and may cause IO operations for consuming the - * remainder of a response entity. Use - * {@link #abortConnection abortConnection} for a hard release. The - * connection may be reused as specified by the duration. - * - * @throws IOException - * in case of an IO problem. The connection will be released - * anyway. - */ - void releaseConnection() - throws IOException - ; - - /** - * Releases the connection without the option of keep-alive. - * This is a "hard" release that implies a shutdown of the connection. - * Use {@link #releaseConnection releaseConnection} for a graceful release. - * - * @throws IOException in case of an IO problem. - * The connection will be released anyway. - */ - void abortConnection() - throws IOException - ; - - -} // interface ConnectionReleaseTrigger diff --git a/src/org/apache/http/conn/EofSensorInputStream.java b/src/org/apache/http/conn/EofSensorInputStream.java deleted file mode 100644 index 0e1b90e..0000000 --- a/src/org/apache/http/conn/EofSensorInputStream.java +++ /dev/null @@ -1,326 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/EofSensorInputStream.java $ - * $Revision: 672367 $ - * $Date: 2008-06-27 12:49:20 -0700 (Fri, 27 Jun 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; - -import java.io.InputStream; -import java.io.IOException; - - -/** - * A stream wrapper that triggers actions on {@link #close close()} and EOF. - * Primarily used to auto-release an underlying - * {@link ManagedClientConnection connection} - * when the response body is consumed or no longer needed. - * - * <p> - * This class is based on <code>AutoCloseInputStream</code> in HttpClient 3.1, - * but has notable differences. It does not allow mark/reset, distinguishes - * different kinds of event, and does not always close the underlying stream - * on EOF. That decision is left to the {@link EofSensorWatcher watcher}. - * </p> - * - * @see EofSensorWatcher EofSensorWatcher - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * @author Ortwin Glueck - * @author Eric Johnson - * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 672367 $ - * - * @since 4.0 - */ -// don't use FilterInputStream as the base class, we'd have to -// override markSupported(), mark(), and reset() to disable them -public class EofSensorInputStream extends InputStream - implements ConnectionReleaseTrigger { - - /** - * The wrapped input stream, while accessible. - * The value changes to <code>null</code> when the wrapped stream - * becomes inaccessible. - */ - protected InputStream wrappedStream; - - - /** - * Indicates whether this stream itself is closed. - * If it isn't, but {@link #wrappedStream wrappedStream} - * is <code>null</code>, we're running in EOF mode. - * All read operations will indicate EOF without accessing - * the underlying stream. After closing this stream, read - * operations will trigger an {@link IOException IOException}. - * - * @see #isReadAllowed isReadAllowed - */ - private boolean selfClosed; - - /** The watcher to be notified, if any. */ - private EofSensorWatcher eofWatcher; - - - /** - * Creates a new EOF sensor. - * If no watcher is passed, the underlying stream will simply be - * closed when EOF is detected or {@link #close close} is called. - * Otherwise, the watcher decides whether the underlying stream - * should be closed before detaching from it. - * - * @param in the wrapped stream - * @param watcher the watcher for events, or <code>null</code> for - * auto-close behavior without notification - */ - public EofSensorInputStream(final InputStream in, - final EofSensorWatcher watcher) { - if (in == null) { - throw new IllegalArgumentException - ("Wrapped stream may not be null."); - } - - wrappedStream = in; - selfClosed = false; - eofWatcher = watcher; - } - - - /** - * Checks whether the underlying stream can be read from. - * - * @return <code>true</code> if the underlying stream is accessible, - * <code>false</code> if this stream is in EOF mode and - * detached from the underlying stream - * - * @throws IOException if this stream is already closed - */ - protected boolean isReadAllowed() throws IOException { - if (selfClosed) { - throw new IOException("Attempted read on closed stream."); - } - return (wrappedStream != null); - } - - - // non-javadoc, see base class InputStream - @Override - public int read() throws IOException { - int l = -1; - - if (isReadAllowed()) { - try { - l = wrappedStream.read(); - checkEOF(l); - } catch (IOException ex) { - checkAbort(); - throw ex; - } - } - - return l; - } - - - // non-javadoc, see base class InputStream - @Override - public int read(byte[] b, int off, int len) throws IOException { - int l = -1; - - if (isReadAllowed()) { - try { - l = wrappedStream.read(b, off, len); - checkEOF(l); - } catch (IOException ex) { - checkAbort(); - throw ex; - } - } - - return l; - } - - - // non-javadoc, see base class InputStream - @Override - public int read(byte[] b) throws IOException { - int l = -1; - - if (isReadAllowed()) { - try { - l = wrappedStream.read(b); - checkEOF(l); - } catch (IOException ex) { - checkAbort(); - throw ex; - } - } - return l; - } - - - // non-javadoc, see base class InputStream - @Override - public int available() throws IOException { - int a = 0; // not -1 - - if (isReadAllowed()) { - try { - a = wrappedStream.available(); - // no checkEOF() here, available() can't trigger EOF - } catch (IOException ex) { - checkAbort(); - throw ex; - } - } - - return a; - } - - - // non-javadoc, see base class InputStream - @Override - public void close() throws IOException { - // tolerate multiple calls to close() - selfClosed = true; - checkClose(); - } - - - /** - * Detects EOF and notifies the watcher. - * This method should only be called while the underlying stream is - * still accessible. Use {@link #isReadAllowed isReadAllowed} to - * check that condition. - * <br/> - * If EOF is detected, the watcher will be notified and this stream - * is detached from the underlying stream. This prevents multiple - * notifications from this stream. - * - * @param eof the result of the calling read operation. - * A negative value indicates that EOF is reached. - * - * @throws IOException - * in case of an IO problem on closing the underlying stream - */ - protected void checkEOF(int eof) throws IOException { - - if ((wrappedStream != null) && (eof < 0)) { - try { - boolean scws = true; // should close wrapped stream? - if (eofWatcher != null) - scws = eofWatcher.eofDetected(wrappedStream); - if (scws) - wrappedStream.close(); - } finally { - wrappedStream = null; - } - } - } - - - /** - * Detects stream close and notifies the watcher. - * There's not much to detect since this is called by {@link #close close}. - * The watcher will only be notified if this stream is closed - * for the first time and before EOF has been detected. - * This stream will be detached from the underlying stream to prevent - * multiple notifications to the watcher. - * - * @throws IOException - * in case of an IO problem on closing the underlying stream - */ - protected void checkClose() throws IOException { - - if (wrappedStream != null) { - try { - boolean scws = true; // should close wrapped stream? - if (eofWatcher != null) - scws = eofWatcher.streamClosed(wrappedStream); - if (scws) - wrappedStream.close(); - } finally { - wrappedStream = null; - } - } - } - - - /** - * Detects stream abort and notifies the watcher. - * There's not much to detect since this is called by - * {@link #abortConnection abortConnection}. - * The watcher will only be notified if this stream is aborted - * for the first time and before EOF has been detected or the - * stream has been {@link #close closed} gracefully. - * This stream will be detached from the underlying stream to prevent - * multiple notifications to the watcher. - * - * @throws IOException - * in case of an IO problem on closing the underlying stream - */ - protected void checkAbort() throws IOException { - - if (wrappedStream != null) { - try { - boolean scws = true; // should close wrapped stream? - if (eofWatcher != null) - scws = eofWatcher.streamAbort(wrappedStream); - if (scws) - wrappedStream.close(); - } finally { - wrappedStream = null; - } - } - } - - - /** - * Same as {@link #close close()}. - */ - public void releaseConnection() throws IOException { - this.close(); - } - - /** - * Aborts this stream. - * This is a special version of {@link #close close()} which prevents - * re-use of the underlying connection, if any. Calling this method - * indicates that there should be no attempt to read until the end of - * the stream. - */ - public void abortConnection() throws IOException { - // tolerate multiple calls - selfClosed = true; - checkAbort(); - } - -} // class EOFSensorInputStream - diff --git a/src/org/apache/http/conn/EofSensorWatcher.java b/src/org/apache/http/conn/EofSensorWatcher.java deleted file mode 100644 index 837f8d9..0000000 --- a/src/org/apache/http/conn/EofSensorWatcher.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/EofSensorWatcher.java $ - * $Revision: 552264 $ - * $Date: 2007-07-01 02:37:47 -0700 (Sun, 01 Jul 2007) $ - * - * ==================================================================== - * - * 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; - -import java.io.InputStream; -import java.io.IOException; - - -/** - * A watcher for {@link EofSensorInputStream EofSensorInputStream}. - * Each stream will notify it's watcher at most once. - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 552264 $ - * - * @since 4.0 - */ -public interface EofSensorWatcher { - - /** - * Indicates that EOF is detected. - * - * @param wrapped the underlying stream which has reached EOF - * - * @return <code>true</code> if <code>wrapped</code> should be closed, - * <code>false</code> if it should be left alone - * - * @throws IOException - * in case of an IO problem, for example if the watcher itself - * closes the underlying stream. The caller will leave the - * wrapped stream alone, as if <code>false</code> was returned. - */ - boolean eofDetected(InputStream wrapped) - throws IOException - ; - - - /** - * Indicates that the {@link EofSensorInputStream stream} is closed. - * This method will be called only if EOF was <i>not</i> detected - * before closing. Otherwise, {@link #eofDetected eofDetected} is called. - * - * @param wrapped the underlying stream which has not reached EOF - * - * @return <code>true</code> if <code>wrapped</code> should be closed, - * <code>false</code> if it should be left alone - * - * @throws IOException - * in case of an IO problem, for example if the watcher itself - * closes the underlying stream. The caller will leave the - * wrapped stream alone, as if <code>false</code> was returned. - */ - boolean streamClosed(InputStream wrapped) - throws IOException - ; - - - /** - * Indicates that the {@link EofSensorInputStream stream} is aborted. - * This method will be called only if EOF was <i>not</i> detected - * before aborting. Otherwise, {@link #eofDetected eofDetected} is called. - * <p/> - * This method will also be invoked when an input operation causes an - * IOException to be thrown to make sure the input stream gets shut down. - * - * @param wrapped the underlying stream which has not reached EOF - * - * @return <code>true</code> if <code>wrapped</code> should be closed, - * <code>false</code> if it should be left alone - * - * @throws IOException - * in case of an IO problem, for example if the watcher itself - * closes the underlying stream. The caller will leave the - * wrapped stream alone, as if <code>false</code> was returned. - */ - boolean streamAbort(InputStream wrapped) - throws IOException - ; - - -} // interface EofSensorWatcher diff --git a/src/org/apache/http/conn/HttpHostConnectException.java b/src/org/apache/http/conn/HttpHostConnectException.java deleted file mode 100644 index 743ca77..0000000 --- a/src/org/apache/http/conn/HttpHostConnectException.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/HttpHostConnectException.java $ - * $Revision: 652020 $ - * $Date: 2008-04-27 14:23:31 -0700 (Sun, 27 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; - -import java.net.ConnectException; - -import org.apache.http.HttpHost; - -/** - * A {@link ConnectException} that specifies the {@link HttpHost} that was - * being connected to. - */ -public class HttpHostConnectException extends ConnectException { - - private static final long serialVersionUID = -3194482710275220224L; - - private final HttpHost host; - - public HttpHostConnectException(final HttpHost host, final ConnectException cause) { - super("Connection to " + host + " refused"); - this.host = host; - initCause(cause); - } - - public HttpHost getHost() { - return this.host; - } - -} diff --git a/src/org/apache/http/conn/ManagedClientConnection.java b/src/org/apache/http/conn/ManagedClientConnection.java deleted file mode 100644 index f642cb9..0000000 --- a/src/org/apache/http/conn/ManagedClientConnection.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ManagedClientConnection.java $ - * $Revision: 672969 $ - * $Date: 2008-06-30 18:09:50 -0700 (Mon, 30 Jun 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; - -import java.io.IOException; -import java.util.concurrent.TimeUnit; - -import javax.net.ssl.SSLSession; - -import org.apache.http.HttpClientConnection; -import org.apache.http.HttpInetConnection; -import org.apache.http.HttpHost; -import org.apache.http.params.HttpParams; -import org.apache.http.protocol.HttpContext; - -import org.apache.http.conn.routing.HttpRoute; - - - -/** - * A client-side connection with advanced connection logic. - * Instances are typically obtained from a connection manager. - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 672969 $ - * - * @since 4.0 - */ -public interface ManagedClientConnection extends - HttpClientConnection, HttpInetConnection, ConnectionReleaseTrigger { - - - /** - * Indicates whether this connection is secure. - * The return value is well-defined only while the connection is open. - * It may change even while the connection is open. - * - * @return <code>true</code> if this connection is secure, - * <code>false</code> otherwise - */ - boolean isSecure() - ; - - - /** - * Obtains the current route of this connection. - * - * @return the route established so far, or - * <code>null</code> if not connected - */ - HttpRoute getRoute() - ; - - - /** - * Obtains the SSL session of the underlying connection, if any. - * If this connection is open, and the underlying socket is an - * {@link javax.net.ssl.SSLSocket SSLSocket}, the SSL session of - * that socket is obtained. This is a potentially blocking operation. - * <br/> - * <b>Note:</b> Whether the underlying socket is an SSL socket - * can not necessarily be determined via {@link #isSecure}. - * Plain sockets may be considered secure, for example if they are - * connected to a known host in the same network segment. - * On the other hand, SSL sockets may be considered insecure, - * for example depending on the chosen cipher suite. - * - * @return the underlying SSL session if available, - * <code>null</code> otherwise - */ - SSLSession getSSLSession() - ; - - - /** - * Opens this connection according to the given route. - * - * @param route the route along which to open. It will be opened to - * the first proxy if present, or directly to the target. - * @param context the context for opening this connection - * @param params the parameters for opening this connection - * - * @throws IOException in case of a problem - */ - void open(HttpRoute route, HttpContext context, HttpParams params) - throws IOException - ; - - - /** - * Indicates that a tunnel to the target has been established. - * The route is the one previously passed to {@link #open open}. - * Subsequently, {@link #layerProtocol layerProtocol} can be called - * to layer the TLS/SSL protocol on top of the tunnelled connection. - * <br/> - * <b>Note:</b> In HttpClient 3, a call to the corresponding method - * would automatically trigger the layering of the TLS/SSL protocol. - * This is not the case anymore, you can establish a tunnel without - * layering a new protocol over the connection. - * - * @param secure <code>true</code> if the tunnel should be considered - * secure, <code>false</code> otherwise - * @param params the parameters for tunnelling this connection - * - * @throws IOException in case of a problem - */ - void tunnelTarget(boolean secure, HttpParams params) - throws IOException - ; - - - /** - * Indicates that a tunnel to an intermediate proxy has been established. - * This is used exclusively for so-called <i>proxy chains</i>, where - * a request has to pass through multiple proxies before reaching the - * target. In that case, all proxies but the last need to be tunnelled - * when establishing the connection. Tunnelling of the last proxy to the - * target is optional and would be indicated via {@link #tunnelTarget}. - * - * @param next the proxy to which the tunnel was established. - * This is <i>not</i> the proxy <i>through</i> which - * the tunnel was established, but the new end point - * of the tunnel. The tunnel does <i>not</i> yet - * reach to the target, use {@link #tunnelTarget} - * to indicate an end-to-end tunnel. - * @param secure <code>true</code> if the connection should be - * considered secure, <code>false</code> otherwise - * @param params the parameters for tunnelling this connection - * - * @throws IOException in case of a problem - */ - void tunnelProxy(HttpHost next, boolean secure, HttpParams params) - throws IOException - ; - - - /** - * Layers a new protocol on top of a {@link #tunnelTarget tunnelled} - * connection. This is typically used to create a TLS/SSL connection - * through a proxy. - * The route is the one previously passed to {@link #open open}. - * It is not guaranteed that the layered connection is - * {@link #isSecure secure}. - * - * @param context the context for layering on top of this connection - * @param params the parameters for layering on top of this connection - * - * @throws IOException in case of a problem - */ - void layerProtocol(HttpContext context, HttpParams params) - throws IOException - ; - - - /** - * Marks this connection as being in a reusable communication state. - * The checkpoints for reuseable communication states (in the absence - * of pipelining) are before sending a request and after receiving - * the response in it's entirety. - * The connection will automatically clear the checkpoint when - * used for communication. A call to this method indicates that - * the next checkpoint has been reached. - * <br/> - * A reusable communication state is necessary but not sufficient - * for the connection to be reused. - * A {@link #getRoute route} mismatch, the connection being closed, - * or other circumstances might prevent reuse. - */ - void markReusable() - ; - - - /** - * Marks this connection as not being in a reusable state. - * This can be used immediately before releasing this connection - * to prevent it's reuse. Reasons for preventing reuse include - * error conditions and the evaluation of a - * {@link org.apache.http.ConnectionReuseStrategy reuse strategy}. - * <br/> - * <b>Note:</b> - * It is <i>not</i> necessary to call here before writing to - * or reading from this connection. Communication attempts will - * automatically unmark the state as non-reusable. It can then - * be switched back using {@link #markReusable markReusable}. - */ - void unmarkReusable() - ; - - - /** - * Indicates whether this connection is in a reusable communication state. - * See {@link #markReusable markReusable} and - * {@link #unmarkReusable unmarkReusable} for details. - * - * @return <code>true</code> if this connection is marked as being in - * a reusable communication state, - * <code>false</code> otherwise - */ - boolean isMarkedReusable() - ; - - /** - * Assigns a state object to this connection. Connection managers may make - * use of the connection state when allocating persistent connections. - * - * @param state The state object - */ - void setState(Object state) - ; - - /** - * Returns the state object associated with this connection. - * - * @return The state object - */ - Object getState() - ; - - /** - * Sets the duration that this connection can remain idle before it is - * reused. The connection should not be used again if this time elapses. The - * idle duration must be reset after each request sent over this connection. - * The elapsed time starts counting when the connection is released, which - * is typically after the headers (and any response body, if present) is - * fully consumed. - */ - void setIdleDuration(long duration, TimeUnit unit); - -} // interface ManagedClientConnection diff --git a/src/org/apache/http/conn/MultihomePlainSocketFactory.java b/src/org/apache/http/conn/MultihomePlainSocketFactory.java deleted file mode 100644 index e9549ab..0000000 --- a/src/org/apache/http/conn/MultihomePlainSocketFactory.java +++ /dev/null @@ -1,212 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/MultihomePlainSocketFactory.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 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; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.SocketTimeoutException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Arrays; - -import org.apache.http.conn.scheme.PlainSocketFactory; -import org.apache.http.conn.scheme.SocketFactory; -import org.apache.http.params.HttpConnectionParams; -import org.apache.http.params.HttpParams; - -/** - * Socket factory that implements a simple multi-home fail-over on connect failure, - * provided the same hostname resolves to multiple {@link InetAddress}es. Please note - * the {@link #connectSocket(Socket, String, int, InetAddress, int, HttpParams)} - * method cannot be reliably interrupted by closing the socket returned by the - * {@link #createSocket()} method. - */ -public final class MultihomePlainSocketFactory implements SocketFactory { - - /** - * The factory singleton. - */ - private static final - MultihomePlainSocketFactory DEFAULT_FACTORY = new MultihomePlainSocketFactory(); - - /** - * Gets the singleton instance of this class. - * @return the one and only plain socket factory - */ - public static MultihomePlainSocketFactory getSocketFactory() { - return DEFAULT_FACTORY; - } - - /** - * Restricted default constructor. - */ - private MultihomePlainSocketFactory() { - super(); - } - - - // non-javadoc, see interface org.apache.http.conn.SocketFactory - public Socket createSocket() { - return new Socket(); - } - - /** - * Attempts to connects the socket to any of the {@link InetAddress}es the - * given host name resolves to. If connection to all addresses fail, the - * last I/O exception is propagated to the caller. - * - * @param sock socket to connect to any of the given addresses - * @param host Host name to connect to - * @param port the port to connect to - * @param localAddress local address - * @param localPort local port - * @param params HTTP parameters - * - * @throws IOException if an error occurs during the connection - * @throws SocketTimeoutException if timeout expires before connecting - */ - 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); - - InetAddress[] inetadrs = InetAddress.getAllByName(host); - List<InetAddress> addresses = new ArrayList<InetAddress>(inetadrs.length); - addresses.addAll(Arrays.asList(inetadrs)); - Collections.shuffle(addresses); - - IOException lastEx = null; - for (InetAddress address: addresses) { - try { - sock.connect(new InetSocketAddress(address, port), timeout); - break; - } catch (SocketTimeoutException ex) { - throw ex; - } catch (IOException ex) { - // create new socket - sock = new Socket(); - // keep the last exception and retry - lastEx = ex; - } - } - if (lastEx != null) { - throw lastEx; - } - 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/OperatedClientConnection.java b/src/org/apache/http/conn/OperatedClientConnection.java deleted file mode 100644 index 2eda8e9..0000000 --- a/src/org/apache/http/conn/OperatedClientConnection.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/OperatedClientConnection.java $ - * $Revision: 646087 $ - * $Date: 2008-04-08 14:36:46 -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; - -import java.io.IOException; -import java.net.Socket; - -import org.apache.http.HttpClientConnection; -import org.apache.http.HttpHost; -import org.apache.http.HttpInetConnection; -import org.apache.http.params.HttpParams; - - -/** - * A client-side connection that relies on outside logic to connect sockets to the - * appropriate hosts. It can be operated directly by an application, or through an - * {@link ClientConnectionOperator operator}. - * - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 646087 $ $Date: 2008-04-08 14:36:46 -0700 (Tue, 08 Apr 2008) $ - * - * @since 4.0 - */ -public interface OperatedClientConnection - extends HttpClientConnection, HttpInetConnection { - - /** - * Obtains the target host for this connection. - * If the connection is to a proxy but not tunnelled, this is - * the proxy. If the connection is tunnelled through a proxy, - * this is the target of the tunnel. - * <br/> - * The return value is well-defined only while the connection is open. - * It may change even while the connection is open, - * because of an {@link #update update}. - * - * @return the host to which this connection is opened - */ - HttpHost getTargetHost() - ; - - /** - * Indicates whether this connection is secure. - * The return value is well-defined only while the connection is open. - * It may change even while the connection is open, - * because of an {@link #update update}. - * - * @return <code>true</code> if this connection is secure, - * <code>false</code> otherwise - */ - boolean isSecure() - ; - - /** - * Obtains the socket for this connection. - * The return value is well-defined only while the connection is open. - * It may change even while the connection is open, - * because of an {@link #update update}. - * - * @return the socket for communicating with the - * {@link #getTargetHost target host} - */ - Socket getSocket() - ; - - - // There is no getParams(). For the moment, we - // do not require connections to store parameters. - - - /** - * Signals that this connection is in the process of being open. - * <br/> - * By calling this method, you can provide the connection with - * the unconnected socket that will be connected before - * {@link #openCompleted} is called. This allows - * the connection to close that socket if - * {@link org.apache.http.HttpConnection#shutdown shutdown} - * is called before it is open. Closing the unconnected socket - * will interrupt a thread that is blocked on the connect. - * Otherwise, that thread will either time out on the connect, - * or it returns successfully and then opens this connection - * which was just shut down. - * <br/> - * You also must call {@link #openCompleted} in order to complete - * the process - * - * @param sock the unconnected socket which is about to - * be connected. - * @param target the target host of this connection - */ - void opening(Socket sock, HttpHost target) - throws IOException - ; - - - /** - * Signals that the connection has been successfully open. - * An attempt to call this method on an open connection will cause - * an exception. - * - * @param secure <code>true</code> if this connection is secure, for - * example if an <code>SSLSocket</code> is used, or - * <code>false</code> if it is not secure - * @param params parameters for this connection. The parameters will - * be used when creating dependent objects, for example - * to determine buffer sizes. - */ - void openCompleted(boolean secure, HttpParams params) - throws IOException - ; - - - /** - * Updates this connection. - * A connection can be updated only while it is open. - * Updates are used for example when a tunnel has been established, - * or when a TLS/SSL connection has been layered on top of a plain - * socket connection. - * <br/> - * <b>Note:</b> Updating the connection will <i>not</i> close the - * previously used socket. It is the caller's responsibility to close - * that socket if it is no longer required. - * - * @param sock the new socket for communicating with the target host, - * or <code>null</code> to continue using the old socket. - * If <code>null</code> is passed, helper objects that - * depend on the socket should be re-used. In that case, - * some changes in the parameters will not take effect. - * @param target the new target host of this connection - * @param secure <code>true</code> if this connection is now secure, - * <code>false</code> if it is not secure - * @param params new parameters for this connection - */ - void update(Socket sock, HttpHost target, - boolean secure, HttpParams params) - throws IOException - ; - - -} // interface OperatedClientConnection diff --git a/src/org/apache/http/conn/package.html b/src/org/apache/http/conn/package.html deleted file mode 100644 index e0b29cd..0000000 --- a/src/org/apache/http/conn/package.html +++ /dev/null @@ -1,91 +0,0 @@ -<html> -<head> -<!-- -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/package.html $ - * $Revision: 651813 $ - * $Date: 2008-04-26 03:43:34 -0700 (Sat, 26 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/>. - * - */ ---> -</head> -<body> -The client-side connection management and handling API -at the heart of what is referred to as <i>HttpConn</i>. -This component provides interfaces and implementations for -opening and managing connections. - -<p> -The lowest layer of connection handling is comprised of -{@link org.apache.http.conn.OperatedClientConnection OperatedClientConnection} -and -{@link org.apache.http.conn.ClientConnectionOperator ClientConnectionOperator}. -The connection interface extends the core -{@link org.apache.http.HttpClientConnection HttpClientConnection} -by operations to set and update a socket. -An operator encapsulates the logic to open and layer sockets, -typically using a {@link org.apache.http.conn.scheme.SocketFactory SocketFactory}. -The socket factory for a protocol -{@link org.apache.http.conn.scheme.Scheme Scheme} -such as "http" or "https" can be looked up in a -{@link org.apache.http.conn.scheme.SchemeRegistry SchemeRegistry}. -Applications without a need for sophisticated connection management -can use this layer directly. -</p> - -<p> -On top of that lies the connection management layer. A -{@link org.apache.http.conn.ClientConnectionManager ClientConnectionManager} -internally manages operated connections, but hands out instances of -{@link org.apache.http.conn.ManagedClientConnection ManagedClientConnection}. -This interface abstracts from the underlying socket operations and -provides convenient methods for opening and updating sockets in order -to establish a {@link org.apache.http.conn.routing.HttpRoute route}. -The operator is encapsulated by the connection manager and called -automatically. - -<br/> - -Connections obtained from a manager have to be returned after use. -This can be {@link org.apache.http.conn.ConnectionReleaseTrigger triggered} -on various levels, either by releasing the -{@link org.apache.http.conn.ManagedClientConnection - connection} -directly, or by calling a method on an -{@link org.apache.http.conn.BasicManagedEntity entity} -received from the connection, or by closing the -{@link org.apache.http.conn.EofSensorInputStream stream} -from which that entity is being read. - -Connection managers will try to keep returned connections alive in -order to re-use them for subsequent requests along the same route. -The managed connection interface and all triggers for connection release -provide methods to enable or disable this behavior. -</p> - -</body> -</html> diff --git a/src/org/apache/http/conn/params/ConnConnectionPNames.java b/src/org/apache/http/conn/params/ConnConnectionPNames.java deleted file mode 100644 index ff1a090..0000000 --- a/src/org/apache/http/conn/params/ConnConnectionPNames.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnConnectionPNames.java $ - * $Revision: 576068 $ - * $Date: 2007-09-16 03:25:01 -0700 (Sun, 16 Sep 2007) $ - * - * ==================================================================== - * - * 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.params; - - -/** - * Parameter names for connections in HttpConn. - * - * @version $Revision: 576068 $ - * - * @since 4.0 - */ -public interface ConnConnectionPNames { - - - /** - * Defines the maximum number of ignorable lines before we expect - * a HTTP response's status line. - * <p> - * With HTTP/1.1 persistent connections, the problem arises that - * broken scripts could return a wrong Content-Length - * (there are more bytes sent than specified). - * Unfortunately, in some cases, this cannot be detected after the - * bad response, but only before the next one. - * So HttpClient must be able to skip those surplus lines this way. - * </p> - * <p> - * This parameter expects a value of type {@link Integer}. - * 0 disallows all garbage/empty lines before the status line. - * Use {@link java.lang.Integer#MAX_VALUE} for unlimited - * (default in lenient mode). - * </p> - */ - public static final String MAX_STATUS_LINE_GARBAGE = "http.connection.max-status-line-garbage"; - - -} diff --git a/src/org/apache/http/conn/params/ConnConnectionParamBean.java b/src/org/apache/http/conn/params/ConnConnectionParamBean.java deleted file mode 100644 index 094b152..0000000 --- a/src/org/apache/http/conn/params/ConnConnectionParamBean.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnConnectionParamBean.java $ - * $Revision: 652020 $ - * $Date: 2008-04-27 14:23:31 -0700 (Sun, 27 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.params; - -import org.apache.http.params.HttpAbstractParamBean; -import org.apache.http.params.HttpParams; - -/** - * Allows for setting parameters relating to connections on - * {@link HttpParams}. This class ensures that the values set on the params - * are type-safe. - */ -public class ConnConnectionParamBean extends HttpAbstractParamBean { - - public ConnConnectionParamBean (final HttpParams params) { - super(params); - } - - /** - * @see ConnConnectionPNames#MAX_STATUS_LINE_GARBAGE - */ - public void setMaxStatusLineGarbage (final int maxStatusLineGarbage) { - params.setIntParameter(ConnConnectionPNames.MAX_STATUS_LINE_GARBAGE, maxStatusLineGarbage); - } - -} diff --git a/src/org/apache/http/conn/params/ConnManagerPNames.java b/src/org/apache/http/conn/params/ConnManagerPNames.java deleted file mode 100644 index 1184b12..0000000 --- a/src/org/apache/http/conn/params/ConnManagerPNames.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnManagerPNames.java $ - * $Revision: 658781 $ - * $Date: 2008-05-21 10:42:13 -0700 (Wed, 21 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.params; - - -/** - * Parameter names for connection managers in HttpConn. - * - * @version $Revision: 658781 $ - * - * @since 4.0 - */ -public interface ConnManagerPNames { - - /** - * Defines the timeout in milliseconds used when retrieving an instance of - * {@link org.apache.http.conn.ManagedClientConnection} from the - * {@link org.apache.http.conn.ClientConnectionManager}. - * <p> - * This parameter expects a value of type {@link Long}. - * </p> - */ - public static final String TIMEOUT = "http.conn-manager.timeout"; - - /** - * Defines the maximum number of connections per route. - * This limit is interpreted by client connection managers - * and applies to individual manager instances. - * <p> - * This parameter expects a value of type {@link ConnPerRoute}. - * </p> - */ - public static final String MAX_CONNECTIONS_PER_ROUTE = "http.conn-manager.max-per-route"; - - /** - * Defines the maximum number of connections in total. - * This limit is interpreted by client connection managers - * and applies to individual manager instances. - * <p> - * This parameter expects a value of type {@link Integer}. - * </p> - */ - public static final String MAX_TOTAL_CONNECTIONS = "http.conn-manager.max-total"; - -} diff --git a/src/org/apache/http/conn/params/ConnManagerParamBean.java b/src/org/apache/http/conn/params/ConnManagerParamBean.java deleted file mode 100644 index 830b7bf..0000000 --- a/src/org/apache/http/conn/params/ConnManagerParamBean.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnManagerParamBean.java $ - * $Revision: 658781 $ - * $Date: 2008-05-21 10:42:13 -0700 (Wed, 21 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.params; - -import org.apache.http.params.HttpAbstractParamBean; -import org.apache.http.params.HttpParams; - -/** - * Allows for setting parameters relating to connection managers on - * {@link HttpParams}. This class ensures that the values set on the params - * are type-safe. - */ -public class ConnManagerParamBean extends HttpAbstractParamBean { - - public ConnManagerParamBean (final HttpParams params) { - super(params); - } - - public void setTimeout (final long timeout) { - params.setLongParameter(ConnManagerPNames.TIMEOUT, timeout); - } - - /** @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS */ - public void setMaxTotalConnections (final int maxConnections) { - params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, maxConnections); - } - - /** @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE */ - public void setConnectionsPerRoute(final ConnPerRouteBean connPerRoute) { - params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, connPerRoute); - } - -} diff --git a/src/org/apache/http/conn/params/ConnManagerParams.java b/src/org/apache/http/conn/params/ConnManagerParams.java deleted file mode 100644 index c6e042e..0000000 --- a/src/org/apache/http/conn/params/ConnManagerParams.java +++ /dev/null @@ -1,169 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnManagerParams.java $ - * $Revision: 658785 $ - * $Date: 2008-05-21 10:47:40 -0700 (Wed, 21 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.params; - -import org.apache.http.conn.routing.HttpRoute; -import org.apache.http.params.HttpParams; - -/** - * This class represents a collection of HTTP protocol parameters applicable - * to client-side - * {@link org.apache.http.conn.ClientConnectionManager connection managers}. - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * @author Michael Becke - * - * @version $Revision: 658785 $ - * - * @since 4.0 - * - * @see ConnManagerPNames - */ -public final class ConnManagerParams implements ConnManagerPNames { - - /** The default maximum number of connections allowed overall */ - public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20; - - /** - * Returns the timeout in milliseconds used when retrieving a - * {@link org.apache.http.conn.ManagedClientConnection} from the - * {@link org.apache.http.conn.ClientConnectionManager}. - * - * @return timeout in milliseconds. - */ - public static long getTimeout(final HttpParams params) { - if (params == null) { - throw new IllegalArgumentException("HTTP parameters may not be null"); - } - return params.getLongParameter(TIMEOUT, 0); - } - - /** - * Sets the timeout in milliseconds used when retrieving a - * {@link org.apache.http.conn.ManagedClientConnection} from the - * {@link org.apache.http.conn.ClientConnectionManager}. - * - * @param timeout the timeout in milliseconds - */ - public static void setTimeout(final HttpParams params, long timeout) { - if (params == null) { - throw new IllegalArgumentException("HTTP parameters may not be null"); - } - params.setLongParameter(TIMEOUT, timeout); - } - - /** The default maximum number of connections allowed per host */ - private static final ConnPerRoute DEFAULT_CONN_PER_ROUTE = new ConnPerRoute() { - - public int getMaxForRoute(HttpRoute route) { - return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE; - } - - }; - - /** - * Sets lookup interface for maximum number of connections allowed per route. - * - * @param params HTTP parameters - * @param connPerRoute lookup interface for maximum number of connections allowed - * per route - * - * @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE - */ - public static void setMaxConnectionsPerRoute(final HttpParams params, - final ConnPerRoute connPerRoute) { - if (params == null) { - throw new IllegalArgumentException - ("HTTP parameters must not be null."); - } - params.setParameter(MAX_CONNECTIONS_PER_ROUTE, connPerRoute); - } - - /** - * Returns lookup interface for maximum number of connections allowed per route. - * - * @param params HTTP parameters - * - * @return lookup interface for maximum number of connections allowed per route. - * - * @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE - */ - public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) { - if (params == null) { - throw new IllegalArgumentException - ("HTTP parameters must not be null."); - } - ConnPerRoute connPerRoute = (ConnPerRoute) params.getParameter(MAX_CONNECTIONS_PER_ROUTE); - if (connPerRoute == null) { - connPerRoute = DEFAULT_CONN_PER_ROUTE; - } - return connPerRoute; - } - - - /** - * Sets the maximum number of connections allowed. - * - * @param params HTTP parameters - * @param maxTotalConnections The maximum number of connections allowed. - * - * @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS - */ - public static void setMaxTotalConnections( - final HttpParams params, - int maxTotalConnections) { - if (params == null) { - throw new IllegalArgumentException - ("HTTP parameters must not be null."); - } - params.setIntParameter(MAX_TOTAL_CONNECTIONS, maxTotalConnections); - } - - /** - * Gets the maximum number of connections allowed. - * - * @param params HTTP parameters - * - * @return The maximum number of connections allowed. - * - * @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS - */ - public static int getMaxTotalConnections( - final HttpParams params) { - if (params == null) { - throw new IllegalArgumentException - ("HTTP parameters must not be null."); - } - return params.getIntParameter(MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS); - } - - -} diff --git a/src/org/apache/http/conn/params/ConnPerRoute.java b/src/org/apache/http/conn/params/ConnPerRoute.java deleted file mode 100644 index abff04e..0000000 --- a/src/org/apache/http/conn/params/ConnPerRoute.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnPerRoute.java $ - * $Revision: 651813 $ - * $Date: 2008-04-26 03:43:34 -0700 (Sat, 26 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.params; - -import org.apache.http.conn.routing.HttpRoute; - -/** - * This interface is intended for looking up maximum number of connections - * allowed for for a given route. This class can be used by pooling - * {@link org.apache.http.conn.ClientConnectionManager connection managers} for - * a fine-grained control of connections on a per route basis. - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @version $Revision: 651813 $ - * - * @since 4.0 - */ -public interface ConnPerRoute { - - int getMaxForRoute(HttpRoute route); - -} diff --git a/src/org/apache/http/conn/params/ConnPerRouteBean.java b/src/org/apache/http/conn/params/ConnPerRouteBean.java deleted file mode 100644 index c6a36e3..0000000 --- a/src/org/apache/http/conn/params/ConnPerRouteBean.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnPerRouteBean.java $ - * $Revision: 652947 $ - * $Date: 2008-05-02 16:15:40 -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.params; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.http.conn.routing.HttpRoute; - -/** - * This class maintains a map of HTTP routes to maximum number of connections allowed - * for those routes. This class can be used by pooling - * {@link org.apache.http.conn.ClientConnectionManager connection managers} for - * a fine-grained control of connections on a per route basis. - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * - * @version $Revision: 652947 $ - * - * @since 4.0 - */ -public final class ConnPerRouteBean implements ConnPerRoute { - - /** The default maximum number of connections allowed per host */ - public static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 2; // Per RFC 2616 sec 8.1.4 - - private final Map<HttpRoute, Integer> maxPerHostMap; - - private int defaultMax; - - public ConnPerRouteBean(int defaultMax) { - super(); - this.maxPerHostMap = new HashMap<HttpRoute, Integer>(); - setDefaultMaxPerRoute(defaultMax); - } - - public ConnPerRouteBean() { - this(DEFAULT_MAX_CONNECTIONS_PER_ROUTE); - } - - public int getDefaultMax() { - return this.defaultMax; - } - - public void setDefaultMaxPerRoute(int max) { - if (max < 1) { - throw new IllegalArgumentException - ("The maximum must be greater than 0."); - } - this.defaultMax = max; - } - - public void setMaxForRoute(final HttpRoute route, int max) { - if (route == null) { - throw new IllegalArgumentException - ("HTTP route may not be null."); - } - if (max < 1) { - throw new IllegalArgumentException - ("The maximum must be greater than 0."); - } - this.maxPerHostMap.put(route, Integer.valueOf(max)); - } - - public int getMaxForRoute(final HttpRoute route) { - if (route == null) { - throw new IllegalArgumentException - ("HTTP route may not be null."); - } - Integer max = this.maxPerHostMap.get(route); - if (max != null) { - return max.intValue(); - } else { - return this.defaultMax; - } - } - - public void setMaxForRoutes(final Map<HttpRoute, Integer> map) { - if (map == null) { - return; - } - this.maxPerHostMap.clear(); - this.maxPerHostMap.putAll(map); - } - -} diff --git a/src/org/apache/http/conn/params/ConnRoutePNames.java b/src/org/apache/http/conn/params/ConnRoutePNames.java deleted file mode 100644 index f9d42db..0000000 --- a/src/org/apache/http/conn/params/ConnRoutePNames.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnRoutePNames.java $ - * $Revision: 613656 $ - * $Date: 2008-01-20 11:06:56 -0800 (Sun, 20 Jan 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.params; - -/** - * Parameter names for routing in HttpConn. - * - * @version $Revision: 613656 $ - * - * @since 4.0 - */ -public interface ConnRoutePNames { - - /** - * Parameter for the default proxy. - * The default value will be used by some - * {@link org.apache.http.conn.routing.HttpRoutePlanner HttpRoutePlanner} - * implementations, in particular the default implementation. - * <p> - * This parameter expects a value of type {@link org.apache.http.HttpHost}. - * </p> - */ - public static final String DEFAULT_PROXY = "http.route.default-proxy"; - - - /** - * Parameter for the local address. - * On machines with multiple network interfaces, this parameter - * can be used to select the network interface from which the - * connection originates. - * It will be interpreted by the standard - * {@link org.apache.http.conn.routing.HttpRoutePlanner HttpRoutePlanner} - * implementations, in particular the default implementation. - * <p> - * This parameter expects a value of type {@link java.net.InetAddress}. - * </p> - */ - public static final String LOCAL_ADDRESS = "http.route.local-address"; - - - /** - * Parameter for an forced route. - * The forced route will be interpreted by the standard - * {@link org.apache.http.conn.routing.HttpRoutePlanner HttpRoutePlanner} - * implementations. - * Instead of computing a route, the given forced route will be - * returned, even if it points to the wrong target host. - * <p> - * This parameter expects a value of type - * {@link org.apache.http.conn.routing.HttpRoute HttpRoute}. - * </p> - */ - public static final String FORCED_ROUTE = "http.route.forced-route"; - -} - diff --git a/src/org/apache/http/conn/params/ConnRouteParamBean.java b/src/org/apache/http/conn/params/ConnRouteParamBean.java deleted file mode 100644 index 9464c02..0000000 --- a/src/org/apache/http/conn/params/ConnRouteParamBean.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnRouteParamBean.java $ - * $Revision: 652020 $ - * $Date: 2008-04-27 14:23:31 -0700 (Sun, 27 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.params; - -import java.net.InetAddress; - -import org.apache.http.HttpHost; -import org.apache.http.conn.routing.HttpRoute; -import org.apache.http.params.HttpAbstractParamBean; -import org.apache.http.params.HttpParams; - -/** - * Allows for setting parameters relating to connection routes on - * {@link HttpParams}. This class ensures that the values set on the params - * are type-safe. - */ -public class ConnRouteParamBean extends HttpAbstractParamBean { - - public ConnRouteParamBean (final HttpParams params) { - super(params); - } - - /** @see ConnRoutePNames#DEFAULT_PROXY */ - public void setDefaultProxy (final HttpHost defaultProxy) { - params.setParameter(ConnRoutePNames.DEFAULT_PROXY, defaultProxy); - } - - /** @see ConnRoutePNames#LOCAL_ADDRESS */ - public void setLocalAddress (final InetAddress address) { - params.setParameter(ConnRoutePNames.LOCAL_ADDRESS, address); - } - - /** @see ConnRoutePNames#FORCED_ROUTE */ - public void setForcedRoute (final HttpRoute route) { - params.setParameter(ConnRoutePNames.FORCED_ROUTE, route); - } - -} diff --git a/src/org/apache/http/conn/params/ConnRouteParams.java b/src/org/apache/http/conn/params/ConnRouteParams.java deleted file mode 100644 index 2fa1654..0000000 --- a/src/org/apache/http/conn/params/ConnRouteParams.java +++ /dev/null @@ -1,203 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/ConnRouteParams.java $ - * $Revision: 658785 $ - * $Date: 2008-05-21 10:47:40 -0700 (Wed, 21 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.params; - - -import java.net.InetAddress; - -import org.apache.http.HttpHost; -import org.apache.http.params.HttpParams; -import org.apache.http.conn.routing.HttpRoute; - - - -/** - * An adaptor for accessing route related parameters in {@link HttpParams}. - * See {@link ConnRoutePNames} for parameter name definitions. - * - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * @version $Revision: 658785 $ - * - * @since 4.0 - */ -public class ConnRouteParams implements ConnRoutePNames { - - /** - * A special value indicating "no host". - * This relies on a nonsense scheme name to avoid conflicts - * with actual hosts. Note that this is a <i>valid</i> host. - */ - public static final HttpHost NO_HOST = - new HttpHost("127.0.0.255", 0, "no-host"); - - /** - * A special value indicating "no route". - * This is a route with {@link #NO_HOST} as the target. - */ - public static final HttpRoute NO_ROUTE = new HttpRoute(NO_HOST); - - - /** Disabled default constructor. */ - private ConnRouteParams() { - // no body - } - - - /** - * Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} - * parameter value. - * {@link #NO_HOST} will be mapped to <code>null</code>, - * to allow unsetting in a hierarchy. - * - * @param params the parameters in which to look up - * - * @return the default proxy set in the argument parameters, or - * <code>null</code> if not set - */ - public static HttpHost getDefaultProxy(HttpParams params) { - if (params == null) { - throw new IllegalArgumentException("Parameters must not be null."); - } - HttpHost proxy = (HttpHost) - params.getParameter(DEFAULT_PROXY); - if ((proxy != null) && NO_HOST.equals(proxy)) { - // value is explicitly unset - proxy = null; - } - return proxy; - } - - - /** - * Sets the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY} - * parameter value. - * - * @param params the parameters in which to set the value - * @param proxy the value to set, may be <code>null</code>. - * Note that {@link #NO_HOST} will be mapped to - * <code>null</code> by {@link #getDefaultProxy}, - * to allow for explicit unsetting in hierarchies. - */ - public static void setDefaultProxy(HttpParams params, - HttpHost proxy) { - if (params == null) { - throw new IllegalArgumentException("Parameters must not be null."); - } - params.setParameter(DEFAULT_PROXY, proxy); - } - - - /** - * Obtains the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE} - * parameter value. - * {@link #NO_ROUTE} will be mapped to <code>null</code>, - * to allow unsetting in a hierarchy. - * - * @param params the parameters in which to look up - * - * @return the forced route set in the argument parameters, or - * <code>null</code> if not set - */ - public static HttpRoute getForcedRoute(HttpParams params) { - if (params == null) { - throw new IllegalArgumentException("Parameters must not be null."); - } - HttpRoute route = (HttpRoute) - params.getParameter(FORCED_ROUTE); - if ((route != null) && NO_ROUTE.equals(route)) { - // value is explicitly unset - route = null; - } - return route; - } - - - /** - * Sets the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE} - * parameter value. - * - * @param params the parameters in which to set the value - * @param route the value to set, may be <code>null</code>. - * Note that {@link #NO_ROUTE} will be mapped to - * <code>null</code> by {@link #getForcedRoute}, - * to allow for explicit unsetting in hierarchies. - */ - public static void setForcedRoute(HttpParams params, - HttpRoute route) { - if (params == null) { - throw new IllegalArgumentException("Parameters must not be null."); - } - params.setParameter(FORCED_ROUTE, route); - } - - - /** - * Obtains the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS} - * parameter value. - * There is no special value that would automatically be mapped to - * <code>null</code>. You can use the wildcard address (0.0.0.0 for IPv4, - * :: for IPv6) to override a specific local address in a hierarchy. - * - * @param params the parameters in which to look up - * - * @return the local address set in the argument parameters, or - * <code>null</code> if not set - */ - public static InetAddress getLocalAddress(HttpParams params) { - if (params == null) { - throw new IllegalArgumentException("Parameters must not be null."); - } - InetAddress local = (InetAddress) - params.getParameter(LOCAL_ADDRESS); - // no explicit unsetting - return local; - } - - - /** - * Sets the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS} - * parameter value. - * - * @param params the parameters in which to set the value - * @param local the value to set, may be <code>null</code> - */ - public static void setLocalAddress(HttpParams params, - InetAddress local) { - if (params == null) { - throw new IllegalArgumentException("Parameters must not be null."); - } - params.setParameter(LOCAL_ADDRESS, local); - } - -} - diff --git a/src/org/apache/http/conn/params/package.html b/src/org/apache/http/conn/params/package.html deleted file mode 100644 index 9b80420..0000000 --- a/src/org/apache/http/conn/params/package.html +++ /dev/null @@ -1,40 +0,0 @@ -<html> -<head> -<!-- -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/params/package.html $ - * $Revision: 555193 $ - * $Date: 2007-07-11 00:36:47 -0700 (Wed, 11 Jul 2007) $ - * - * ==================================================================== - * 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/>. - * - */ ---> -</head> -<body> -Parameters for configuring <i>HttpConn</i>. - -</body> -</html> diff --git a/src/org/apache/http/conn/routing/BasicRouteDirector.java b/src/org/apache/http/conn/routing/BasicRouteDirector.java deleted file mode 100644 index a3714ec..0000000 --- a/src/org/apache/http/conn/routing/BasicRouteDirector.java +++ /dev/null @@ -1,181 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/routing/BasicRouteDirector.java $ - * $Revision: 620255 $ - * $Date: 2008-02-10 02:23:55 -0800 (Sun, 10 Feb 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.routing; - - - -/** - * Basic implementation of an {@link HttpRouteDirector HttpRouteDirector}. - * This implementation is stateless and therefore thread-safe. - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 620255 $ - * - * @since 4.0 - */ -public class BasicRouteDirector implements HttpRouteDirector { - - // public default constructor - - - /** - * Provides the next step. - * - * @param plan the planned route - * @param fact the currently established route, or - * <code>null</code> if nothing is established - * - * @return one of the constants defined in this class, indicating - * either the next step to perform, or success, or failure. - * 0 is for success, a negative value for failure. - */ - public int nextStep(RouteInfo plan, RouteInfo fact) { - if (plan == null) { - throw new IllegalArgumentException - ("Planned route may not be null."); - } - - int step = UNREACHABLE; - - if ((fact == null) || (fact.getHopCount() < 1)) - step = firstStep(plan); - else if (plan.getHopCount() > 1) - step = proxiedStep(plan, fact); - else - step = directStep(plan, fact); - - return step; - - } // nextStep - - - /** - * Determines the first step to establish a route. - * - * @param plan the planned route - * - * @return the first step - */ - protected int firstStep(RouteInfo plan) { - - return (plan.getHopCount() > 1) ? - CONNECT_PROXY : CONNECT_TARGET; - } - - - /** - * Determines the next step to establish a direct connection. - * - * @param plan the planned route - * @param fact the currently established route - * - * @return one of the constants defined in this class, indicating - * either the next step to perform, or success, or failure - */ - protected int directStep(RouteInfo plan, RouteInfo fact) { - - if (fact.getHopCount() > 1) - return UNREACHABLE; - if (!plan.getTargetHost().equals(fact.getTargetHost())) - return UNREACHABLE; - // If the security is too low, we could now suggest to layer - // a secure protocol on the direct connection. Layering on direct - // connections has not been supported in HttpClient 3.x, we don't - // consider it here until there is a real-life use case for it. - - // Should we tolerate if security is better than planned? - // (plan.isSecure() && !fact.isSecure()) - if (plan.isSecure() != fact.isSecure()) - return UNREACHABLE; - - // Local address has to match only if the plan specifies one. - if ((plan.getLocalAddress() != null) && - !plan.getLocalAddress().equals(fact.getLocalAddress()) - ) - return UNREACHABLE; - - return COMPLETE; - } - - - /** - * Determines the next step to establish a connection via proxy. - * - * @param plan the planned route - * @param fact the currently established route - * - * @return one of the constants defined in this class, indicating - * either the next step to perform, or success, or failure - */ - protected int proxiedStep(RouteInfo plan, RouteInfo fact) { - - if (fact.getHopCount() <= 1) - return UNREACHABLE; - if (!plan.getTargetHost().equals(fact.getTargetHost())) - return UNREACHABLE; - final int phc = plan.getHopCount(); - final int fhc = fact.getHopCount(); - if (phc < fhc) - return UNREACHABLE; - - for (int i=0; i<fhc-1; i++) { - if (!plan.getHopTarget(i).equals(fact.getHopTarget(i))) - return UNREACHABLE; - } - // now we know that the target matches and proxies so far are the same - if (phc > fhc) - return TUNNEL_PROXY; // need to extend the proxy chain - - // proxy chain and target are the same, check tunnelling and layering - if ((fact.isTunnelled() && !plan.isTunnelled()) || - (fact.isLayered() && !plan.isLayered())) - return UNREACHABLE; - - if (plan.isTunnelled() && !fact.isTunnelled()) - return TUNNEL_TARGET; - if (plan.isLayered() && !fact.isLayered()) - return LAYER_PROTOCOL; - - // tunnel and layering are the same, remains to check the security - // Should we tolerate if security is better than planned? - // (plan.isSecure() && !fact.isSecure()) - if (plan.isSecure() != fact.isSecure()) - return UNREACHABLE; - - return COMPLETE; - } - - -} // class BasicRouteDirector diff --git a/src/org/apache/http/conn/routing/HttpRoute.java b/src/org/apache/http/conn/routing/HttpRoute.java deleted file mode 100644 index 1e870b8..0000000 --- a/src/org/apache/http/conn/routing/HttpRoute.java +++ /dev/null @@ -1,443 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/routing/HttpRoute.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 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.routing; - -import java.net.InetAddress; - -import org.apache.http.HttpHost; - -/** - * The route for a request. - * Instances of this class are unmodifiable and therefore suitable - * for use as lookup keys. - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 653041 $ - * - * @since 4.0 - */ -public final class HttpRoute implements RouteInfo, Cloneable { - - /** The target host to connect to. */ - private final HttpHost targetHost; - - /** - * The local address to connect from. - * <code>null</code> indicates that the default should be used. - */ - private final InetAddress localAddress; - - /** The proxy servers, if any. */ - private final HttpHost[] proxyChain; - - /** Whether the the route is tunnelled through the proxy. */ - private final TunnelType tunnelled; - - /** Whether the route is layered. */ - private final LayerType layered; - - /** Whether the route is (supposed to be) secure. */ - private final boolean secure; - - - /** - * Internal, fully-specified constructor. - * This constructor does <i>not</i> clone the proxy chain array, - * nor test it for <code>null</code> elements. This conversion and - * check is the responsibility of the public constructors. - * The order of arguments here is different from the similar public - * constructor, as required by Java. - * - * @param local the local address to route from, or - * <code>null</code> for the default - * @param target the host to which to route - * @param proxies the proxy chain to use, or - * <code>null</code> for a direct route - * @param secure <code>true</code> if the route is (to be) secure, - * <code>false</code> otherwise - * @param tunnelled the tunnel type of this route, or - * <code>null</code> for PLAIN - * @param layered the layering type of this route, or - * <code>null</code> for PLAIN - */ - private HttpRoute(InetAddress local, - HttpHost target, HttpHost[] proxies, - boolean secure, - TunnelType tunnelled, LayerType layered) { - if (target == null) { - throw new IllegalArgumentException - ("Target host may not be null."); - } - if ((tunnelled == TunnelType.TUNNELLED) && (proxies == null)) { - throw new IllegalArgumentException - ("Proxy required if tunnelled."); - } - - // tunnelled is already checked above, that is in line with the default - if (tunnelled == null) - tunnelled = TunnelType.PLAIN; - if (layered == null) - layered = LayerType.PLAIN; - - this.targetHost = target; - this.localAddress = local; - this.proxyChain = proxies; - this.secure = secure; - this.tunnelled = tunnelled; - this.layered = layered; - } - - - /** - * Creates a new route with all attributes specified explicitly. - * - * @param target the host to which to route - * @param local the local address to route from, or - * <code>null</code> for the default - * @param proxies the proxy chain to use, or - * <code>null</code> for a direct route - * @param secure <code>true</code> if the route is (to be) secure, - * <code>false</code> otherwise - * @param tunnelled the tunnel type of this route - * @param layered the layering type of this route - */ - public HttpRoute(HttpHost target, InetAddress local, HttpHost[] proxies, - boolean secure, TunnelType tunnelled, LayerType layered) { - this(local, target, toChain(proxies), secure, tunnelled, layered); - } - - - /** - * Creates a new route with at most one proxy. - * - * @param target the host to which to route - * @param local the local address to route from, or - * <code>null</code> for the default - * @param proxy the proxy to use, or - * <code>null</code> for a direct route - * @param secure <code>true</code> if the route is (to be) secure, - * <code>false</code> otherwise - * @param tunnelled <code>true</code> if the route is (to be) tunnelled - * via the proxy, - * <code>false</code> otherwise - * @param layered <code>true</code> if the route includes a - * layered protocol, - * <code>false</code> otherwise - */ - public HttpRoute(HttpHost target, InetAddress local, HttpHost proxy, - boolean secure, TunnelType tunnelled, LayerType layered) { - this(local, target, toChain(proxy), secure, tunnelled, layered); - } - - - /** - * Creates a new direct route. - * That is a route without a proxy. - * - * @param target the host to which to route - * @param local the local address to route from, or - * <code>null</code> for the default - * @param secure <code>true</code> if the route is (to be) secure, - * <code>false</code> otherwise - */ - public HttpRoute(HttpHost target, InetAddress local, boolean secure) { - this(local, target, null, secure, TunnelType.PLAIN, LayerType.PLAIN); - } - - - /** - * Creates a new direct insecure route. - * - * @param target the host to which to route - */ - public HttpRoute(HttpHost target) { - this(null, target, null, false, TunnelType.PLAIN, LayerType.PLAIN); - } - - - /** - * Creates a new route through a proxy. - * When using this constructor, the <code>proxy</code> MUST be given. - * For convenience, it is assumed that a secure connection will be - * layered over a tunnel through the proxy. - * - * @param target the host to which to route - * @param local the local address to route from, or - * <code>null</code> for the default - * @param proxy the proxy to use - * @param secure <code>true</code> if the route is (to be) secure, - * <code>false</code> otherwise - */ - public HttpRoute(HttpHost target, InetAddress local, HttpHost proxy, - boolean secure) { - this(local, target, toChain(proxy), secure, - secure ? TunnelType.TUNNELLED : TunnelType.PLAIN, - secure ? LayerType.LAYERED : LayerType.PLAIN); - if (proxy == null) { - throw new IllegalArgumentException - ("Proxy host may not be null."); - } - } - - - /** - * Helper to convert a proxy to a proxy chain. - * - * @param proxy the only proxy in the chain, or <code>null</code> - * - * @return a proxy chain array, or <code>null</code> - */ - private static HttpHost[] toChain(HttpHost proxy) { - if (proxy == null) - return null; - - return new HttpHost[]{ proxy }; - } - - - /** - * Helper to duplicate and check a proxy chain. - * An empty proxy chain is converted to <code>null</code>. - * - * @param proxies the proxy chain to duplicate, or <code>null</code> - * - * @return a new proxy chain array, or <code>null</code> - */ - private static HttpHost[] toChain(HttpHost[] proxies) { - if ((proxies == null) || (proxies.length < 1)) - return null; - - for (HttpHost proxy : proxies) { - if (proxy == null) - throw new IllegalArgumentException - ("Proxy chain may not contain null elements."); - } - - // copy the proxy chain, the traditional way - HttpHost[] result = new HttpHost[proxies.length]; - System.arraycopy(proxies, 0, result, 0, proxies.length); - - return result; - } - - - - // non-JavaDoc, see interface RouteInfo - public final HttpHost getTargetHost() { - return this.targetHost; - } - - - // non-JavaDoc, see interface RouteInfo - public final InetAddress getLocalAddress() { - return this.localAddress; - } - - - // non-JavaDoc, see interface RouteInfo - public final int getHopCount() { - return (proxyChain == null) ? 1 : (proxyChain.length+1); - } - - - // non-JavaDoc, see interface RouteInfo - public final HttpHost getHopTarget(int hop) { - if (hop < 0) - throw new IllegalArgumentException - ("Hop index must not be negative: " + hop); - final int hopcount = getHopCount(); - if (hop >= hopcount) - throw new IllegalArgumentException - ("Hop index " + hop + - " exceeds route length " + hopcount); - - HttpHost result = null; - if (hop < hopcount-1) - result = this.proxyChain[hop]; - else - result = this.targetHost; - - return result; - } - - - // non-JavaDoc, see interface RouteInfo - public final HttpHost getProxyHost() { - return (this.proxyChain == null) ? null : this.proxyChain[0]; - } - - - // non-JavaDoc, see interface RouteInfo - public final TunnelType getTunnelType() { - return this.tunnelled; - } - - - // non-JavaDoc, see interface RouteInfo - public final boolean isTunnelled() { - return (this.tunnelled == TunnelType.TUNNELLED); - } - - - // non-JavaDoc, see interface RouteInfo - public final LayerType getLayerType() { - return this.layered; - } - - - // non-JavaDoc, see interface RouteInfo - public final boolean isLayered() { - return (this.layered == LayerType.LAYERED); - } - - - // non-JavaDoc, see interface RouteInfo - public final boolean isSecure() { - return this.secure; - } - - - /** - * Compares this route to another. - * - * @param o the object to compare with - * - * @return <code>true</code> if the argument is the same route, - * <code>false</code> - */ - @Override - public final boolean equals(Object o) { - if (o == this) - return true; - if (!(o instanceof HttpRoute)) - return false; - - HttpRoute that = (HttpRoute) o; - boolean equal = this.targetHost.equals(that.targetHost); - equal &= - ( this.localAddress == that.localAddress) || - ((this.localAddress != null) && - this.localAddress.equals(that.localAddress)); - equal &= - ( this.proxyChain == that.proxyChain) || - ((this.proxyChain != null) && - (that.proxyChain != null) && - (this.proxyChain.length == that.proxyChain.length)); - // comparison of actual proxies follows below - equal &= - (this.secure == that.secure) && - (this.tunnelled == that.tunnelled) && - (this.layered == that.layered); - - // chain length has been compared above, now check the proxies - if (equal && (this.proxyChain != null)) { - for (int i=0; equal && (i<this.proxyChain.length); i++) - equal = this.proxyChain[i].equals(that.proxyChain[i]); - } - - return equal; - } - - - /** - * Generates a hash code for this route. - * - * @return the hash code - */ - @Override - public final int hashCode() { - - int hc = this.targetHost.hashCode(); - - if (this.localAddress != null) - hc ^= localAddress.hashCode(); - if (this.proxyChain != null) { - hc ^= proxyChain.length; - for (HttpHost aProxyChain : proxyChain) hc ^= aProxyChain.hashCode(); - } - - if (this.secure) - hc ^= 0x11111111; - - hc ^= this.tunnelled.hashCode(); - hc ^= this.layered.hashCode(); - - return hc; - } - - - /** - * Obtains a description of this route. - * - * @return a human-readable representation of this route - */ - @Override - public final String toString() { - StringBuilder cab = new StringBuilder(50 + getHopCount()*30); - - cab.append("HttpRoute["); - if (this.localAddress != null) { - cab.append(this.localAddress); - cab.append("->"); - } - cab.append('{'); - if (this.tunnelled == TunnelType.TUNNELLED) - cab.append('t'); - if (this.layered == LayerType.LAYERED) - cab.append('l'); - if (this.secure) - cab.append('s'); - cab.append("}->"); - if (this.proxyChain != null) { - for (HttpHost aProxyChain : this.proxyChain) { - cab.append(aProxyChain); - cab.append("->"); - } - } - cab.append(this.targetHost); - cab.append(']'); - - return cab.toString(); - } - - - // default implementation of clone() is sufficient - @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - -} // class HttpRoute diff --git a/src/org/apache/http/conn/routing/HttpRouteDirector.java b/src/org/apache/http/conn/routing/HttpRouteDirector.java deleted file mode 100644 index 8cfcf67..0000000 --- a/src/org/apache/http/conn/routing/HttpRouteDirector.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/routing/HttpRouteDirector.java $ - * $Revision: 620255 $ - * $Date: 2008-02-10 02:23:55 -0800 (Sun, 10 Feb 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.routing; - - - -/** - * Provides directions on establishing a route. - * Implementations of this interface compare a planned route with - * a tracked route and indicate the next step required. - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 620255 $ - * - * @since 4.0 - */ -public interface HttpRouteDirector { - - /** Indicates that the route can not be established at all. */ - public final static int UNREACHABLE = -1; - - /** Indicates that the route is complete. */ - public final static int COMPLETE = 0; - - /** Step: open connection to target. */ - public final static int CONNECT_TARGET = 1; - - /** Step: open connection to proxy. */ - public final static int CONNECT_PROXY = 2; - - /** Step: tunnel through proxy to target. */ - public final static int TUNNEL_TARGET = 3; - - /** Step: tunnel through proxy to other proxy. */ - public final static int TUNNEL_PROXY = 4; - - /** Step: layer protocol (over tunnel). */ - public final static int LAYER_PROTOCOL = 5; - - - /** - * Provides the next step. - * - * @param plan the planned route - * @param fact the currently established route, or - * <code>null</code> if nothing is established - * - * @return one of the constants defined in this interface, indicating - * either the next step to perform, or success, or failure. - * 0 is for success, a negative value for failure. - */ - public int nextStep(RouteInfo plan, RouteInfo fact) - ; - - -} // interface HttpRouteDirector diff --git a/src/org/apache/http/conn/routing/HttpRoutePlanner.java b/src/org/apache/http/conn/routing/HttpRoutePlanner.java deleted file mode 100644 index 489702a..0000000 --- a/src/org/apache/http/conn/routing/HttpRoutePlanner.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/routing/HttpRoutePlanner.java $ - * $Revision: 613654 $ - * $Date: 2008-01-20 11:00:19 -0800 (Sun, 20 Jan 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.routing; - -import org.apache.http.HttpException; -import org.apache.http.HttpHost; -import org.apache.http.HttpRequest; -import org.apache.http.protocol.HttpContext; - - - -/** - * Encapsulates logic to compute a {@link HttpRoute} to a target host. - * Implementations may for example be based on parameters, or on the - * standard Java system properties. - */ -public interface HttpRoutePlanner { - - /** - * Determines the route for a request. - * - * @param target the target host for the request. - * Implementations may accept <code>null</code> - * if they can still determine a route, for example - * to a default target or by inspecting the request. - * @param request the request to execute - * @param context the context to use for the subsequent execution. - * Implementations may accept <code>null</code>. - * - * @return the route that the request should take - * - * @throws HttpException in case of a problem - */ - public HttpRoute determineRoute(HttpHost target, - HttpRequest request, - HttpContext context) - throws HttpException - ; - -} diff --git a/src/org/apache/http/conn/routing/RouteInfo.java b/src/org/apache/http/conn/routing/RouteInfo.java deleted file mode 100644 index 3449cb1..0000000 --- a/src/org/apache/http/conn/routing/RouteInfo.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/routing/RouteInfo.java $ - * $Revision: 652200 $ - * $Date: 2008-04-29 17:22:43 -0700 (Tue, 29 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.routing; - -import java.net.InetAddress; - -import org.apache.http.HttpHost; - - -/** - * Read-only interface for route information. - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 652200 $ - * - * @since 4.0 - */ -public interface RouteInfo { - - /** - * The tunnelling type of a route. - * Plain routes are established by connecting to the target or - * the first proxy. - * Tunnelled routes are established by connecting to the first proxy - * and tunnelling through all proxies to the target. - * Routes without a proxy cannot be tunnelled. - */ - public enum TunnelType { PLAIN, TUNNELLED } - - /** - * The layering type of a route. - * Plain routes are established by connecting or tunnelling. - * Layered routes are established by layering a protocol such as TLS/SSL - * over an existing connection. - * Protocols can only be layered over a tunnel to the target, or - * or over a direct connection without proxies. - * <br/> - * Layering a protocol - * over a direct connection makes little sense, since the connection - * could be established with the new protocol in the first place. - * But we don't want to exclude that use case. - */ - public enum LayerType { PLAIN, LAYERED } - - - - /** - * Obtains the target host. - * - * @return the target host - */ - HttpHost getTargetHost() - ; - - - /** - * Obtains the local address to connect from. - * - * @return the local address, - * or <code>null</code> - */ - InetAddress getLocalAddress() - ; - - - /** - * Obtains the number of hops in this route. - * A direct route has one hop. A route through a proxy has two hops. - * A route through a chain of <i>n</i> proxies has <i>n+1</i> hops. - * - * @return the number of hops in this route - */ - int getHopCount() - ; - - - /** - * Obtains the target of a hop in this route. - * The target of the last hop is the {@link #getTargetHost target host}, - * the target of previous hops is the respective proxy in the chain. - * For a route through exactly one proxy, target of hop 0 is the proxy - * and target of hop 1 is the target host. - * - * @param hop index of the hop for which to get the target, - * 0 for first - * - * @return the target of the given hop - * - * @throws IllegalArgumentException - * if the argument is negative or not less than - * {@link #getHopCount getHopCount()} - */ - HttpHost getHopTarget(int hop) - ; - - - /** - * Obtains the first proxy host. - * - * @return the first proxy in the proxy chain, or - * <code>null</code> if this route is direct - */ - HttpHost getProxyHost() - ; - - - /** - * Obtains the tunnel type of this route. - * If there is a proxy chain, only end-to-end tunnels are considered. - * - * @return the tunnelling type - */ - TunnelType getTunnelType() - ; - - - /** - * Checks whether this route is tunnelled through a proxy. - * If there is a proxy chain, only end-to-end tunnels are considered. - * - * @return <code>true</code> if tunnelled end-to-end through at least - * one proxy, - * <code>false</code> otherwise - */ - boolean isTunnelled() - ; - - - /** - * Obtains the layering type of this route. - * In the presence of proxies, only layering over an end-to-end tunnel - * is considered. - * - * @return the layering type - */ - LayerType getLayerType() - ; - - - /** - * Checks whether this route includes a layered protocol. - * In the presence of proxies, only layering over an end-to-end tunnel - * is considered. - * - * @return <code>true</code> if layered, - * <code>false</code> otherwise - */ - boolean isLayered() - ; - - - /** - * Checks whether this route is secure. - * - * @return <code>true</code> if secure, - * <code>false</code> otherwise - */ - boolean isSecure() - ; - - -} // interface RouteInfo diff --git a/src/org/apache/http/conn/routing/RouteTracker.java b/src/org/apache/http/conn/routing/RouteTracker.java deleted file mode 100644 index ba8213e..0000000 --- a/src/org/apache/http/conn/routing/RouteTracker.java +++ /dev/null @@ -1,439 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/routing/RouteTracker.java $ - * $Revision: 620254 $ - * $Date: 2008-02-10 02:18:48 -0800 (Sun, 10 Feb 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.routing; - -import java.net.InetAddress; - -import org.apache.http.HttpHost; - - -/** - * Helps tracking the steps in establishing a route. - * - * @author <a href="mailto:rolandw at apache.org">Roland Weber</a> - * - * - * <!-- empty lines to avoid svn diff problems --> - * @version $Revision: 620254 $ - * - * @since 4.0 - */ -public final class RouteTracker implements RouteInfo, Cloneable { - - /** The target host to connect to. */ - private final HttpHost targetHost; - - /** - * The local address to connect from. - * <code>null</code> indicates that the default should be used. - */ - private final InetAddress localAddress; - - // the attributes above are fixed at construction time - // now follow attributes that indicate the established route - - /** Whether the first hop of the route is established. */ - private boolean connected; - - /** The proxy chain, if any. */ - private HttpHost[] proxyChain; - - /** Whether the the route is tunnelled end-to-end through proxies. */ - private TunnelType tunnelled; - - /** Whether the route is layered over a tunnel. */ - private LayerType layered; - - /** Whether the route is secure. */ - private boolean secure; - - - /** - * Creates a new route tracker. - * The target and origin need to be specified at creation time. - * - * @param target the host to which to route - * @param local the local address to route from, or - * <code>null</code> for the default - */ - public RouteTracker(HttpHost target, InetAddress local) { - if (target == null) { - throw new IllegalArgumentException("Target host may not be null."); - } - this.targetHost = target; - this.localAddress = local; - this.tunnelled = TunnelType.PLAIN; - this.layered = LayerType.PLAIN; - } - - - /** - * Creates a new tracker for the given route. - * Only target and origin are taken from the route, - * everything else remains to be tracked. - * - * @param route the route to track - */ - public RouteTracker(HttpRoute route) { - this(route.getTargetHost(), route.getLocalAddress()); - } - - - /** - * Tracks connecting to the target. - * - * @param secure <code>true</code> if the route is secure, - * <code>false</code> otherwise - */ - public final void connectTarget(boolean secure) { - if (this.connected) { - throw new IllegalStateException("Already connected."); - } - this.connected = true; - this.secure = secure; - } - - - /** - * Tracks connecting to the first proxy. - * - * @param proxy the proxy connected to - * @param secure <code>true</code> if the route is secure, - * <code>false</code> otherwise - */ - public final void connectProxy(HttpHost proxy, boolean secure) { - if (proxy == null) { - throw new IllegalArgumentException("Proxy host may not be null."); - } - if (this.connected) { - throw new IllegalStateException("Already connected."); - } - this.connected = true; - this.proxyChain = new HttpHost[]{ proxy }; - this.secure = secure; - } - - - /** - * Tracks tunnelling to the target. - * - * @param secure <code>true</code> if the route is secure, - * <code>false</code> otherwise - */ - public final void tunnelTarget(boolean secure) { - if (!this.connected) { - throw new IllegalStateException("No tunnel unless connected."); - } - if (this.proxyChain == null) { - throw new IllegalStateException("No tunnel without proxy."); - } - this.tunnelled = TunnelType.TUNNELLED; - this.secure = secure; - } - - - /** - * Tracks tunnelling to a proxy in a proxy chain. - * This will extend the tracked proxy chain, but it does not mark - * the route as tunnelled. Only end-to-end tunnels are considered there. - * - * @param proxy the proxy tunnelled to - * @param secure <code>true</code> if the route is secure, - * <code>false</code> otherwise - */ - public final void tunnelProxy(HttpHost proxy, boolean secure) { - if (proxy == null) { - throw new IllegalArgumentException("Proxy host may not be null."); - } - if (!this.connected) { - throw new IllegalStateException("No tunnel unless connected."); - } - if (this.proxyChain == null) { - throw new IllegalStateException("No proxy tunnel without proxy."); - } - - // prepare an extended proxy chain - HttpHost[] proxies = new HttpHost[this.proxyChain.length+1]; - System.arraycopy(this.proxyChain, 0, - proxies, 0, this.proxyChain.length); - proxies[proxies.length-1] = proxy; - - this.proxyChain = proxies; - this.secure = secure; - } - - - /** - * Tracks layering a protocol. - * - * @param secure <code>true</code> if the route is secure, - * <code>false</code> otherwise - */ - public final void layerProtocol(boolean secure) { - // it is possible to layer a protocol over a direct connection, - // although this case is probably not considered elsewhere - if (!this.connected) { - throw new IllegalStateException - ("No layered protocol unless connected."); - } - this.layered = LayerType.LAYERED; - this.secure = secure; - } - - - - // non-JavaDoc, see interface RouteInfo - public final HttpHost getTargetHost() { - return this.targetHost; - } - - - // non-JavaDoc, see interface RouteInfo - public final InetAddress getLocalAddress() { - return this.localAddress; - } - - - // non-JavaDoc, see interface RouteInfo - public final int getHopCount() { - int hops = 0; - if (this.connected) { - if (proxyChain == null) - hops = 1; - else - hops = proxyChain.length + 1; - } - return hops; - } - - - // non-JavaDoc, see interface RouteInfo - public final HttpHost getHopTarget(int hop) { - if (hop < 0) - throw new IllegalArgumentException - ("Hop index must not be negative: " + hop); - final int hopcount = getHopCount(); - if (hop >= hopcount) { - throw new IllegalArgumentException - ("Hop index " + hop + - " exceeds tracked route length " + hopcount +"."); - } - - HttpHost result = null; - if (hop < hopcount-1) - result = this.proxyChain[hop]; - else - result = this.targetHost; - - return result; - } - - - // non-JavaDoc, see interface RouteInfo - public final HttpHost getProxyHost() { - return (this.proxyChain == null) ? null : this.proxyChain[0]; - } - - - // non-JavaDoc, see interface RouteInfo - public final boolean isConnected() { - return this.connected; - } - - - // non-JavaDoc, see interface RouteInfo - public final TunnelType getTunnelType() { - return this.tunnelled; - } - - - // non-JavaDoc, see interface RouteInfo - public final boolean isTunnelled() { - return (this.tunnelled == TunnelType.TUNNELLED); - } - - - // non-JavaDoc, see interface RouteInfo - public final LayerType getLayerType() { - return this.layered; - } - - - // non-JavaDoc, see interface RouteInfo - public final boolean isLayered() { - return (this.layered == LayerType.LAYERED); - } - - - // non-JavaDoc, see interface RouteInfo - public final boolean isSecure() { - return this.secure; - } - - - /** - * Obtains the tracked route. - * If a route has been tracked, it is {@link #isConnected connected}. - * If not connected, nothing has been tracked so far. - * - * @return the tracked route, or - * <code>null</code> if nothing has been tracked so far - */ - public final HttpRoute toRoute() { - return !this.connected ? - null : new HttpRoute(this.targetHost, this.localAddress, - this.proxyChain, this.secure, - this.tunnelled, this.layered); - } - - - /** - * Compares this tracked route to another. - * - * @param o the object to compare with - * - * @return <code>true</code> if the argument is the same tracked route, - * <code>false</code> - */ - @Override - public final boolean equals(Object o) { - if (o == this) - return true; - if (!(o instanceof RouteTracker)) - return false; - - RouteTracker that = (RouteTracker) o; - boolean equal = this.targetHost.equals(that.targetHost); - equal &= - ( this.localAddress == that.localAddress) || - ((this.localAddress != null) && - this.localAddress.equals(that.localAddress)); - equal &= - ( this.proxyChain == that.proxyChain) || - ((this.proxyChain != null) && - (that.proxyChain != null) && - (this.proxyChain.length == that.proxyChain.length)); - // comparison of actual proxies follows below - equal &= - (this.connected == that.connected) && - (this.secure == that.secure) && - (this.tunnelled == that.tunnelled) && - (this.layered == that.layered); - - // chain length has been compared above, now check the proxies - if (equal && (this.proxyChain != null)) { - for (int i=0; equal && (i<this.proxyChain.length); i++) - equal = this.proxyChain[i].equals(that.proxyChain[i]); - } - - return equal; - } - - - /** - * Generates a hash code for this tracked route. - * Route trackers are modifiable and should therefore not be used - * as lookup keys. Use {@link #toRoute toRoute} to obtain an - * unmodifiable representation of the tracked route. - * - * @return the hash code - */ - @Override - public final int hashCode() { - - int hc = this.targetHost.hashCode(); - - if (this.localAddress != null) - hc ^= localAddress.hashCode(); - if (this.proxyChain != null) { - hc ^= proxyChain.length; - for (int i=0; i<proxyChain.length; i++) - hc ^= proxyChain[i].hashCode(); - } - - if (this.connected) - hc ^= 0x11111111; - if (this.secure) - hc ^= 0x22222222; - - hc ^= this.tunnelled.hashCode(); - hc ^= this.layered.hashCode(); - - return hc; - } - - - /** - * Obtains a description of the tracked route. - * - * @return a human-readable representation of the tracked route - */ - @Override - public final String toString() { - StringBuilder cab = new StringBuilder(50 + getHopCount()*30); - - cab.append("RouteTracker["); - if (this.localAddress != null) { - cab.append(this.localAddress); - cab.append("->"); - } - cab.append('{'); - if (this.connected) - cab.append('c'); - if (this.tunnelled == TunnelType.TUNNELLED) - cab.append('t'); - if (this.layered == LayerType.LAYERED) - cab.append('l'); - if (this.secure) - cab.append('s'); - cab.append("}->"); - if (this.proxyChain != null) { - for (int i=0; i<this.proxyChain.length; i++) { - cab.append(this.proxyChain[i]); - cab.append("->"); - } - } - cab.append(this.targetHost); - cab.append(']'); - - return cab.toString(); - } - - - // default implementation of clone() is sufficient - @Override - public Object clone() throws CloneNotSupportedException { - return super.clone(); - } - - -} // class RouteTracker diff --git a/src/org/apache/http/conn/routing/package.html b/src/org/apache/http/conn/routing/package.html deleted file mode 100644 index b50f97c..0000000 --- a/src/org/apache/http/conn/routing/package.html +++ /dev/null @@ -1,62 +0,0 @@ -<html> -<head> -<!-- -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/routing/package.html $ - * $Revision: 613656 $ - * $Date: 2008-01-20 11:06:56 -0800 (Sun, 20 Jan 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/>. - * - */ ---> -</head> -<body> -The client-side route representation and tracking API, part of <i>HttpConn</i>. - -<p> -An {@link org.apache.http.conn.routing.HttpRoute HttpRoute} -is the path along which a request has to be sent to the server. -The route starts at a local network address and may pass -through one or more proxies before reaching the target. -Routes through proxies can be tunnelled, and a layered protocol (TLS/SSL) -might be put on top of the tunnel. -The {@link org.apache.http.conn.routing.RouteTracker RouteTracker} -helps in tracking the steps for establishing a route, while an -{@link org.apache.http.conn.routing.HttpRouteDirector HttpRouteDirector} -determines the next step to take. -</p> - - -<p> -The {@link org.apache.http.conn.routing.HttpRoutePlanner HttpRoutePlanner} -is responsible for determining a route to a given target host. -Implementations must know about proxies to use, and about exemptions -for hosts that should be contacted directly without a proxy. -</p> - - -</body> -</html> 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 - ; - -} diff --git a/src/org/apache/http/conn/ssl/AbstractVerifier.java b/src/org/apache/http/conn/ssl/AbstractVerifier.java deleted file mode 100644 index 5195e58..0000000 --- a/src/org/apache/http/conn/ssl/AbstractVerifier.java +++ /dev/null @@ -1,343 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/AbstractVerifier.java $ - * $Revision: 653041 $ - * $Date: 2008-05-03 03:39:28 -0700 (Sat, 03 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.ssl; - -import org.apache.http.conn.util.InetAddressUtils; - -import java.io.IOException; -import java.io.InputStream; -import java.security.cert.Certificate; -import java.security.cert.CertificateParsingException; -import java.security.cert.X509Certificate; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.StringTokenizer; -import java.util.logging.Logger; -import java.util.logging.Level; - -import javax.net.ssl.SSLException; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocket; - -/** - * Abstract base class for all standard {@link X509HostnameVerifier} - * implementations. - * - * @author Julius Davies - */ -public abstract class AbstractVerifier implements X509HostnameVerifier { - - /** - * This contains a list of 2nd-level domains that aren't allowed to - * have wildcards when combined with country-codes. - * For example: [*.co.uk]. - * <p/> - * The [*.co.uk] problem is an interesting one. Should we just hope - * that CA's would never foolishly allow such a certificate to happen? - * Looks like we're the only implementation guarding against this. - * Firefox, Curl, Sun Java 1.4, 5, 6 don't bother with this check. - */ - private final static String[] BAD_COUNTRY_2LDS = - { "ac", "co", "com", "ed", "edu", "go", "gouv", "gov", "info", - "lg", "ne", "net", "or", "org" }; - - static { - // Just in case developer forgot to manually sort the array. :-) - Arrays.sort(BAD_COUNTRY_2LDS); - } - - public AbstractVerifier() { - super(); - } - - public final void verify(String host, SSLSocket ssl) - throws IOException { - if(host == null) { - throw new NullPointerException("host to verify is null"); - } - - ssl.startHandshake(); - SSLSession session = ssl.getSession(); - if(session == null) { - // In our experience this only happens under IBM 1.4.x when - // spurious (unrelated) certificates show up in the server' - // chain. Hopefully this will unearth the real problem: - InputStream in = ssl.getInputStream(); - in.available(); - /* - If you're looking at the 2 lines of code above because - you're running into a problem, you probably have two - options: - - #1. Clean up the certificate chain that your server - is presenting (e.g. edit "/etc/apache2/server.crt" - or wherever it is your server's certificate chain - is defined). - - OR - - #2. Upgrade to an IBM 1.5.x or greater JVM, or switch - to a non-IBM JVM. - */ - - // If ssl.getInputStream().available() didn't cause an - // exception, maybe at least now the session is available? - session = ssl.getSession(); - if(session == null) { - // If it's still null, probably a startHandshake() will - // unearth the real problem. - ssl.startHandshake(); - - // Okay, if we still haven't managed to cause an exception, - // might as well go for the NPE. Or maybe we're okay now? - session = ssl.getSession(); - } - } - - Certificate[] certs = session.getPeerCertificates(); - X509Certificate x509 = (X509Certificate) certs[0]; - verify(host, x509); - } - - public final boolean verify(String host, SSLSession session) { - try { - Certificate[] certs = session.getPeerCertificates(); - X509Certificate x509 = (X509Certificate) certs[0]; - verify(host, x509); - return true; - } - catch(SSLException e) { - return false; - } - } - - public final void verify(String host, X509Certificate cert) - throws SSLException { - String[] cns = getCNs(cert); - String[] subjectAlts = getDNSSubjectAlts(cert); - verify(host, cns, subjectAlts); - } - - public final void verify(final String host, final String[] cns, - final String[] subjectAlts, - final boolean strictWithSubDomains) - throws SSLException { - - // Build the list of names we're going to check. Our DEFAULT and - // STRICT implementations of the HostnameVerifier only use the - // first CN provided. All other CNs are ignored. - // (Firefox, wget, curl, Sun Java 1.4, 5, 6 all work this way). - LinkedList<String> names = new LinkedList<String>(); - if(cns != null && cns.length > 0 && cns[0] != null) { - names.add(cns[0]); - } - if(subjectAlts != null) { - for (String subjectAlt : subjectAlts) { - if (subjectAlt != null) { - names.add(subjectAlt); - } - } - } - - if(names.isEmpty()) { - String msg = "Certificate for <" + host + "> doesn't contain CN or DNS subjectAlt"; - throw new SSLException(msg); - } - - // StringBuffer for building the error message. - StringBuffer buf = new StringBuffer(); - - // We're can be case-insensitive when comparing the host we used to - // establish the socket to the hostname in the certificate. - String hostName = host.trim().toLowerCase(Locale.ENGLISH); - boolean match = false; - for(Iterator<String> it = names.iterator(); it.hasNext();) { - // Don't trim the CN, though! - String cn = it.next(); - cn = cn.toLowerCase(Locale.ENGLISH); - // Store CN in StringBuffer in case we need to report an error. - buf.append(" <"); - buf.append(cn); - buf.append('>'); - if(it.hasNext()) { - buf.append(" OR"); - } - - // The CN better have at least two dots if it wants wildcard - // action. It also can't be [*.co.uk] or [*.co.jp] or - // [*.org.uk], etc... - boolean doWildcard = cn.startsWith("*.") && - cn.lastIndexOf('.') >= 0 && - acceptableCountryWildcard(cn) && - !InetAddressUtils.isIPv4Address(host); - - if(doWildcard) { - match = hostName.endsWith(cn.substring(1)); - if(match && strictWithSubDomains) { - // If we're in strict mode, then [*.foo.com] is not - // allowed to match [a.b.foo.com] - match = countDots(hostName) == countDots(cn); - } - } else { - match = hostName.equals(cn); - } - if(match) { - break; - } - } - if(!match) { - throw new SSLException("hostname in certificate didn't match: <" + host + "> !=" + buf); - } - } - - public static boolean acceptableCountryWildcard(String cn) { - int cnLen = cn.length(); - if(cnLen >= 7 && cnLen <= 9) { - // Look for the '.' in the 3rd-last position: - if(cn.charAt(cnLen - 3) == '.') { - // Trim off the [*.] and the [.XX]. - String s = cn.substring(2, cnLen - 3); - // And test against the sorted array of bad 2lds: - int x = Arrays.binarySearch(BAD_COUNTRY_2LDS, s); - return x < 0; - } - } - return true; - } - - public static String[] getCNs(X509Certificate cert) { - LinkedList<String> cnList = new LinkedList<String>(); - /* - Sebastian Hauer's original StrictSSLProtocolSocketFactory used - getName() and had the following comment: - - Parses a X.500 distinguished name for the value of the - "Common Name" field. This is done a bit sloppy right - now and should probably be done a bit more according to - <code>RFC 2253</code>. - - I've noticed that toString() seems to do a better job than - getName() on these X500Principal objects, so I'm hoping that - addresses Sebastian's concern. - - For example, getName() gives me this: - 1.2.840.113549.1.9.1=#16166a756c6975736461766965734063756362632e636f6d - - whereas toString() gives me this: - EMAILADDRESS=juliusdavies@cucbc.com - - Looks like toString() even works with non-ascii domain names! - I tested it with "花子.co.jp" and it worked fine. - */ - String subjectPrincipal = cert.getSubjectX500Principal().toString(); - StringTokenizer st = new StringTokenizer(subjectPrincipal, ","); - while(st.hasMoreTokens()) { - String tok = st.nextToken(); - int x = tok.indexOf("CN="); - if(x >= 0) { - cnList.add(tok.substring(x + 3)); - } - } - if(!cnList.isEmpty()) { - String[] cns = new String[cnList.size()]; - cnList.toArray(cns); - return cns; - } else { - return null; - } - } - - - /** - * Extracts the array of SubjectAlt DNS names from an X509Certificate. - * Returns null if there aren't any. - * <p/> - * Note: Java doesn't appear able to extract international characters - * from the SubjectAlts. It can only extract international characters - * from the CN field. - * <p/> - * (Or maybe the version of OpenSSL I'm using to test isn't storing the - * international characters correctly in the SubjectAlts?). - * - * @param cert X509Certificate - * @return Array of SubjectALT DNS names stored in the certificate. - */ - public static String[] getDNSSubjectAlts(X509Certificate cert) { - LinkedList<String> subjectAltList = new LinkedList<String>(); - Collection<List<?>> c = null; - try { - c = cert.getSubjectAlternativeNames(); - } - catch(CertificateParsingException cpe) { - Logger.getLogger(AbstractVerifier.class.getName()) - .log(Level.FINE, "Error parsing certificate.", cpe); - } - if(c != null) { - for (List<?> aC : c) { - List<?> list = aC; - int type = ((Integer) list.get(0)).intValue(); - // If type is 2, then we've got a dNSName - if (type == 2) { - String s = (String) list.get(1); - subjectAltList.add(s); - } - } - } - if(!subjectAltList.isEmpty()) { - String[] subjectAlts = new String[subjectAltList.size()]; - subjectAltList.toArray(subjectAlts); - return subjectAlts; - } else { - return null; - } - } - - /** - * Counts the number of dots "." in a string. - * @param s string to count dots from - * @return number of dots - */ - public static int countDots(final String s) { - int count = 0; - for(int i = 0; i < s.length(); i++) { - if(s.charAt(i) == '.') { - count++; - } - } - return count; - } - -} diff --git a/src/org/apache/http/conn/ssl/AllowAllHostnameVerifier.java b/src/org/apache/http/conn/ssl/AllowAllHostnameVerifier.java deleted file mode 100644 index 05828fb..0000000 --- a/src/org/apache/http/conn/ssl/AllowAllHostnameVerifier.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/AllowAllHostnameVerifier.java $ - * $Revision: 617642 $ - * $Date: 2008-02-01 12:54:07 -0800 (Fri, 01 Feb 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.ssl; - -/** - * The ALLOW_ALL HostnameVerifier essentially turns hostname verification - * off. This implementation is a no-op, and never throws the SSLException. - * - * @author Julius Davies - */ -public class AllowAllHostnameVerifier extends AbstractVerifier { - - public final void verify( - final String host, - final String[] cns, - final String[] subjectAlts) { - // Allow everything - so never blowup. - } - - @Override - public final String toString() { - return "ALLOW_ALL"; - } - -} diff --git a/src/org/apache/http/conn/ssl/BrowserCompatHostnameVerifier.java b/src/org/apache/http/conn/ssl/BrowserCompatHostnameVerifier.java deleted file mode 100644 index f4129d6..0000000 --- a/src/org/apache/http/conn/ssl/BrowserCompatHostnameVerifier.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/BrowserCompatHostnameVerifier.java $ - * $Revision: 617642 $ - * $Date: 2008-02-01 12:54:07 -0800 (Fri, 01 Feb 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.ssl; - -import javax.net.ssl.SSLException; - -/** - * The HostnameVerifier that works the same way as Curl and Firefox. - * <p/> - * The hostname must match either the first CN, or any of the subject-alts. - * A wildcard can occur in the CN, and in any of the subject-alts. - * <p/> - * The only difference between BROWSER_COMPATIBLE and STRICT is that a wildcard - * (such as "*.foo.com") with BROWSER_COMPATIBLE matches all subdomains, - * including "a.b.foo.com". - * - * @author Julius Davies - */ -public class BrowserCompatHostnameVerifier extends AbstractVerifier { - - public final void verify( - final String host, - final String[] cns, - final String[] subjectAlts) throws SSLException { - verify(host, cns, subjectAlts, false); - } - - @Override - public final String toString() { - return "BROWSER_COMPATIBLE"; - } - -} diff --git a/src/org/apache/http/conn/ssl/SSLSocketFactory.java b/src/org/apache/http/conn/ssl/SSLSocketFactory.java deleted file mode 100644 index 498b43e..0000000 --- a/src/org/apache/http/conn/ssl/SSLSocketFactory.java +++ /dev/null @@ -1,384 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/SSLSocketFactory.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.ssl; - -import org.apache.http.conn.scheme.HostNameResolver; -import org.apache.http.conn.scheme.LayeredSocketFactory; -import org.apache.http.params.HttpConnectionParams; -import org.apache.http.params.HttpParams; - -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocket; -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactory; -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.Socket; -import java.net.UnknownHostException; -import java.security.KeyManagementException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.security.UnrecoverableKeyException; - -/** - * Layered socket factory for TLS/SSL connections, based on JSSE. - *. - * <p> - * SSLSocketFactory can be used to validate the identity of the HTTPS - * server against a list of trusted certificates and to authenticate to - * the HTTPS server using a private key. - * </p> - * - * <p> - * SSLSocketFactory will enable server authentication when supplied with - * a {@link KeyStore truststore} file containg one or several trusted - * certificates. The client secure socket will reject the connection during - * the SSL session handshake if the target HTTPS server attempts to - * authenticate itself with a non-trusted certificate. - * </p> - * - * <p> - * Use JDK keytool utility to import a trusted certificate and generate a truststore file: - * <pre> - * keytool -import -alias "my server cert" -file server.crt -keystore my.truststore - * </pre> - * </p> - * - * <p> - * SSLSocketFactory will enable client authentication when supplied with - * a {@link KeyStore keystore} file containg a private key/public certificate - * pair. The client secure socket will use the private key to authenticate - * itself to the target HTTPS server during the SSL session handshake if - * requested to do so by the server. - * The target HTTPS server will in its turn verify the certificate presented - * by the client in order to establish client's authenticity - * </p> - * - * <p> - * Use the following sequence of actions to generate a keystore file - * </p> - * <ul> - * <li> - * <p> - * Use JDK keytool utility to generate a new key - * <pre>keytool -genkey -v -alias "my client key" -validity 365 -keystore my.keystore</pre> - * For simplicity use the same password for the key as that of the keystore - * </p> - * </li> - * <li> - * <p> - * Issue a certificate signing request (CSR) - * <pre>keytool -certreq -alias "my client key" -file mycertreq.csr -keystore my.keystore</pre> - * </p> - * </li> - * <li> - * <p> - * Send the certificate request to the trusted Certificate Authority for signature. - * One may choose to act as her own CA and sign the certificate request using a PKI - * tool, such as OpenSSL. - * </p> - * </li> - * <li> - * <p> - * Import the trusted CA root certificate - * <pre>keytool -import -alias "my trusted ca" -file caroot.crt -keystore my.keystore</pre> - * </p> - * </li> - * <li> - * <p> - * Import the PKCS#7 file containg the complete certificate chain - * <pre>keytool -import -alias "my client key" -file mycert.p7 -keystore my.keystore</pre> - * </p> - * </li> - * <li> - * <p> - * Verify the content the resultant keystore file - * <pre>keytool -list -v -keystore my.keystore</pre> - * </p> - * </li> - * </ul> - * @author <a href="mailto:oleg at ural.ru">Oleg Kalnichevski</a> - * @author Julius Davies - */ - -public class SSLSocketFactory implements LayeredSocketFactory { - - public static final String TLS = "TLS"; - public static final String SSL = "SSL"; - public static final String SSLV2 = "SSLv2"; - - public static final X509HostnameVerifier ALLOW_ALL_HOSTNAME_VERIFIER - = new AllowAllHostnameVerifier(); - - public static final X509HostnameVerifier BROWSER_COMPATIBLE_HOSTNAME_VERIFIER - = new BrowserCompatHostnameVerifier(); - - public static final X509HostnameVerifier STRICT_HOSTNAME_VERIFIER - = new StrictHostnameVerifier(); - /** - * The factory using the default JVM settings for secure connections. - */ - private static final SSLSocketFactory DEFAULT_FACTORY = new SSLSocketFactory(); - - /** - * Gets an singleton instance of the SSLProtocolSocketFactory. - * @return a SSLProtocolSocketFactory - */ - public static SSLSocketFactory getSocketFactory() { - return DEFAULT_FACTORY; - } - - private final SSLContext sslcontext; - private final javax.net.ssl.SSLSocketFactory socketfactory; - private final HostNameResolver nameResolver; - private X509HostnameVerifier hostnameVerifier = BROWSER_COMPATIBLE_HOSTNAME_VERIFIER; - - public SSLSocketFactory( - String algorithm, - final KeyStore keystore, - final String keystorePassword, - final KeyStore truststore, - final SecureRandom random, - final HostNameResolver nameResolver) - throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException - { - super(); - if (algorithm == null) { - algorithm = TLS; - } - KeyManager[] keymanagers = null; - if (keystore != null) { - keymanagers = createKeyManagers(keystore, keystorePassword); - } - TrustManager[] trustmanagers = null; - if (truststore != null) { - trustmanagers = createTrustManagers(truststore); - } - this.sslcontext = SSLContext.getInstance(algorithm); - this.sslcontext.init(keymanagers, trustmanagers, random); - this.socketfactory = this.sslcontext.getSocketFactory(); - this.nameResolver = nameResolver; - } - - public SSLSocketFactory( - final KeyStore keystore, - final String keystorePassword, - final KeyStore truststore) - throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException - { - this(TLS, keystore, keystorePassword, truststore, null, null); - } - - public SSLSocketFactory(final KeyStore keystore, final String keystorePassword) - throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException - { - this(TLS, keystore, keystorePassword, null, null, null); - } - - public SSLSocketFactory(final KeyStore truststore) - throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException - { - this(TLS, null, null, truststore, null, null); - } - - /** - * Creates the default SSL socket factory. - * This constructor is used exclusively to instantiate the factory for - * {@link #getSocketFactory getSocketFactory}. - */ - private SSLSocketFactory() { - super(); - this.sslcontext = null; - this.socketfactory = HttpsURLConnection.getDefaultSSLSocketFactory(); - this.nameResolver = null; - } - - private static KeyManager[] createKeyManagers(final KeyStore keystore, final String password) - throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException { - if (keystore == null) { - throw new IllegalArgumentException("Keystore may not be null"); - } - KeyManagerFactory kmfactory = KeyManagerFactory.getInstance( - KeyManagerFactory.getDefaultAlgorithm()); - kmfactory.init(keystore, password != null ? password.toCharArray(): null); - return kmfactory.getKeyManagers(); - } - - private static TrustManager[] createTrustManagers(final KeyStore keystore) - throws KeyStoreException, NoSuchAlgorithmException { - if (keystore == null) { - throw new IllegalArgumentException("Keystore may not be null"); - } - TrustManagerFactory tmfactory = TrustManagerFactory.getInstance( - TrustManagerFactory.getDefaultAlgorithm()); - tmfactory.init(keystore); - return tmfactory.getTrustManagers(); - } - - - // non-javadoc, see interface org.apache.http.conn.SocketFactory - public Socket createSocket() - throws IOException { - - // the cast makes sure that the factory is working as expected - return (SSLSocket) this.socketfactory.createSocket(); - } - - - // non-javadoc, see interface org.apache.http.conn.SocketFactory - public Socket connectSocket( - final Socket sock, - final String host, - final int port, - final InetAddress localAddress, - int localPort, - final 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."); - } - - SSLSocket sslsock = (SSLSocket) - ((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); - sslsock.bind(isa); - } - - int connTimeout = HttpConnectionParams.getConnectionTimeout(params); - int soTimeout = HttpConnectionParams.getSoTimeout(params); - - InetSocketAddress remoteAddress; - if (this.nameResolver != null) { - remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port); - } else { - remoteAddress = new InetSocketAddress(host, port); - } - - sslsock.connect(remoteAddress, connTimeout); - - sslsock.setSoTimeout(soTimeout); - try { - hostnameVerifier.verify(host, sslsock); - // verifyHostName() didn't blowup - good! - } catch (IOException iox) { - // close the socket before re-throwing the exception - try { sslsock.close(); } catch (Exception x) { /*ignore*/ } - throw iox; - } - - return sslsock; - } - - - /** - * Checks whether a socket connection is secure. - * This factory creates TLS/SSL socket connections - * which, by default, are considered secure. - * <br/> - * Derived classes may override this method to perform - * runtime checks, for example based on the cypher suite. - * - * @param sock the connected socket - * - * @return <code>true</code> - * - * @throws IllegalArgumentException if the argument is invalid - */ - public boolean isSecure(Socket sock) - throws IllegalArgumentException { - - if (sock == null) { - throw new IllegalArgumentException("Socket may not be null."); - } - // This instanceof check is in line with createSocket() above. - if (!(sock instanceof SSLSocket)) { - throw new IllegalArgumentException - ("Socket not created by this factory."); - } - // This check is performed last since it calls the argument object. - if (sock.isClosed()) { - throw new IllegalArgumentException("Socket is closed."); - } - - return true; - - } // isSecure - - - // non-javadoc, see interface LayeredSocketFactory - public Socket createSocket( - final Socket socket, - final String host, - final int port, - final boolean autoClose - ) throws IOException, UnknownHostException { - SSLSocket sslSocket = (SSLSocket) this.socketfactory.createSocket( - socket, - host, - port, - autoClose - ); - hostnameVerifier.verify(host, sslSocket); - // verifyHostName() didn't blowup - good! - return sslSocket; - } - - public void setHostnameVerifier(X509HostnameVerifier hostnameVerifier) { - if ( hostnameVerifier == null ) { - throw new IllegalArgumentException("Hostname verifier may not be null"); - } - this.hostnameVerifier = hostnameVerifier; - } - - public X509HostnameVerifier getHostnameVerifier() { - return hostnameVerifier; - } - -} diff --git a/src/org/apache/http/conn/ssl/StrictHostnameVerifier.java b/src/org/apache/http/conn/ssl/StrictHostnameVerifier.java deleted file mode 100644 index 5eb0d96..0000000 --- a/src/org/apache/http/conn/ssl/StrictHostnameVerifier.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/StrictHostnameVerifier.java $ - * $Revision: 617642 $ - * $Date: 2008-02-01 12:54:07 -0800 (Fri, 01 Feb 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.ssl; - -import javax.net.ssl.SSLException; - -/** - * The Strict HostnameVerifier works the same way as Sun Java 1.4, Sun - * Java 5, Sun Java 6-rc. It's also pretty close to IE6. This - * implementation appears to be compliant with RFC 2818 for dealing with - * wildcards. - * <p/> - * The hostname must match either the first CN, or any of the subject-alts. - * A wildcard can occur in the CN, and in any of the subject-alts. The - * one divergence from IE6 is how we only check the first CN. IE6 allows - * a match against any of the CNs present. We decided to follow in - * Sun Java 1.4's footsteps and only check the first CN. (If you need - * to check all the CN's, feel free to write your own implementation!). - * <p/> - * A wildcard such as "*.foo.com" matches only subdomains in the same - * level, for example "a.foo.com". It does not match deeper subdomains - * such as "a.b.foo.com". - * - * @author Julius Davies - */ -public class StrictHostnameVerifier extends AbstractVerifier { - - public final void verify( - final String host, - final String[] cns, - final String[] subjectAlts) throws SSLException { - verify(host, cns, subjectAlts, true); - } - - @Override - public final String toString() { - return "STRICT"; - } - -} diff --git a/src/org/apache/http/conn/ssl/X509HostnameVerifier.java b/src/org/apache/http/conn/ssl/X509HostnameVerifier.java deleted file mode 100644 index 05ad04d..0000000 --- a/src/org/apache/http/conn/ssl/X509HostnameVerifier.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/X509HostnameVerifier.java $ - * $Revision: 618365 $ - * $Date: 2008-02-04 10:20:08 -0800 (Mon, 04 Feb 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.ssl; - -import javax.net.ssl.HostnameVerifier; -import javax.net.ssl.SSLException; -import javax.net.ssl.SSLSession; -import javax.net.ssl.SSLSocket; -import java.io.IOException; -import java.security.cert.X509Certificate; - -/** - * Interface for checking if a hostname matches the names stored inside the - * server's X.509 certificate. Implements javax.net.ssl.HostnameVerifier, but - * we don't actually use that interface. Instead we added some methods that - * take String parameters (instead of javax.net.ssl.HostnameVerifier's - * SSLSession). JUnit is a lot easier this way! :-) - * <p/> - * We provide the HostnameVerifier.DEFAULT, HostnameVerifier.STRICT, and - * HostnameVerifier.ALLOW_ALL implementations. But feel free to define - * your own implementation! - * <p/> - * Inspired by Sebastian Hauer's original StrictSSLProtocolSocketFactory in the - * HttpClient "contrib" repository. - * - * @author Julius Davies - * @author <a href="mailto:hauer@psicode.com">Sebastian Hauer</a> - * - * @since 4.0 (8-Dec-2006) - */ -public interface X509HostnameVerifier extends HostnameVerifier { - - boolean verify(String host, SSLSession session); - - void verify(String host, SSLSocket ssl) throws IOException; - - void verify(String host, X509Certificate cert) throws SSLException; - - /** - * Checks to see if the supplied hostname matches any of the supplied CNs - * or "DNS" Subject-Alts. Most implementations only look at the first CN, - * and ignore any additional CNs. Most implementations do look at all of - * the "DNS" Subject-Alts. The CNs or Subject-Alts may contain wildcards - * according to RFC 2818. - * - * @param cns CN fields, in order, as extracted from the X.509 - * certificate. - * @param subjectAlts Subject-Alt fields of type 2 ("DNS"), as extracted - * from the X.509 certificate. - * @param host The hostname to verify. - * @throws SSLException If verification failed. - */ - void verify(String host, String[] cns, String[] subjectAlts) - throws SSLException; - - -} diff --git a/src/org/apache/http/conn/ssl/package.html b/src/org/apache/http/conn/ssl/package.html deleted file mode 100644 index a5c737f..0000000 --- a/src/org/apache/http/conn/ssl/package.html +++ /dev/null @@ -1,40 +0,0 @@ -<html> -<head> -<!-- -/* - * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/module-client/src/main/java/org/apache/http/conn/ssl/package.html $ - * $Revision: 555193 $ - * $Date: 2007-07-11 00:36:47 -0700 (Wed, 11 Jul 2007) $ - * - * ==================================================================== - * 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/>. - * - */ ---> -</head> -<body> -TLS/SSL specific parts of the <i>HttpConn</i> API. - -</body> -</html> diff --git a/src/org/apache/http/conn/util/InetAddressUtils.java b/src/org/apache/http/conn/util/InetAddressUtils.java deleted file mode 100644 index 71f2190..0000000 --- a/src/org/apache/http/conn/util/InetAddressUtils.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/util/InetAddressUtils.java $ - * $Revision: 652020 $ - * $Date: 2008-04-27 14:23:31 -0700 (Sun, 27 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.util; - -import java.util.regex.Pattern; - -/** - * A collection of utilities relating to InetAddresses. - */ -public class InetAddressUtils { - - private InetAddressUtils() { - } - - private static final Pattern IPV4_PATTERN = - Pattern.compile( - "^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$"); - - private static final Pattern IPV6_STD_PATTERN = - Pattern.compile( - "^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$"); - - private static final Pattern IPV6_HEX_COMPRESSED_PATTERN = - Pattern.compile( - "^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$"); - - public static boolean isIPv4Address(final String input) { - return IPV4_PATTERN.matcher(input).matches(); - } - - public static boolean isIPv6StdAddress(final String input) { - return IPV6_STD_PATTERN.matcher(input).matches(); - } - - public static boolean isIPv6HexCompressedAddress(final String input) { - return IPV6_HEX_COMPRESSED_PATTERN.matcher(input).matches(); - } - - public static boolean isIPv6Address(final String input) { - return isIPv6StdAddress(input) || isIPv6HexCompressedAddress(input); - } - -} |