001: /*
002: * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/params/DefaultHttpParamsFactory.java,v 1.16 2004/11/20 21:48:47 mbecke Exp $
003: * $Revision: 566065 $
004: * $Date: 2007-08-15 10:34:30 +0200 (Wed, 15 Aug 2007) $
005: *
006: * ====================================================================
007: *
008: * Licensed to the Apache Software Foundation (ASF) under one or more
009: * contributor license agreements. See the NOTICE file distributed with
010: * this work for additional information regarding copyright ownership.
011: * The ASF licenses this file to You under the Apache License, Version 2.0
012: * (the "License"); you may not use this file except in compliance with
013: * the License. You may obtain a copy of the License at
014: *
015: * http://www.apache.org/licenses/LICENSE-2.0
016: *
017: * Unless required by applicable law or agreed to in writing, software
018: * distributed under the License is distributed on an "AS IS" BASIS,
019: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
020: * See the License for the specific language governing permissions and
021: * limitations under the License.
022: * ====================================================================
023: *
024: * This software consists of voluntary contributions made by many
025: * individuals on behalf of the Apache Software Foundation. For more
026: * information on the Apache Software Foundation, please see
027: * <http://www.apache.org/>.
028: *
029: */
030:
031: package org.apache.commons.httpclient.params;
032:
033: import java.util.ArrayList;
034: import java.util.Arrays;
035:
036: import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
037: import org.apache.commons.httpclient.HttpVersion;
038: import org.apache.commons.httpclient.SimpleHttpConnectionManager;
039: import org.apache.commons.httpclient.cookie.CookiePolicy;
040: import org.apache.commons.httpclient.util.DateUtil;
041:
042: /**
043: * @since 3.0
044: */
045: public class DefaultHttpParamsFactory implements HttpParamsFactory {
046:
047: private HttpParams httpParams;
048:
049: /**
050: *
051: */
052: public DefaultHttpParamsFactory() {
053: super ();
054: }
055:
056: /* (non-Javadoc)
057: * @see org.apache.commons.httpclient.params.HttpParamsFactory#getDefaultParams()
058: */
059: public synchronized HttpParams getDefaultParams() {
060: if (httpParams == null) {
061: httpParams = createParams();
062: }
063:
064: return httpParams;
065: }
066:
067: protected HttpParams createParams() {
068: HttpClientParams params = new HttpClientParams(null);
069:
070: params.setParameter(HttpMethodParams.USER_AGENT,
071: "Jakarta Commons-HttpClient/3.1");
072: params.setVersion(HttpVersion.HTTP_1_1);
073: params
074: .setConnectionManagerClass(SimpleHttpConnectionManager.class);
075: params.setCookiePolicy(CookiePolicy.DEFAULT);
076: params.setHttpElementCharset("US-ASCII");
077: params.setContentCharset("ISO-8859-1");
078: params.setParameter(HttpMethodParams.RETRY_HANDLER,
079: new DefaultHttpMethodRetryHandler());
080:
081: ArrayList datePatterns = new ArrayList();
082: datePatterns.addAll(Arrays.asList(new String[] {
083: DateUtil.PATTERN_RFC1123, DateUtil.PATTERN_RFC1036,
084: DateUtil.PATTERN_ASCTIME,
085: "EEE, dd-MMM-yyyy HH:mm:ss z",
086: "EEE, dd-MMM-yyyy HH-mm-ss z",
087: "EEE, dd MMM yy HH:mm:ss z",
088: "EEE dd-MMM-yyyy HH:mm:ss z",
089: "EEE dd MMM yyyy HH:mm:ss z",
090: "EEE dd-MMM-yyyy HH-mm-ss z",
091: "EEE dd-MMM-yy HH:mm:ss z", "EEE dd MMM yy HH:mm:ss z",
092: "EEE,dd-MMM-yy HH:mm:ss z",
093: "EEE,dd-MMM-yyyy HH:mm:ss z",
094: "EEE, dd-MM-yyyy HH:mm:ss z", }));
095: params.setParameter(HttpMethodParams.DATE_PATTERNS,
096: datePatterns);
097:
098: // TODO: To be removed. Provided for backward compatibility
099: String agent = null;
100: try {
101: agent = System.getProperty("httpclient.useragent");
102: } catch (SecurityException ignore) {
103: }
104: if (agent != null) {
105: params.setParameter(HttpMethodParams.USER_AGENT, agent);
106: }
107:
108: // TODO: To be removed. Provided for backward compatibility
109: String preemptiveDefault = null;
110: try {
111: preemptiveDefault = System
112: .getProperty("httpclient.authentication.preemptive");
113: } catch (SecurityException ignore) {
114: }
115: if (preemptiveDefault != null) {
116: preemptiveDefault = preemptiveDefault.trim().toLowerCase();
117: if (preemptiveDefault.equals("true")) {
118: params.setParameter(
119: HttpClientParams.PREEMPTIVE_AUTHENTICATION,
120: Boolean.TRUE);
121: } else if (preemptiveDefault.equals("false")) {
122: params.setParameter(
123: HttpClientParams.PREEMPTIVE_AUTHENTICATION,
124: Boolean.FALSE);
125: }
126: }
127:
128: // TODO: To be removed. Provided for backward compatibility
129: String defaultCookiePolicy = null;
130: try {
131: defaultCookiePolicy = System
132: .getProperty("apache.commons.httpclient.cookiespec");
133: } catch (SecurityException ignore) {
134: }
135: if (defaultCookiePolicy != null) {
136: if ("COMPATIBILITY".equalsIgnoreCase(defaultCookiePolicy)) {
137: params
138: .setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
139: } else if ("NETSCAPE_DRAFT"
140: .equalsIgnoreCase(defaultCookiePolicy)) {
141: params.setCookiePolicy(CookiePolicy.NETSCAPE);
142: } else if ("RFC2109".equalsIgnoreCase(defaultCookiePolicy)) {
143: params.setCookiePolicy(CookiePolicy.RFC_2109);
144: }
145: }
146:
147: return params;
148: }
149:
150: }
|