Source Code Cross Referenced for LocalServletHandler.java in  » Web-Services » xins » org » xins » common » servlet » container » 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 » Web Services » xins » org.xins.common.servlet.container 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: LocalServletHandler.java,v 1.25 2007/09/18 08:45:09 agoubard Exp $
003:         *
004:         * Copyright 2003-2007 Orange Nederland Breedband B.V.
005:         * See the COPYRIGHT file for redistribution and use restrictions.
006:         */
007:        package org.xins.common.servlet.container;
008:
009:        import java.io.File;
010:        import java.io.IOException;
011:        import java.util.HashMap;
012:        import java.util.Map;
013:        import javax.servlet.ServletException;
014:        import javax.servlet.http.HttpServlet;
015:
016:        import org.xins.common.Log;
017:
018:        /**
019:         * This class allows to invoke a XINS API without using HTTP.
020:         *
021:         * Example:
022:         * <code>
023:         * LocalServletHandler handler = LocalServletHandler.getInstance("c:\\test\\myproject.war");
024:         * String xmlResult = handler.query("http://127.0.0.1:8080/myproject/?_function=MyFunction&gender=f&personLastName=Lee");
025:         * </code>
026:         *
027:         * @version $Revision: 1.25 $ $Date: 2007/09/18 08:45:09 $
028:         * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
029:         */
030:        public class LocalServletHandler {
031:
032:            /**
033:             * The Servlet started by this Servlet handler.
034:             */
035:            private HttpServlet _apiServlet;
036:
037:            /**
038:             * Creates a Servlet handler that allow to invoke a Servlet without starting
039:             * a HTTP server.
040:             *
041:             * @param warFile
042:             *    the location of the war file containing the Servlet, cannot be
043:             *    <code>null</code>.
044:             *
045:             * @throws ServletException
046:             *    if the Servlet cannot be created.
047:             */
048:            public LocalServletHandler(File warFile) throws ServletException {
049:                initServlet(warFile);
050:            }
051:
052:            /**
053:             * Creates a Servlet handler that allow to invoke a Servlet without starting
054:             * a HTTP server.
055:             *
056:             * @param servletClassName
057:             *    The name of the servlet's class to load, cannot be <code>null</code>.
058:             *
059:             * @throws ServletException
060:             *    if the Servlet cannot be created.
061:             */
062:            public LocalServletHandler(String servletClassName)
063:                    throws ServletException {
064:                initServlet(servletClassName);
065:            }
066:
067:            /**
068:             * Initializes the Servlet.
069:             *
070:             * @param warFile
071:             *    the location of the war file, cannot be <code>null</code>.
072:             *
073:             * @throws ServletException
074:             *    if the Servlet cannot be loaded.
075:             */
076:            public void initServlet(File warFile) throws ServletException {
077:                // create and initiliaze the Servlet
078:                Log.log_1503(warFile.getPath());
079:                try {
080:                    LocalServletConfig servletConfig = new LocalServletConfig(
081:                            warFile);
082:                    _apiServlet = (HttpServlet) Class.forName(
083:                            servletConfig.getServletClass()).newInstance();
084:                    _apiServlet.init(servletConfig);
085:                } catch (ServletException exception) {
086:                    Log.log_1508(exception);
087:                    throw exception;
088:                } catch (Exception exception) {
089:                    Log.log_1509(exception);
090:                    throw new ServletException(exception);
091:                }
092:            }
093:
094:            /**
095:             * Initializes the Servlet.
096:             *
097:             * @param servletClassName
098:             *    The name of the servlet's class to load, cannot be <code>null</code>.
099:             *
100:             * @throws ServletException
101:             *    if the Servlet cannot be loaded.
102:             */
103:            public void initServlet(String servletClassName)
104:                    throws ServletException {
105:                // create and initiliaze the Servlet
106:                //Log.log_1503(warFile.getPath());
107:                try {
108:                    _apiServlet = (HttpServlet) Class.forName(servletClassName)
109:                            .newInstance();
110:                    _apiServlet.init();
111:                } catch (ServletException exception) {
112:                    Log.log_1508(exception);
113:                    throw exception;
114:                } catch (Exception exception) {
115:                    Log.log_1509(exception);
116:                    throw new ServletException(exception);
117:                }
118:            }
119:
120:            /**
121:             * Gets the Servlet.
122:             *
123:             * @return
124:             *    the created Servlet or <code>null</code> if no Servlet was created.
125:             */
126:            public Object getServlet() {
127:                return _apiServlet;
128:            }
129:
130:            /**
131:             * Queries the Servlet with the specified URL.
132:             *
133:             * @param url
134:             *    the url query for the request.
135:             *
136:             * @return
137:             *    the servlet response.
138:             *
139:             * @throws IOException
140:             *    If the query is not handled correctly by the servlet.
141:             */
142:            public XINSServletResponse query(String url) throws IOException {
143:                return query("GET", url, null, new HashMap());
144:            }
145:
146:            /**
147:             * Queries the servlet with the specified method, URL, content and HTTP
148:             * headers.
149:             *
150:             * @param method
151:             *    the request method, cannot be <code>null</code>.
152:             *
153:             * @param url
154:             *    the url query for the request, if <code>null</code> then the /
155:             *    path is used as default with no parameters.
156:             *
157:             * @param data
158:             *    the data post for the request. <code>null</code> for HTTP GET queries.
159:             *
160:             * @param headers
161:             *    the HTTP headers passed with the query, cannot be <code>null</code>.
162:             *    The key and the value of the Map is String. The keys are all in
163:             *    uppercase.
164:             *
165:             * @return
166:             *    the servlet response.
167:             *
168:             * @throws IOException
169:             *    If the query is not handled correctly by the servlet.
170:             *
171:             * @since XINS 1.5.0
172:             */
173:            public XINSServletResponse query(String method, String url,
174:                    String data, Map headers) throws IOException {
175:
176:                Log.log_1504(url);
177:
178:                XINSServletRequest request = new XINSServletRequest(method,
179:                        url, data, headers);
180:                XINSServletResponse response = new XINSServletResponse();
181:                try {
182:                    _apiServlet.service(request, response);
183:                } catch (ServletException ex) {
184:                    Log.log_1505(ex);
185:                    throw new IOException(ex.getMessage());
186:                }
187:                Log.log_1506(response.getResult(), response.getStatus());
188:                return response;
189:            }
190:
191:            /**
192:             * Disposes the Servlet and closes this Servlet handler.
193:             */
194:            public void close() {
195:                Log.log_1507();
196:                _apiServlet.destroy();
197:            }
198:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.