diff options
author | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2008-10-21 07:00:00 -0700 |
commit | 417f3b92ba4549b2f22340e3107d869d2b9c5bb8 (patch) | |
tree | 2e08a2a91d6d14995df54490e3667f7943fbc6d6 /src/org/apache/http/conn/params | |
download | external_apache-http-417f3b92ba4549b2f22340e3107d869d2b9c5bb8.zip external_apache-http-417f3b92ba4549b2f22340e3107d869d2b9c5bb8.tar.gz external_apache-http-417f3b92ba4549b2f22340e3107d869d2b9c5bb8.tar.bz2 |
Initial Contribution
Diffstat (limited to 'src/org/apache/http/conn/params')
11 files changed, 983 insertions, 0 deletions
diff --git a/src/org/apache/http/conn/params/ConnConnectionPNames.java b/src/org/apache/http/conn/params/ConnConnectionPNames.java new file mode 100644 index 0000000..ff1a090 --- /dev/null +++ b/src/org/apache/http/conn/params/ConnConnectionPNames.java @@ -0,0 +1,65 @@ +/* + * $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 new file mode 100644 index 0000000..094b152 --- /dev/null +++ b/src/org/apache/http/conn/params/ConnConnectionParamBean.java @@ -0,0 +1,55 @@ +/* + * $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 new file mode 100644 index 0000000..1184b12 --- /dev/null +++ b/src/org/apache/http/conn/params/ConnManagerPNames.java @@ -0,0 +1,73 @@ +/* + * $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 new file mode 100644 index 0000000..830b7bf --- /dev/null +++ b/src/org/apache/http/conn/params/ConnManagerParamBean.java @@ -0,0 +1,62 @@ +/* + * $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 new file mode 100644 index 0000000..c6e042e --- /dev/null +++ b/src/org/apache/http/conn/params/ConnManagerParams.java @@ -0,0 +1,169 @@ +/* + * $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 new file mode 100644 index 0000000..abff04e --- /dev/null +++ b/src/org/apache/http/conn/params/ConnPerRoute.java @@ -0,0 +1,51 @@ +/* + * $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 new file mode 100644 index 0000000..c6a36e3 --- /dev/null +++ b/src/org/apache/http/conn/params/ConnPerRouteBean.java @@ -0,0 +1,114 @@ +/* + * $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 new file mode 100644 index 0000000..f9d42db --- /dev/null +++ b/src/org/apache/http/conn/params/ConnRoutePNames.java @@ -0,0 +1,84 @@ +/* + * $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 new file mode 100644 index 0000000..9464c02 --- /dev/null +++ b/src/org/apache/http/conn/params/ConnRouteParamBean.java @@ -0,0 +1,67 @@ +/* + * $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 new file mode 100644 index 0000000..2fa1654 --- /dev/null +++ b/src/org/apache/http/conn/params/ConnRouteParams.java @@ -0,0 +1,203 @@ +/* + * $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 new file mode 100644 index 0000000..9b80420 --- /dev/null +++ b/src/org/apache/http/conn/params/package.html @@ -0,0 +1,40 @@ +<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> |