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