001: /*
002: * Copyright 2003-2006 Rick Knowles <winstone-devel at lists sourceforge net>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: */
007: package winstone.auth;
008:
009: import java.io.IOException;
010: import java.io.InputStream;
011: import java.util.Collections;
012: import java.util.Enumeration;
013: import java.util.HashMap;
014: import java.util.Locale;
015: import java.util.Map;
016: import java.util.Vector;
017:
018: import javax.servlet.ServletRequest;
019: import javax.servlet.http.HttpServletRequest;
020:
021: /**
022: * This is used by the ACL filter to allow a retry by using a key lookup
023: * on old request. It's only used when retrying an old request that was blocked
024: * by the ACL filter.
025: *
026: * @author <a href="mailto:rick_knowles@hotmail.com">Rick Knowles</a>
027: * @version $Id: RetryRequestParams.java,v 1.2 2007/06/01 15:59:53 rickknowles Exp $
028: */
029: public class RetryRequestParams implements java.io.Serializable {
030:
031: private String method;
032: private String scheme;
033: private String contextPath;
034: private String servletPath;
035: private String pathInfo;
036: private String queryString;
037: private String protocol;
038: private int contentLength;
039: private String contentType;
040: private String encoding;
041: private Map headers;
042: private Vector locales;
043: private Locale locale;
044: private byte[] bodyContent;
045:
046: /**
047: * Constructor - this populates the wrapper from the object in session
048: */
049: public RetryRequestParams(ServletRequest request)
050: throws IOException {
051: this .protocol = request.getProtocol();
052: this .locales = new Vector(Collections
053: .list(request.getLocales()));
054: this .locale = request.getLocale();
055: this .contentLength = request.getContentLength();
056: this .contentType = request.getContentType();
057: this .encoding = request.getCharacterEncoding();
058: this .headers = new HashMap();
059:
060: if (request instanceof HttpServletRequest) {
061: HttpServletRequest httpRequest = (HttpServletRequest) request;
062: this .method = httpRequest.getMethod();
063: this .contextPath = httpRequest.getContextPath();
064: this .servletPath = httpRequest.getServletPath();
065: this .pathInfo = httpRequest.getPathInfo();
066: this .queryString = httpRequest.getQueryString();
067:
068: for (Enumeration names = httpRequest.getHeaderNames(); names
069: .hasMoreElements();) {
070: String name = (String) names.nextElement();
071: headers.put(name.toLowerCase(), new Vector(Collections
072: .list(httpRequest.getHeaders(name))));
073: }
074: }
075:
076: if (((this .method == null) || this .method
077: .equalsIgnoreCase("POST"))
078: && (this .contentLength != -1)) {
079: InputStream inData = request.getInputStream();
080: this .bodyContent = new byte[this .contentLength];
081: int readCount = 0;
082: int read = 0;
083: while ((read = inData.read(this .bodyContent, readCount,
084: this .contentLength - readCount)) >= 0) {
085: readCount += read;
086: }
087: inData.close();
088: }
089: }
090:
091: public byte[] getBodyContent() {
092: return bodyContent;
093: }
094:
095: public int getContentLength() {
096: return contentLength;
097: }
098:
099: public String getContentType() {
100: return contentType;
101: }
102:
103: public String getEncoding() {
104: return encoding;
105: }
106:
107: public Map getHeaders() {
108: return headers;
109: }
110:
111: public Locale getLocale() {
112: return locale;
113: }
114:
115: public Vector getLocales() {
116: return locales;
117: }
118:
119: public String getMethod() {
120: return method;
121: }
122:
123: public String getPathInfo() {
124: return pathInfo;
125: }
126:
127: public String getProtocol() {
128: return protocol;
129: }
130:
131: public String getQueryString() {
132: return queryString;
133: }
134:
135: public String getScheme() {
136: return scheme;
137: }
138:
139: public String getServletPath() {
140: return servletPath;
141: }
142:
143: public String getContextPath() {
144: return contextPath;
145: }
146: }
|