KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > tui > MockHttpServletRequest


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/tui/MockHttpServletRequest.java#5 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2005-2006 Julian Hyde and others
7 // All Rights Reserved.
8 // You must accept the terms of that agreement to use this software.
9 */

10
11 package mondrian.tui;
12
13 import java.io.ByteArrayInputStream JavaDoc;
14 import java.io.IOException JavaDoc;
15 import java.io.BufferedReader JavaDoc;
16 import java.io.StringReader JavaDoc;
17 import java.io.UnsupportedEncodingException JavaDoc;
18 import java.text.SimpleDateFormat JavaDoc;
19 import java.text.ParseException JavaDoc;
20 import java.util.Locale JavaDoc;
21 import java.util.Collections JavaDoc;
22 import java.util.Enumeration JavaDoc;
23 import java.util.LinkedHashMap JavaDoc;
24 import java.util.ArrayList JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Date JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.security.Principal JavaDoc;
30 import javax.servlet.RequestDispatcher JavaDoc;
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.ServletRequest JavaDoc;
33 import javax.servlet.ServletResponse JavaDoc;
34 import javax.servlet.ServletInputStream JavaDoc;
35 import javax.servlet.http.Cookie JavaDoc;
36 import javax.servlet.http.HttpSession JavaDoc;
37 import javax.servlet.http.HttpServletRequest JavaDoc;
38
39 /**
40  * This is a partial implementation of the HttpServletRequest where just
41  * enough is present to allow for communication between Mondrian's
42  * XMLA code and other code in the same JVM.
43  * Currently it is used in both the CmdRunner and in XMLA JUnit tests.
44  * <p>
45  * If you need to add to this implementation, please do so.
46  *
47  * @author <a>Richard M. Emberson</a>
48  * @version $Id: //open/mondrian/src/main/mondrian/tui/MockHttpServletRequest.java#5 $
49  */

