Source Code Cross Referenced for ServletTester.java in  » Sevlet-Container » jetty-extras » org » mortbay » jetty » testing » 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 » Sevlet Container » jetty extras » org.mortbay.jetty.testing 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.mortbay.jetty.testing;
002:
003:        import java.util.Enumeration;
004:        import java.util.EventListener;
005:
006:        import org.mortbay.jetty.LocalConnector;
007:        import org.mortbay.jetty.Server;
008:        import org.mortbay.jetty.servlet.Context;
009:        import org.mortbay.jetty.servlet.FilterHolder;
010:        import org.mortbay.jetty.servlet.ServletHolder;
011:        import org.mortbay.util.Attributes;
012:
013:        /* ------------------------------------------------------------ */
014:        /** Testing support for servlets and filters.
015:         * 
016:         * Allows a programatic setup of a context with servlets and filters for 
017:         * testing.  Raw HTTP requests may be sent to the context and responses received.
018:         * To avoid handling raw HTTP see {@link org.mortbay.jetty.testing.HttpTester}.
019:         * <pre>
020:         *      ServletTester tester=new ServletTester();
021:         *      tester.setContextPath("/context");
022:         *      tester.addServlet(TestServlet.class, "/servlet/*");
023:         *      tester.addServlet("org.mortbay.jetty.servlet.DefaultServlet", "/");
024:         *      tester.start();
025:         *      String response = tester.getResponses("GET /context/servlet/info HTTP/1.0\r\n\r\n");
026:         * </pre>
027:         * 
028:         * @see org.mortbay.jetty.testing.HttpTester
029:         * @author gregw
030:         *
031:         */
032:        public class ServletTester {
033:            Server server = new Server();
034:            LocalConnector connector = new LocalConnector();
035:            Context context = new Context(Context.SESSIONS | Context.SECURITY);
036:
037:            public ServletTester() {
038:                try {
039:                    server.setSendServerVersion(false);
040:                    server.addConnector(connector);
041:                    server.addHandler(context);
042:                } catch (Error e) {
043:                    throw e;
044:                } catch (RuntimeException e) {
045:                    throw e;
046:                } catch (Exception e) {
047:                    throw new RuntimeException(e);
048:                }
049:            }
050:
051:            /* ------------------------------------------------------------ */
052:            public void start() throws Exception {
053:                server.start();
054:            }
055:
056:            /* ------------------------------------------------------------ */
057:            public void stop() throws Exception {
058:                server.stop();
059:            }
060:
061:            /* ------------------------------------------------------------ */
062:            /** Get raw HTTP responses from raw HTTP requests.
063:             * Multiple requests and responses may be handled, but only if
064:             * persistent connections conditions apply.
065:             * @param rawRequests String of raw HTTP requests
066:             * @return String of raw HTTP responses
067:             * @throws Exception
068:             */
069:            public String getResponses(String rawRequests) throws Exception {
070:                connector.reopen();
071:                //System.err.println(">>>>\n"+rawRequests);
072:                String responses = connector.getResponses(rawRequests);
073:                //System.err.println("<<<<\n"+responses);
074:                return responses;
075:            }
076:
077:            /* ------------------------------------------------------------ */
078:            /**
079:             * @param listener
080:             * @see org.mortbay.jetty.handler.ContextHandler#addEventListener(java.util.EventListener)
081:             */
082:            public void addEventListener(EventListener listener) {
083:                context.addEventListener(listener);
084:            }
085:
086:            /* ------------------------------------------------------------ */
087:            /**
088:             * @param filterClass
089:             * @param pathSpec
090:             * @param dispatches
091:             * @return
092:             * @see org.mortbay.jetty.servlet.Context#addFilter(java.lang.Class, java.lang.String, int)
093:             */
094:            public FilterHolder addFilter(Class filterClass, String pathSpec,
095:                    int dispatches) {
096:                return context.addFilter(filterClass, pathSpec, dispatches);
097:            }
098:
099:            /* ------------------------------------------------------------ */
100:            /**
101:             * @param filterClass
102:             * @param pathSpec
103:             * @param dispatches
104:             * @return
105:             * @see org.mortbay.jetty.servlet.Context#addFilter(java.lang.String, java.lang.String, int)
106:             */
107:            public FilterHolder addFilter(String filterClass, String pathSpec,
108:                    int dispatches) {
109:                return context.addFilter(filterClass, pathSpec, dispatches);
110:            }
111:
112:            /* ------------------------------------------------------------ */
113:            /**
114:             * @param servlet
115:             * @param pathSpec
116:             * @return
117:             * @see org.mortbay.jetty.servlet.Context#addServlet(java.lang.Class, java.lang.String)
118:             */
119:            public ServletHolder addServlet(Class servlet, String pathSpec) {
120:                return context.addServlet(servlet, pathSpec);
121:            }
122:
123:            /* ------------------------------------------------------------ */
124:            /**
125:             * @param className
126:             * @param pathSpec
127:             * @return
128:             * @see org.mortbay.jetty.servlet.Context#addServlet(java.lang.String, java.lang.String)
129:             */
130:            public ServletHolder addServlet(String className, String pathSpec) {
131:                return context.addServlet(className, pathSpec);
132:            }
133:
134:            /* ------------------------------------------------------------ */
135:            /**
136:             * @param name
137:             * @return
138:             * @see org.mortbay.jetty.handler.ContextHandler#getAttribute(java.lang.String)
139:             */
140:            public Object getAttribute(String name) {
141:                return context.getAttribute(name);
142:            }
143:
144:            /* ------------------------------------------------------------ */
145:            /**
146:             * @return
147:             * @see org.mortbay.jetty.handler.ContextHandler#getAttributeNames()
148:             */
149:            public Enumeration getAttributeNames() {
150:                return context.getAttributeNames();
151:            }
152:
153:            /* ------------------------------------------------------------ */
154:            /**
155:             * @return
156:             * @see org.mortbay.jetty.handler.ContextHandler#getAttributes()
157:             */
158:            public Attributes getAttributes() {
159:                return context.getAttributes();
160:            }
161:
162:            /* ------------------------------------------------------------ */
163:            /**
164:             * @return
165:             * @see org.mortbay.jetty.handler.ContextHandler#getResourceBase()
166:             */
167:            public String getResourceBase() {
168:                return context.getResourceBase();
169:            }
170:
171:            /* ------------------------------------------------------------ */
172:            /**
173:             * @param name
174:             * @param value
175:             * @see org.mortbay.jetty.handler.ContextHandler#setAttribute(java.lang.String, java.lang.Object)
176:             */
177:            public void setAttribute(String name, Object value) {
178:                context.setAttribute(name, value);
179:            }
180:
181:            /* ------------------------------------------------------------ */
182:            /**
183:             * @param classLoader
184:             * @see org.mortbay.jetty.handler.ContextHandler#setClassLoader(java.lang.ClassLoader)
185:             */
186:            public void setClassLoader(ClassLoader classLoader) {
187:                context.setClassLoader(classLoader);
188:            }
189:
190:            /* ------------------------------------------------------------ */
191:            /**
192:             * @param contextPath
193:             * @see org.mortbay.jetty.handler.ContextHandler#setContextPath(java.lang.String)
194:             */
195:            public void setContextPath(String contextPath) {
196:                context.setContextPath(contextPath);
197:            }
198:
199:            /* ------------------------------------------------------------ */
200:            /**
201:             * @param eventListeners
202:             * @see org.mortbay.jetty.handler.ContextHandler#setEventListeners(java.util.EventListener[])
203:             */
204:            public void setEventListeners(EventListener[] eventListeners) {
205:                context.setEventListeners(eventListeners);
206:            }
207:
208:            /* ------------------------------------------------------------ */
209:            /**
210:             * @param resourceBase
211:             * @see org.mortbay.jetty.handler.ContextHandler#setResourceBase(java.lang.String)
212:             */
213:            public void setResourceBase(String resourceBase) {
214:                context.setResourceBase(resourceBase);
215:            }
216:
217:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.