View Javadoc

1   /*
2    * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/params/HttpClientParams.java,v 1.7 2004/05/13 04:01:22 mbecke Exp $
3    * $Revision: 354155 $
4    * $Date: 2005-12-05 15:18:10 -0500 (Mon, 05 Dec 2005) $
5    *
6    * ====================================================================
7    *
8    *  Copyright 1999-2004 The Apache Software Foundation
9    *
10   *  Licensed under the Apache License, Version 2.0 (the "License");
11   *  you may not use this file except in compliance with the License.
12   *  You may obtain a copy of the License at
13   *
14   *      http://www.apache.org/licenses/LICENSE-2.0
15   *
16   *  Unless required by applicable law or agreed to in writing, software
17   *  distributed under the License is distributed on an "AS IS" BASIS,
18   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19   *  See the License for the specific language governing permissions and
20   *  limitations under the License.
21   * ====================================================================
22   *
23   * This software consists of voluntary contributions made by many
24   * individuals on behalf of the Apache Software Foundation.  For more
25   * information on the Apache Software Foundation, please see
26   * <http://www.apache.org/>.
27   *
28   */
29  
30  package org.apache.commons.httpclient.params;
31  
32  /***
33   * This class represents a collection of HTTP protocol parameters applicable to 
34   * {@link org.apache.commons.httpclient.HttpClient instances of HttpClient}. 
35   * Protocol parameters may be linked together to form a hierarchy. If a particular 
36   * parameter value has not been explicitly defined in the collection itself, its 
37   * value will be drawn from the parent collection of parameters.
38   * 
39   * @author <a href="mailto:oleg@ural.ru">Oleg Kalnichevski</a>
40   * 
41   * @version $Revision: 354155 $
42   * 
43   * @since 3.0
44   */
45  public class HttpClientParams extends HttpMethodParams {
46  
47      /***
48       * Sets the timeout in milliseconds used when retrieving an 
49       * {@link org.apache.commons.httpclient.HttpConnection HTTP connection} from the
50       * {@link org.apache.commons.httpclient.HttpConnectionManager HTTP connection manager}.
51       * <p>
52       * This parameter expects a value of type {@link Long}.
53       * </p>
54       */ 
55      public static final String CONNECTION_MANAGER_TIMEOUT = "http.connection-manager.timeout"; 
56  
57      /***
58       * Defines the default 
59       * {@link org.apache.commons.httpclient.HttpConnectionManager HTTP connection manager}
60       * class.
61       * <p>
62       * This parameter expects a value of type {@link Class}.
63       * </p>
64       */ 
65      public static final String CONNECTION_MANAGER_CLASS = "http.connection-manager.class"; 
66  
67      /***
68       * Defines whether authentication should be attempted preemptively.
69       * <p>
70       * This parameter expects a value of type {@link Boolean}.
71       * </p>
72       */
73      public static final String PREEMPTIVE_AUTHENTICATION = "http.authentication.preemptive";
74  
75      /***
76       * Defines whether relative redirects should be rejected.
77       * <p>
78       * This parameter expects a value of type {@link Boolean}.
79       * </p>
80       */
81      public static final String REJECT_RELATIVE_REDIRECT = "http.protocol.reject-relative-redirect"; 
82  
83      /*** 
84       * Defines the maximum number of redirects to be followed. 
85       * The limit on number of redirects is intended to prevent infinite loops. 
86       * <p>
87       * This parameter expects a value of type {@link Integer}.
88       * </p>
89       */
90      public static final String MAX_REDIRECTS = "http.protocol.max-redirects";
91  
92      /*** 
93       * Defines whether circular redirects (redirects to the same location) should be allowed. 
94       * The HTTP spec is not sufficiently clear whether circular redirects are permitted, 
95       * therefore optionally they can be enabled
96       * <p>
97       * This parameter expects a value of type {@link Boolean}.
98       * </p>
99       */
100     public static final String ALLOW_CIRCULAR_REDIRECTS = "http.protocol.allow-circular-redirects";
101 
102     /***
103      * Creates a new collection of parameters with the collection returned
104      * by {@link #getDefaultParams()} as a parent. The collection will defer
105      * to its parent for a default value if a particular parameter is not 
106      * explicitly set in the collection itself.
107      * 
108      * @see #getDefaultParams()
109      */
110     public HttpClientParams() {
111         super();
112     }
113 
114     /***
115      * Creates a new collection of parameters with the given parent. 
116      * The collection will defer to its parent for a default value 
117      * if a particular parameter is not explicitly set in the collection
118      * itself.
119      * 
120      * @param defaults the parent collection to defer to, if a parameter
121      * is not explictly set in the collection itself.
122      *
123      * @see #getDefaultParams()
124      */
125     public HttpClientParams(HttpParams defaults) {
126         super(defaults);
127     }
128 
129     /***
130      * Returns the timeout in milliseconds used when retrieving an 
131      * {@link org.apache.commons.httpclient.HttpConnection HTTP connection} from the
132      * {@link org.apache.commons.httpclient.HttpConnectionManager HTTP connection manager}.
133      * 
134      * @return timeout in milliseconds.
135      */ 
136     public long getConnectionManagerTimeout() {
137         return getLongParameter(CONNECTION_MANAGER_TIMEOUT, 0);
138     }
139 
140     /***
141      * Sets the timeout in milliseconds used when retrieving an 
142      * {@link org.apache.commons.httpclient.HttpConnection HTTP connection} from the
143      * {@link org.apache.commons.httpclient.HttpConnectionManager HTTP connection manager}.
144      * 
145      * @param timeout the timeout in milliseconds
146      */ 
147     public void setConnectionManagerTimeout(long timeout) {
148         setLongParameter(CONNECTION_MANAGER_TIMEOUT, timeout);
149     }
150 
151     /***
152      * Returns the default 
153      * {@link org.apache.commons.httpclient.HttpConnectionManager HTTP connection manager}
154      * class.
155      * @return {@link org.apache.commons.httpclient.HttpConnectionManager HTTP connection manager}
156      * factory class.
157      */ 
158     public Class getConnectionManagerClass() {
159         return (Class) getParameter(CONNECTION_MANAGER_CLASS);
160     }
161 
162     /***
163      * Sets {@link org.apache.commons.httpclient.HttpConnectionManager HTTP connection manager}
164      * class to be used der default.
165      * @param clazz 
166      *  {@link org.apache.commons.httpclient.HttpConnectionManager HTTP connection manager}
167      *  factory class.
168      */ 
169     public void setConnectionManagerClass(Class clazz) {
170         setParameter(CONNECTION_MANAGER_CLASS, clazz);
171     }
172     
173     /***
174      * Returns <tt>true</tt> if authentication should be attempted preemptively, 
175      * <tt>false</tt> otherwise.
176      * 
177      * @return <tt>true</tt> if authentication should be attempted preemptively,
178      *   <tt>false</tt> otherwise.
179      */
180     public boolean isAuthenticationPreemptive() {
181         return getBooleanParameter(PREEMPTIVE_AUTHENTICATION, false); 
182     }
183 
184     /***
185      * Sets whether authentication should be attempted preemptively.
186      * 
187      * @param value <tt>true</tt> if authentication should be attempted preemptively,
188      *   <tt>false</tt> otherwise.
189      */
190     public void setAuthenticationPreemptive(boolean value) {
191         setBooleanParameter(PREEMPTIVE_AUTHENTICATION, value); 
192     }
193 
194     private static final String[] PROTOCOL_STRICTNESS_PARAMETERS = {
195         REJECT_RELATIVE_REDIRECT,
196         ALLOW_CIRCULAR_REDIRECTS
197     };
198 
199 
200     public void makeStrict() {
201         super.makeStrict();
202         setParameters(PROTOCOL_STRICTNESS_PARAMETERS, Boolean.TRUE);
203     }
204 
205 
206     public void makeLenient() {
207         super.makeLenient();
208         setParameters(PROTOCOL_STRICTNESS_PARAMETERS, Boolean.FALSE);
209     }
210 }