Source Code Cross Referenced for WebRequestImpl.java in  » Testing » jakarta-cactus » org » apache » cactus » internal » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta cactus » org.apache.cactus.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2001-2004 The Apache Software Foundation.
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         * 
018:         * ========================================================================
019:         */
020:        package org.apache.cactus.internal;
021:
022:        import java.net.HttpURLConnection;
023:        import java.util.StringTokenizer;
024:
025:        import org.apache.cactus.Cookie;
026:        import org.apache.cactus.HttpSessionCookie;
027:        import org.apache.cactus.ServletURL;
028:        import org.apache.cactus.WebResponse;
029:        import org.apache.cactus.internal.client.ClientException;
030:        import org.apache.cactus.internal.client.WebResponseObjectFactory;
031:        import org.apache.cactus.internal.client.connector.http.HttpClientConnectionHelper;
032:        import org.apache.cactus.internal.configuration.WebConfiguration;
033:        import org.apache.cactus.util.ChainedRuntimeException;
034:
035:        /**
036:         * Extends {@link BaseWebRequest} to add properties specific to the
037:         * Cactus Web Redirectors.
038:         *
039:         * @version $Id: WebRequestImpl.java 238991 2004-05-22 11:34:50Z vmassol $
040:         */
041:        public class WebRequestImpl extends BaseWebRequest {
042:            /**
043:             * The URL to simulate
044:             */
045:            private ServletURL url;
046:
047:            /**
048:             * Automatic session creation flag (default is true).
049:             */
050:            private boolean isAutomaticSession = true;
051:
052:            /**
053:             * Redirector Name. This is to let the user the possibility to override
054:             * the default Redirector Name specified in <code>cactus.properties</code>.
055:             */
056:            private String redirectorName;
057:
058:            /**
059:             * Default constructor that requires that 
060:             * {@link #setConfiguration(Configuration)} be called before the methods
061:             * requiring a configuration object.
062:             * 
063:             */
064:            public WebRequestImpl() {
065:            }
066:
067:            /**
068:             * @param theConfiguration the Cactus configuration
069:             */
070:            public WebRequestImpl(WebConfiguration theConfiguration) {
071:                super (theConfiguration);
072:            }
073:
074:            /**
075:             * @see org.apache.cactus.WebRequest#setRedirectorName(String)
076:             */
077:            public void setRedirectorName(String theRedirectorName) {
078:                this .redirectorName = theRedirectorName;
079:            }
080:
081:            /**
082:             * @see org.apache.cactus.WebRequest#getRedirectorName()
083:             */
084:            public String getRedirectorName() {
085:                return this .redirectorName;
086:            }
087:
088:            /**
089:             * @see org.apache.cactus.WebRequest#setAutomaticSession(boolean)
090:             */
091:            public void setAutomaticSession(boolean isAutomaticSession) {
092:                this .isAutomaticSession = isAutomaticSession;
093:            }
094:
095:            /**
096:             * @see org.apache.cactus.WebRequest#getAutomaticSession()
097:             */
098:            public boolean getAutomaticSession() {
099:                return this .isAutomaticSession;
100:            }
101:
102:            /**
103:             * @see org.apache.cactus.WebRequest#setURL(String, String, String, String, String)
104:             */
105:            public void setURL(String theServerName, String theContextPath,
106:                    String theServletPath, String thePathInfo,
107:                    String theQueryString) {
108:                this .url = new ServletURL(theServerName, theContextPath,
109:                        theServletPath, thePathInfo, theQueryString);
110:
111:                // Now automatically add all HTTP parameters to the list of passed
112:                // parameters
113:                addQueryStringParameters(theQueryString);
114:            }
115:
116:            /**
117:             * @see org.apache.cactus.WebRequest#getURL()
118:             */
119:            public ServletURL getURL() {
120:                return this .url;
121:            }
122:
123:            /**
124:             * @return a string representation of the request
125:             */
126:            public String toString() {
127:                StringBuffer buffer = new StringBuffer();
128:
129:                buffer.append("simulation URL = [" + getURL() + "], ");
130:                buffer.append("automatic session = [" + getAutomaticSession()
131:                        + "], ");
132:
133:                buffer.append(super .toString());
134:
135:                return buffer.toString();
136:            }
137:
138:            /**
139:             * Extract the HTTP parameters that might have been specified on the
140:             * query string and add them to the list of parameters to pass to the
141:             * servlet redirector.
142:             *
143:             * @param theQueryString the Query string in the URL to simulate, i.e. this
144:             *                       is the string that will be returned by the
145:             *                       <code>HttpServletResquest.getQueryString()</code>.
146:             *                       Can be null.
147:             */
148:            private void addQueryStringParameters(String theQueryString) {
149:                if (theQueryString == null) {
150:                    return;
151:                }
152:
153:                String nameValue = null;
154:                StringTokenizer tokenizer = new StringTokenizer(theQueryString,
155:                        "&");
156:                int breakParam = -1;
157:
158:                while (tokenizer.hasMoreTokens()) {
159:                    nameValue = tokenizer.nextToken();
160:                    breakParam = nameValue.indexOf("=");
161:
162:                    if (breakParam != -1) {
163:                        addParameter(nameValue.substring(0, breakParam),
164:                                nameValue.substring(breakParam + 1));
165:                    } else {
166:                        throw new RuntimeException("Bad QueryString ["
167:                                + theQueryString + "] NameValue pair: ["
168:                                + nameValue + "]");
169:                    }
170:                }
171:            }
172:
173:            /**
174:             * @see org.apache.cactus.WebRequest#getSessionCookie()
175:             */
176:            public HttpSessionCookie getSessionCookie() {
177:                if (getConfiguration() == null) {
178:                    throw new ChainedRuntimeException(
179:                            "setConfiguration() should have "
180:                                    + "been called prior to calling getSessionCookie()");
181:                }
182:
183:                HttpClientConnectionHelper helper = new HttpClientConnectionHelper(
184:                        ((WebConfiguration) getConfiguration())
185:                                .getRedirectorURL(this ));
186:
187:                WebRequestImpl obtainSessionIdRequest = new WebRequestImpl(
188:                        (WebConfiguration) getConfiguration());
189:
190:                //Not sure whether I should be adding the service parameter to
191:                //this request (this) or to the obtainSessionIdRequest
192:                //seems obvious that it should be the obtainSessionIdRequest
193:                RequestDirectives directives = new RequestDirectives(
194:                        obtainSessionIdRequest);
195:                directives
196:                        .setService(ServiceEnumeration.CREATE_SESSION_SERVICE);
197:
198:                HttpURLConnection resultConnection;
199:                try {
200:                    resultConnection = helper.connect(obtainSessionIdRequest,
201:                            getConfiguration());
202:                } catch (Throwable e) {
203:                    throw new ChainedRuntimeException("Failed to connect to ["
204:                            + ((WebConfiguration) getConfiguration())
205:                                    .getRedirectorURL(this ) + "]", e);
206:                }
207:
208:                WebResponse response;
209:                try {
210:                    response = (WebResponse) new WebResponseObjectFactory(
211:                            resultConnection)
212:                            .getResponseObject(WebResponse.class.getName(),
213:                                    obtainSessionIdRequest);
214:                } catch (ClientException e) {
215:                    throw new ChainedRuntimeException("Failed to connect to ["
216:                            + ((WebConfiguration) getConfiguration())
217:                                    .getRedirectorURL(this ) + "]", e);
218:                }
219:
220:                Cookie cookie = response.getCookieIgnoreCase("jsessionid");
221:
222:                // TODO: Add a constructor to the Cookie class that takes a Cookie
223:                // as parameter.
224:
225:                HttpSessionCookie sessionCookie = null;
226:
227:                if (cookie != null) {
228:                    sessionCookie = new HttpSessionCookie(cookie.getDomain(),
229:                            cookie.getName(), cookie.getValue());
230:                    sessionCookie.setComment(cookie.getComment());
231:                    sessionCookie.setExpiryDate(cookie.getExpiryDate());
232:                    sessionCookie.setPath(cookie.getPath());
233:                    sessionCookie.setSecure(cookie.isSecure());
234:                }
235:
236:                return sessionCookie;
237:            }
238:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.