Source Code Cross Referenced for WebResponseObjectFactory.java in  » Testing » jakarta-cactus » org » apache » cactus » internal » client » 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.client 
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.client;
021:
022:        import java.lang.reflect.Method;
023:
024:        import java.net.HttpURLConnection;
025:        import java.net.URLConnection;
026:
027:        import org.apache.cactus.Request;
028:        import org.apache.cactus.WebRequest;
029:        import org.apache.cactus.WebResponse;
030:        import org.apache.cactus.spi.client.ResponseObjectFactory;
031:
032:        /**
033:         * Constructs Web response objects. Supports both Cactus
034:         * {@link org.apache.cactus.WebResponse} and HttpUnit 
035:         * <code>com.meterware.httpunit.WebResponse</code> response object creation.
036:         *
037:         * @version $Id: WebResponseObjectFactory.java 238991 2004-05-22 11:34:50Z vmassol $
038:         */
039:        public class WebResponseObjectFactory implements  ResponseObjectFactory {
040:            /**
041:             * Connection object used to connect to the Cactus server side. Required
042:             * to create the response object.  
043:             */
044:            private HttpURLConnection connection;
045:
046:            /**
047:             * @param theConnection the connection object used to connect to the 
048:             *        Cactus server side
049:             */
050:            public WebResponseObjectFactory(HttpURLConnection theConnection) {
051:                this .connection = theConnection;
052:            }
053:
054:            /**
055:             * @see ResponseObjectFactory#getResponseObject
056:             */
057:            public Object getResponseObject(String theClassName,
058:                    Request theRequest) throws ClientException {
059:                Object responseObject;
060:
061:                // Is it a Http Unit WebResponse ?
062:                if (theClassName.equals("com.meterware.httpunit.WebResponse")) {
063:                    responseObject = createHttpUnitWebResponse(this .connection);
064:
065:                    // Is it a Cactus WebResponse ?
066:                } else if (theClassName.equals("org.apache.cactus.WebResponse")) {
067:                    responseObject = new WebResponse((WebRequest) theRequest,
068:                            this .connection);
069:
070:                    // Is it an old HttpURLConnection (deprecated) ?
071:                } else if (theClassName.equals("java.net.HttpURLConnection")) {
072:                    responseObject = this .connection;
073:                } else {
074:                    // Else it is an error ...
075:                    throw new ClientException("Invalid parameter type ["
076:                            + theClassName + "]");
077:                }
078:
079:                return responseObject;
080:            }
081:
082:            /**
083:             * Create a HttpUnit <code>WebResponse</code> object by reflection (so
084:             * that we don't need the HttpUnit jar for users who are not using
085:             * the HttpUnit endXXX() signature).
086:             *
087:             * @param theConnection the HTTP connection that was used when connecting
088:             *        to the server side and which now contains the returned HTTP
089:             *        response that we will pass to HttpUnit so that it can construt
090:             *        a <code>com.meterware.httpunit.WebResponse</code> object.
091:             * @return a HttpUnit <code>WebResponse</code> object
092:             * @exception ClientException if it failes to create a HttpClient
093:             *            WebResponse object for any reason
094:             */
095:            private Object createHttpUnitWebResponse(
096:                    HttpURLConnection theConnection) throws ClientException {
097:                Object webResponse;
098:
099:                try {
100:                    Class responseClass = Class
101:                            .forName("com.meterware.httpunit.WebResponse");
102:                    Method method = responseClass.getMethod("newResponse",
103:                            new Class[] { URLConnection.class });
104:
105:                    webResponse = method.invoke(null,
106:                            new Object[] { theConnection });
107:                } catch (Exception e) {
108:                    throw new ClientException(
109:                            "Error calling "
110:                                    + "[public static com.meterware.httpunit.WebResponse "
111:                                    + "com.meterware.httpunit.WebResponse.newResponse("
112:                                    + "java.net.URLConnection) throws java.io.IOException]",
113:                            e);
114:                }
115:
116:                return webResponse;
117:            }
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.