50 public class MockHttpServletRequest implements HttpServletRequest JavaDoc {
51     public static String JavaDoc AUTHORIZATION = "Authorization";
52     public final static String JavaDoc DATE_FORMAT_HEADER = "EEE, d MMM yyyy HH:mm:ss Z";
53
54     public class MockRequestDispatcher implements RequestDispatcher JavaDoc {
55         private ServletRequest JavaDoc forwardedRequest;
56         private ServletResponse JavaDoc forwardedResponse;
57         private ServletRequest JavaDoc includedRequest;
58         private ServletResponse JavaDoc includedResponse;
59         private String JavaDoc path;
60
61         MockRequestDispatcher() {
62         }
63         public void setPath(String JavaDoc path) {
64             this.path = path;
65         }
66         public String JavaDoc getPath() {
67             return this.path;
68         }
69         public void forward(ServletRequest JavaDoc request, ServletResponse JavaDoc response)
70             throws ServletException JavaDoc, IOException JavaDoc {
71             this.forwardedRequest = request;
72             this.forwardedResponse = response;
73         }
74         public void include(ServletRequest JavaDoc request, ServletResponse JavaDoc response)
75                 throws ServletException JavaDoc, IOException JavaDoc {
76             this.includedRequest = request;
77             this.includedResponse = response;
78         }
79
80         public ServletRequest JavaDoc getForwardedRequest() {
81             return this.forwardedRequest;
82         }
83
84         public ServletResponse JavaDoc getForwardedResponse() {
85             return this.forwardedResponse;
86         }
87         public ServletRequest JavaDoc getIncludedRequest() {
88             return this.includedRequest;
89         }
90
91         public ServletResponse JavaDoc getIncludedResponse() {
92             return this.includedResponse;
93         }
94     }
95     static class MockServletInputStream extends ServletInputStream JavaDoc {
96         private ByteArrayInputStream JavaDoc stream;
97
98         public MockServletInputStream(byte[] data) {
99             stream = new ByteArrayInputStream JavaDoc(data);
100         }
101
102         public int read() throws IOException JavaDoc {
103             return stream.read();
104         }
105     }
106
107
108     private HttpSession JavaDoc session;
109     //private ByteArrayInputStream bin;
110
private Map JavaDoc<String JavaDoc, String JavaDoc[]> parameters;
111     private Map JavaDoc<String JavaDoc, RequestDispatcher JavaDoc> requestDispatchers;
112     private List JavaDoc<Locale JavaDoc> locales;
113     private String JavaDoc serverName;
114     private String JavaDoc charEncoding;
115     private String JavaDoc method;
116     private String JavaDoc pathInfo;
117     private String JavaDoc pathTranslated;
118     private String JavaDoc contextPath;
119     private String JavaDoc queryString;
120     private String JavaDoc remoteUser;
121     private String JavaDoc requestedSessionId;
122     private String JavaDoc servletPath;
123     private String JavaDoc scheme;
124     private String JavaDoc localName;
125     private String JavaDoc localAddr;
126     private String JavaDoc authType;
127     private String JavaDoc protocol;
128     private String JavaDoc schema;
129     private Principal JavaDoc principal;
130     private List JavaDoc<Cookie JavaDoc> cookies;
131     private boolean requestedSessionIdIsFromCookie;
132     private int remotePort;
133     private int localPort;
134     private int serverPort;
135     private String JavaDoc remoteAddr;
136     private String JavaDoc remoteHost;
137     private Map JavaDoc<String JavaDoc, Object JavaDoc> attributes;
138     private final LinkedHashMap JavaDoc<String JavaDoc, List JavaDoc<String JavaDoc>> headers;
139     private boolean sessionCreated;
140     private String JavaDoc requestedURI;
141     private StringBuffer JavaDoc requestUrl;
142     private String JavaDoc bodyContent;
143     private Map JavaDoc<String JavaDoc, Boolean JavaDoc> roles;
144
145     public MockHttpServletRequest() {
146         this(new byte[0]);
147     }
148     public MockHttpServletRequest(byte[] bytes) {
149         this(new String JavaDoc(bytes));
150     }
151     public MockHttpServletRequest(String JavaDoc bodyContent) {
152         this.bodyContent = bodyContent;
153         this.attributes = Collections.emptyMap();
154         //this.bin = new ByteArrayInputStream(bytes);
155
this.headers = new LinkedHashMap JavaDoc<String JavaDoc, List JavaDoc<String JavaDoc>>();
156         this.requestDispatchers = new HashMap JavaDoc<String JavaDoc, RequestDispatcher JavaDoc>();
157         this.parameters = new HashMap JavaDoc<String JavaDoc, String JavaDoc[]>();
158         this.cookies = new ArrayList JavaDoc<Cookie JavaDoc>();
159         this.locales = new ArrayList JavaDoc<Locale JavaDoc>();
160         this.roles = new HashMap JavaDoc<String JavaDoc, Boolean JavaDoc>();
161         this.requestedSessionIdIsFromCookie = true;
162         this.method = "GET";
163         this.protocol = "HTTP/1.1";
164         this.serverName = "localhost";
165         this.serverPort = 8080;
166         this.scheme = "http";
167         this.remoteHost = "localhost";
168         this.remoteAddr = "127.0.0.1";
169         this.localAddr = "127.0.0.1";
170         this.localName = "localhost";
171         this.localPort = 8080;
172         this.remotePort = 5000;
173
174         this.sessionCreated = false;
175
176     }
177
178
179     /**
180      * Returns the value of the named attribute as an Object, or null if no
181      * attribute of the given name exists.
182      *
183      */

184     public Object JavaDoc getAttribute(String JavaDoc name) {
185         return this.attributes.get(name);
186     }
187
188     /**
189      * to this request.
190      *
191      */

192     public Enumeration JavaDoc getAttributeNames() {
193         return Collections.enumeration(attributes.keySet());
194     }
195
196     /**
197      * Returns the name of the character encoding used in the body of this
198      * request.
199      *
200      */

201     public String JavaDoc getCharacterEncoding() {
202         return charEncoding;
203     }
204
205     /**
206      *
207      *
208      */

209     public void setCharacterEncoding(String JavaDoc charEncoding)
210             throws UnsupportedEncodingException JavaDoc {
211         this.charEncoding = charEncoding;
212     }
213
214     /**
215      * Returns the length, in bytes, of the request body and made available by
216      * the input stream, or -1 if the length is not known.
217      *
218      */

219     public int getContentLength() {
220         return getIntHeader("Content-Length");
221     }
222
223     /**
224      * Returns the MIME type of the body of the request, or null if the type is
225      * not known.
226      *
227      */

228     public String JavaDoc getContentType() {
229         return getHeader("Content-Type");
230     }
231
232     /**
233      * Retrieves the body of the request as binary data using a
234      * ServletInputStream.
235      *
236      * @throws IOException
237      */

238     public ServletInputStream JavaDoc getInputStream() throws IOException JavaDoc {
239         return new MockServletInputStream(bodyContent.getBytes());
240     }
241
242     /**
243      * Returns the value of a request parameter as a String, or null if the
244      * parameter does not exist.
245      *
246      */

247     public String JavaDoc getParameter(String JavaDoc name) {
248         String JavaDoc[] values = getParameterValues(name);
249         return (null != values && 0 < values.length)
250             ? values[0] : null;
251     }
252
253     /**
254      * Returns an Enumeration of String objects containing the names of the
255      * parameters contained in this request.
256      *
257      */

258     public Enumeration JavaDoc getParameterNames() {
259         return Collections.enumeration(parameters.keySet());
260     }
261
262     /**
263      * Returns an array of String objects containing all of the values the given
264      * request parameter has, or null if the parameter does not exist.
265      *
266      */

267     public String JavaDoc[] getParameterValues(String JavaDoc name) {
268         return parameters.get(name);
269     }
270
271
272     /**
273      * Returns the name and version of the protocol the request uses in the form
274      * protocol/majorVersion.minorVersion, for example, HTTP/1.1.
275      *
276      */

277     public String JavaDoc getProtocol() {
278         return protocol;
279     }
280
281     /**
282      * Returns the name of the scheme used to make this request, for example,
283      * http, https, or ftp.
284      *
285      */

286     public String JavaDoc getScheme() {
287         return schema;
288     }
289
290     /**
291      * Returns the host name of the server that received the request.
292      *
293      */

294     public String JavaDoc getServerName() {
295         return serverName;
296     }
297
298     /**
299      * Returns the port number on which this request was received.
300      *
301      */

302     public int getServerPort() {
303         return serverPort;
304     }
305
306     /**
307      * Retrieves the body of the request as character data using a
308      * BufferedReader.
309      *
310      * @throws IOException
311      */

312     public BufferedReader JavaDoc getReader() throws IOException JavaDoc {
313         return (bodyContent == null)
314             ? null
315             : new BufferedReader JavaDoc(new StringReader JavaDoc(bodyContent));
316     }
317
318     /**
319      * Returns the Internet Protocol (IP) address of the client that sent the
320      * request.
321      *
322      */

323     public String JavaDoc getRemoteAddr() {
324         return remoteAddr;
325     }
326
327     /**
328      * Returns the fully qualified name of the client that sent the request, or
329      * the IP address of the client if the name cannot be determined.
330      *
331      */

332     public String JavaDoc getRemoteHost() {
333         return remoteHost;
334     }
335
336     /**
337      * Stores an attribute in this request.
338      *
339      */

340     public void setAttribute(String JavaDoc name, Object JavaDoc obj) {
341         if (attributes == Collections.EMPTY_MAP) {
342             attributes = new HashMap JavaDoc<String JavaDoc, Object JavaDoc>();
343         }
344         this.attributes.put(name, obj);
345     }
346
347     /**
348      * Removes an attribute from this request.
349      *
350      */

351     public void removeAttribute(String JavaDoc name) {
352         this.attributes.remove(name);
353     }
354
355     /**
356      * Returns the preferred Locale that the client will accept content in,
357      * based on the Accept-Language header.
358      *
359      */

360     public Locale JavaDoc getLocale() {
361         return (locales.size() < 1)
362             ? Locale.getDefault()
363             : locales.get(0);
364     }
365
366     /**
367      * Returns an Enumeration of Locale objects indicating, in decreasing order
368      * starting with the preferred locale, the locales that are acceptable to
369      * the client based on the Accept-Language header.
370      *
371      */

372     public Enumeration JavaDoc getLocales() {
373         return Collections.enumeration(locales);
374     }
375
376     /**
377      * Returns a boolean indicating whether this request was made using a
378      * secure channel, such as HTTPS.
379      *
380      */

381     public boolean isSecure() {
382         String JavaDoc scheme = getScheme();
383         return (scheme == null)
384             ? false
385             : scheme.equals("https");
386     }
387
388     /**
389      * Returns a RequestDispatcher object that acts as a wrapper for the
390      * resource located at the given path.
391      *
392      */

393     public RequestDispatcher JavaDoc getRequestDispatcher(String JavaDoc path) {
394         RequestDispatcher JavaDoc dispatcher =
395             requestDispatchers.get(path);
396         if (dispatcher == null) {
397             dispatcher = new MockRequestDispatcher();
398             setRequestDispatcher(path, dispatcher);
399         }
400         return dispatcher;
401     }
402
403     /**
404      * Deprecated. As of Version 2.1 of the Java Servlet API, use
405      * ServletContext.getRealPath(java.lang.String) instead.
406      * @deprecated Method getRealPath is deprecated
407      *
408      */

409     public String JavaDoc getRealPath(String JavaDoc path) {
410         HttpSession JavaDoc session = getSession();
411         return (session == null)
412             ? null
413             : session.getServletContext().getRealPath(path);
414
415     }
416
417     /**
418      *
419      *
420      */

421     public int getRemotePort() {
422         return remotePort;
423     }
424
425     /**
426      *
427      *
428      */

429     public String JavaDoc getLocalName() {
430         return localName;
431     }
432
433     /**
434      *
435      *
436      */

437     public String JavaDoc getLocalAddr() {
438         return localAddr;
439     }
440
441     /**
442      *
443      *
444      */

445     public int getLocalPort() {
446         return localPort;
447     }
448
449     /**
450      * Returns the name of the authentication scheme used to protect the
451      * servlet, for example, "BASIC" or "SSL," or null if the servlet was not
452      * protected.
453      *
454      */

455     public String JavaDoc getAuthType() {
456         return authType;
457     }
458
459     /**
460      * Returns an array containing all of the Cookie objects the client sent
461      * with this request.
462      *
463      */

464     public Cookie JavaDoc[] getCookies() {
465         return cookies.toArray(new Cookie JavaDoc[cookies.size()]);
466     }
467
468     /**
469      * Returns the value of the specified request header as a long value that
470      * represents a Date object.
471      *
472      */

473     public long getDateHeader(String JavaDoc name) {
474         String JavaDoc header = getHeader(name);
475         if (header == null) {
476             return -1;
477         }
478         try {
479             Date JavaDoc dateValue = new SimpleDateFormat JavaDoc(DATE_FORMAT_HEADER, Locale.US).parse(header);
480             return dateValue.getTime();
481         } catch (ParseException JavaDoc exc) {
482             throw new IllegalArgumentException JavaDoc(exc.getMessage());
483         }
484     }
485
486     /**
487      * Returns the value of the specified request header as a String.
488      *
489      */

490     public String JavaDoc getHeader(String JavaDoc name) {
491
492         List JavaDoc<String JavaDoc> headerList = headers.get(name);
493
494         return ((headerList == null) || (headerList.size() ==0))
495             ? null
496             : headerList.get(0);
497     }
498
499     /**
500      * Returns all the values of the specified request header as an Enumeration
501      * of String objects.
502      *
503      */

504     public Enumeration JavaDoc getHeaders(String JavaDoc name) {
505         List JavaDoc<String JavaDoc> headerList = headers.get(name);
506         return (headerList == null)
507             ? null
508             : Collections.enumeration(headerList);
509     }
510
511     /**
512      * Returns an enumeration of all the header names this request contains.
513      *
514      */

515     public Enumeration JavaDoc getHeaderNames() {
516         return Collections.enumeration(headers.keySet());
517     }
518
519     /**
520      * Returns the value of the specified request header as an int.
521      *
522      */

523     public int getIntHeader(String JavaDoc name) {
524         String JavaDoc header = getHeader(name);
525         return (header == null)
526             ? -1
527             : Integer.parseInt(header);
528     }
529
530     /**
531      * Returns the name of the HTTP method with which this request was made, for
532      * example, GET, POST, or PUT.
533      *
534      */

535     public String JavaDoc getMethod() {
536         return this.method;
537     }
538
539     /**
540      * Returns any extra path information associated with the URL the client
541      * sent when it made this request.
542      *
543      */

544     public String JavaDoc getPathInfo() {
545         return pathInfo;
546     }
547
548     /**
549      * Returns any extra path information after the servlet name but before the
550      * query string, and translates it to a real path.
551      *
552      */

553     public String JavaDoc getPathTranslated() {
554         return pathTranslated;
555     }
556
557     /**
558      * Returns the portion of the request URI that indicates the context of the
559      * request.
560      *
561      */

562     public String JavaDoc getContextPath() {
563         return contextPath;
564     }
565
566     /**
567      * Returns the query string that is contained in the request URL after the
568      * path.
569      *
570      */

571     public String JavaDoc getQueryString() {
572         return queryString;
573     }
574
575     /**
576      * Returns the login of the user making this request, if the user has been
577      * authenticated, or null if the user has not been authenticated.
578      *
579      */

580     public String JavaDoc getRemoteUser() {
581         return remoteUser;
582     }
583
584     /**
585      * Returns a boolean indicating whether the authenticated user is included
586      * in the specified logical "role".
587      *
588      */

589     public boolean isUserInRole(String JavaDoc role) {
590         return roles.get(role);
591     }
592
593     /**
594      * Returns a java.security.Principal object containing the name of the
595      * current authenticated user.
596      *
597      */

598     public Principal JavaDoc getUserPrincipal() {
599         return principal;
600     }
601
602     /**
603      * Returns the session ID specified by the client.
604      *
605      */

606     public String JavaDoc getRequestedSessionId() {
607         HttpSession JavaDoc session = getSession();
608         return (session == null)
609             ? null
610             : session.getId();
611     }
612
613     /**
614      * Returns the part of this request's URL from the protocol name up to the
615      * query string in the first line of the HTTP request.
616      *
617      */

618     public String JavaDoc getRequestURI() {
619         return requestedURI;
620     }
621
622     /**
623      *
624      *
625      */

626     public StringBuffer JavaDoc getRequestURL() {
627         return requestUrl;
628     }
629
630     /**
631      * Returns the part of this request's URL that calls the servlet.
632      *
633      */

634     public String JavaDoc getServletPath() {
635         return servletPath;
636     }
637
638     /**
639      * Returns the current HttpSession associated with this request or, if if
640      * there is no current session and create is true, returns a new session.
641      *
642      */

643     public HttpSession JavaDoc getSession(boolean create) {
644         if (! create && ! sessionCreated) {
645             return null;
646         }
647         return getSession();
648     }
649
650     /**
651      * Returns the current session associated with this request, or if the
652      * request does not have a session, creates one.
653      *
654      */

655     public HttpSession JavaDoc getSession() {
656         sessionCreated = true;
657         return session;
658     }
659
660     /**
661      * Checks whether the requested session ID is still valid.
662      *
663      */

664     public boolean isRequestedSessionIdValid() {
665         HttpSession JavaDoc session = getSession();
666         return (session != null);
667     }
668
669     /**
670      * Checks whether the requested session ID came in as a cookie.
671      *
672      */

673     public boolean isRequestedSessionIdFromCookie() {
674         return requestedSessionIdIsFromCookie;
675     }
676
677     /**
678      * Checks whether the requested session ID came in as part of the request
679      * URL.
680      *
681      */

682     public boolean isRequestedSessionIdFromURL() {
683         return !requestedSessionIdIsFromCookie;
684     }
685
686     /**
687      * Deprecated. As of Version 2.1 of the Java Servlet API, use
688      * isRequestedSessionIdFromURL() instead.
689      * @deprecated Method isRequestedSessionIdFromUrl is deprecated
690      *
691      * @return
692      */

693     public boolean isRequestedSessionIdFromUrl() {
694         return isRequestedSessionIdFromURL();
695     }
696
697     /////////////////////////////////////////////////////////////////////////
698
//
699
// implementation access
700
//
701
/////////////////////////////////////////////////////////////////////////
702
/*
703     public void setBytes(byte[] bytes) {
704         this.bin = new ByteArrayInputStream(bytes);
705     }
706 */

707     /**
708      *
709      *
710      */

711     public Map JavaDoc getParameterMap() {
712         return Collections.unmodifiableMap(parameters);
713     }
714
715     public void setServerName(String JavaDoc serverName) {
716         this.serverName = serverName;
717     }
718     public void setRemoteHost(String JavaDoc remoteHost) {
719         this.remoteHost = remoteHost;
720     }
721     public void setRemoteAddr(String JavaDoc remoteAddr) {
722         this.remoteAddr = remoteAddr;
723     }
724     public void setMethod(String JavaDoc method) {
725         this.method = method;
726     }
727     public void setPathInfo(String JavaDoc pathInfo) {
728         this.pathInfo = pathInfo;
729     }
730     public void setPathTranslated(String JavaDoc pathTranslated) {
731         this.pathTranslated = pathTranslated;
732     }
733     public void setContextPath(String JavaDoc contextPath) {
734         this.contextPath = contextPath;
735     }
736     public void setQueryString(String JavaDoc queryString) {
737         this.queryString = queryString;
738     }
739     public void setRemoteUser(String JavaDoc remoteUser) {
740         this.remoteUser = remoteUser;
741     }
742     public void setRequestedSessionId(String JavaDoc requestedSessionId) {
743         this.requestedSessionId = requestedSessionId;
744     }
745     public void setRequestURI(String JavaDoc requestedURI) {
746         this.requestedURI = requestedURI;
747     }
748     public void setServletPath(String JavaDoc servletPath) {
749         this.servletPath = servletPath;
750     }
751     public void setLocalName(String JavaDoc localName) {
752         this.localName = localName;
753     }
754     public void setLocalAddr(String JavaDoc localAddr) {
755         this.localAddr = localAddr;
756     }
757     public void setAuthType(String JavaDoc authType) {
758         this.authType = authType;
759     }
760     public void setProtocol(String JavaDoc protocol) {
761         this.protocol = protocol;
762     }
763     public void setScheme(String JavaDoc schema) {
764         this.schema = schema;
765     }
766
767     public void setRemotePort(int remotePort) {
768         this.remotePort = remotePort;
769     }
770     public void setLocalPort(int localPort) {
771         this.localPort = localPort;
772     }
773     public void setServerPort(int serverPort) {
774         this.serverPort = serverPort;
775     }
776
777     public void setContentType(String JavaDoc contentType) {
778         setHeader("Content-Type", contentType);
779     }
780     public void setHeader(String JavaDoc name, String JavaDoc value) {
781         List JavaDoc<String JavaDoc> valueList = headers.get(name);
782         if (valueList == null) {
783             valueList = new ArrayList JavaDoc<String JavaDoc>();
784             headers.put(name, valueList);
785         }
786         valueList.add(value);
787     }
788     /////////////////////////////////////////////////////////////////////////
789
//
790
// helpers
791
//
792
/////////////////////////////////////////////////////////////////////////
793

794     public void clearParameters() {
795         parameters.clear();
796     }
797
798     public void setupAddParameter(String JavaDoc key, String JavaDoc[] values) {
799         parameters.put(key, values);
800     }
801     public void setupAddParameter(String JavaDoc key, String JavaDoc value) {
802         setupAddParameter(key, new String JavaDoc[] { value });
803     }
804
805     public void clearAttributes() {
806         attributes.clear();
807     }
808
809     public void setSession(HttpSession JavaDoc session) {
810         this.session = session;
811     }
812
813     public Map JavaDoc<String JavaDoc, RequestDispatcher JavaDoc> getRequestDispatcherMap() {
814         return Collections.unmodifiableMap(requestDispatchers);
815     }
816
817     public void setRequestDispatcher(String JavaDoc path, RequestDispatcher JavaDoc dispatcher) {
818         if(dispatcher instanceof MockRequestDispatcher) {
819             ((MockRequestDispatcher)dispatcher).setPath(path);
820         }
821         requestDispatchers.put(path, dispatcher);
822     }
823
824     public void addLocale(Locale JavaDoc locale) {
825         locales.add(locale);
826     }
827
828     public void addLocales(List JavaDoc<Locale JavaDoc> localeList) {
829         locales.addAll(localeList);
830     }
831
832     public void addHeader(String JavaDoc key, String JavaDoc value) {
833         List JavaDoc<String JavaDoc> valueList = headers.get(key);
834         if (valueList == null) {
835             valueList = new ArrayList JavaDoc<String JavaDoc>();
836             headers.put(key, valueList);
837         }
838         valueList.add(value);
839     }
840     public void clearHeader(String JavaDoc key) {
841         headers.remove(key);
842     }
843
844     public void setRequestURL(String JavaDoc requestUrl) {
845         this.requestUrl = new StringBuffer JavaDoc(requestUrl);
846     }
847     public void setUserPrincipal(Principal JavaDoc principal) {
848         this.principal = principal;
849     }
850     public void addCookie(Cookie JavaDoc cookie) {
851         cookies.add(cookie);
852     }
853
854     public void setRequestedSessionIdFromCookie(boolean requestedSessionIdIsFromCookie) {
855         this.requestedSessionIdIsFromCookie = requestedSessionIdIsFromCookie;
856     }
857     public void setUserInRole(String JavaDoc role, boolean isInRole) {
858         roles.put(role, isInRole);
859     }
860
861     public void setBodyContent(byte[] data) {
862         setBodyContent(new String JavaDoc(data));
863     }
864
865     public void setBodyContent(String JavaDoc bodyContent) {
866         this.bodyContent = bodyContent;
867     }
868
869
870 }
871
Popular Tags