Source Code Cross Referenced for HTTPServletStarter.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: HTTPServletStarter.java,v 1.26 2007/09/18 08:45:08 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.lang.reflect.Constructor;
011:        import javax.swing.JFrame;
012:
013:        /**
014:         * HTTP Server used to invoke the XINS Servlet.
015:         *
016:         * @version $Revision: 1.26 $ $Date: 2007/09/18 08:45:08 $
017:         * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
018:         */
019:        public class HTTPServletStarter {
020:
021:            /**
022:             * The default port number.
023:             */
024:            public static final int DEFAULT_PORT_NUMBER = 8080;
025:
026:            /**
027:             * Creates a new <code>HTTPServletStarter</code> for the specified WAR
028:             * file, on the default port, as a daemon thread.
029:             *
030:             * <p>A listener is started on the port immediately.
031:             *
032:             * @param warFile
033:             *    the WAR file of the application to deploy, cannot be
034:             *    <code>null</code>.
035:             *
036:             * @throws ServletException
037:             *    if the servlet cannot be initialized.
038:             *
039:             * @throws IOException
040:             *    if the servlet container cannot be started.
041:             */
042:            // Exception is thrown as ServletException is not in the classpath
043:            public HTTPServletStarter(File warFile) throws Exception {
044:                this (warFile, DEFAULT_PORT_NUMBER, true);
045:            }
046:
047:            /**
048:             * Creates a new <code>HTTPServletStarter</code> for the specified WAR
049:             * file, on the specified port, as a daemon thread.
050:             *
051:             * <p>A listener is started on the port immediately.
052:             *
053:             * @param warFile
054:             *    the WAR file of the application to deploy, cannot be
055:             *    <code>null</code>.
056:             *
057:             * @param port
058:             *    the port to run the web server on.
059:             *
060:             * @throws ServletException
061:             *    if the servlet cannot be initialized.
062:             *
063:             * @throws IOException
064:             *    if the servlet container cannot be started.
065:             */
066:            public HTTPServletStarter(File warFile, int port) throws Exception {
067:                this (warFile, port, true);
068:            }
069:
070:            /**
071:             * Creates a new <code>HTTPServletStarter</code> for the specified WAR
072:             * file, on the specified port, optionally as a daemon thread.
073:             *
074:             * <p>A listener is started on the port immediately.
075:             *
076:             * @param warFile
077:             *    The war file of the application to deploy, cannot be <code>null</code>.
078:             *
079:             * @param port
080:             *    The port of the web server, cannot be <code>null</code>.
081:             *
082:             * @param deamon
083:             *    <code>true</code> if the thread listening to connection should be a
084:             *    deamon thread, <code>false</code> otherwise.
085:             *
086:             * @throws ServletException
087:             *    if the servlet cannot be initialized.
088:             *
089:             * @throws IOException
090:             *    if the servlet container cannot be started.
091:             */
092:            public HTTPServletStarter(File warFile, int port, boolean deamon)
093:                    throws Exception {
094:                this (warFile, port, deamon,
095:                        ServletClassLoader.USE_WAR_EXTERNAL_LIB);
096:            }
097:
098:            /**
099:             * Creates a new <code>HTTPServletStarter</code> for the specified servlet
100:             * class, on the specified port, optionally as a daemon thread.
101:             *
102:             * <p>A listener is started on the port immediately.
103:             *
104:             * @param servletClassName
105:             *    The name of the servlet to load, cannot be <code>null</code>.
106:             *
107:             * @param port
108:             *    The port of the web server, cannot be <code>null</code>.
109:             *
110:             * @param deamon
111:             *    <code>true</code> if the thread listening to connection should be a
112:             *    deamon thread, <code>false</code> otherwise.
113:             *
114:             * @param loaderMode
115:             *    the way the ClassLoader should locate and load the classes.
116:             *    See {@link ServletClassLoader].
117:             *
118:             * @throws ServletException
119:             *    if the servlet cannot be initialized.
120:             *
121:             * @throws IOException
122:             *    if the servlet container cannot be started.
123:             *
124:             * @since XINS 2.1.
125:             */
126:            public HTTPServletStarter(File warFile, int port, boolean deamon,
127:                    int loaderMode) throws Exception {
128:
129:                // Create the servlet
130:                ClassLoader loader = ServletClassLoader.getServletClassLoader(
131:                        warFile, loaderMode);
132:
133:                Class[] constClasses = { File.class, Integer.TYPE, Boolean.TYPE };
134:                Object[] constArgs = { warFile, new Integer(port),
135:                        deamon ? Boolean.TRUE : Boolean.FALSE };
136:                try {
137:                    Class delegate = loader
138:                            .loadClass("org.xins.common.servlet.container.HTTPServletHandler");
139:                    Constructor constructor = delegate
140:                            .getConstructor(constClasses);
141:                    constructor.newInstance(constArgs);
142:                } catch (Exception ex) {
143:                    ex.printStackTrace();
144:                }
145:            }
146:
147:            /**
148:             * Creates a new <code>HTTPServletStarter</code> for the specified servlet
149:             * class, on the specified port, optionally as a daemon thread.
150:             *
151:             * <p>A listener is started on the port immediately.
152:             *
153:             * @param servletClassName
154:             *    The name of the servlet to load, cannot be <code>null</code>.
155:             *
156:             * @param port
157:             *    The port of the web server, cannot be <code>null</code>.
158:             *
159:             * @param deamon
160:             *    <code>true</code> if the thread listening to connection should be a
161:             *    deamon thread, <code>false</code> otherwise.
162:             *
163:             * @throws ServletException
164:             *    if the servlet cannot be initialized.
165:             *
166:             * @throws IOException
167:             *    if the servlet container cannot be started.
168:             */
169:            public HTTPServletStarter(String servletClassName, int port,
170:                    boolean deamon) throws Exception {
171:
172:                // Create the servlet
173:                Class[] constClasses = { String.class, Integer.TYPE,
174:                        Boolean.TYPE };
175:                Object[] constArgs = { servletClassName, new Integer(port),
176:                        Boolean.valueOf(deamon) };
177:                try {
178:                    Class delegate = getClass()
179:                            .getClassLoader()
180:                            .loadClass(
181:                                    "org.xins.common.servlet.container.HTTPServletHandler");
182:                    Constructor constructor = delegate
183:                            .getConstructor(constClasses);
184:                    constructor.newInstance(constArgs);
185:                } catch (Exception ex) {
186:                    ex.printStackTrace();
187:                }
188:            }
189:
190:            /**
191:             * Starts the Servlet container for the specific API.
192:             *
193:             * @param args
194:             *    The command line arguments, the first argument should be the location
195:             *    of the WAR file or the name of the class of the servlet to load,
196:             *    the optional second argument is the port number.
197:             *    If no port number is specified, 8080 is used as default.
198:             */
199:            public static void main(String[] args) {
200:
201:                CommandLineArguments cmdArgs = new CommandLineArguments(args);
202:                if (cmdArgs.getPort() == -1) {
203:                    try {
204:                        ClassLoader loader = ServletClassLoader
205:                                .getServletClassLoader(cmdArgs.getWarFile(),
206:                                        cmdArgs.getLoaderMode());
207:                        loader.loadClass("org.xins.common.spec.SpecGUI")
208:                                .newInstance();
209:                    } catch (Exception ex) {
210:                        ex.printStackTrace();
211:                    }
212:                } else {
213:                    if (cmdArgs.showGUI()) {
214:                        JFrame apiFrame = new JFrame();
215:                        new ConsoleGUI(apiFrame, cmdArgs);
216:                        apiFrame.setVisible(true);
217:                    }
218:                    try {
219:                        // Starts the server and wait for connections
220:                        new HTTPServletStarter(cmdArgs.getWarFile(), cmdArgs
221:                                .getPort(), false, cmdArgs.getLoaderMode());
222:                    } catch (Exception ioe) {
223:                        ioe.printStackTrace();
224:                    }
225:                }
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.