Source Code Cross Referenced for TomcatServer.java in  » ESB » wso2-esb » org » wso2 » esb » transport » tomcat » 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 » ESB » wso2 esb » org.wso2.esb.transport.tomcat 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one
003:         *  or more contributor license agreements.  See the NOTICE file
004:         *  distributed with this work for additional information
005:         *  regarding copyright ownership.  The ASF licenses this file
006:         *  to you under the Apache License, Version 2.0 (the
007:         *  "License"); you may not use this file except in compliance
008:         *  with the License.  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,
013:         *  software distributed under the License is distributed on an
014:         *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         *  KIND, either express or implied.  See the License for the
016:         *  specific language governing permissions and limitations
017:         *  under the License.
018:         */
019:        package org.wso2.esb.transport.tomcat;
020:
021:        import org.apache.catalina.Context;
022:        import org.apache.catalina.Engine;
023:        import org.apache.catalina.Host;
024:        import org.apache.catalina.LifecycleException;
025:        import org.apache.catalina.connector.Connector;
026:        import org.apache.catalina.realm.MemoryRealm;
027:        import org.apache.catalina.startup.Embedded;
028:        import org.apache.commons.logging.Log;
029:        import org.apache.commons.logging.LogFactory;
030:        import org.apache.tomcat.util.IntrospectionUtils;
031:        import org.wso2.esb.ServiceBusConfiguration;
032:        import org.wso2.esb.ServiceBusConstants;
033:        import org.wso2.esb.ServiceBusException;
034:        import org.wso2.esb.ServiceBusManager;
035:        import org.wso2.esb.transport.WebServer;
036:        import org.wso2.esb.util.XmlConfigurationFactory;
037:        import org.wso2.utils.NetworkUtils;
038:
039:        import java.io.File;
040:        import java.net.InetAddress;
041:
042:        /**
043:         *
044:         */
045:
046:        public class TomcatServer implements  WebServer {
047:
048:            private static Log log = LogFactory.getLog(TomcatServer.class);
049:            private Embedded embedded;
050:
051:            public TomcatServer() {
052:                embedded = new Embedded();
053:            }
054:
055:            public void start() throws Exception {
056:                Engine engine;
057:                ServiceBusManager manager = ServiceBusManager.getInstance();
058:
059:                String esbHome = System
060:                        .getProperty(ServiceBusConstants.ESB_HOME);
061:
062:                String catalinaHome = new File(esbHome).getAbsolutePath()
063:                        + File.separator + "tomcat";
064:
065:                embedded.setCatalinaHome(catalinaHome);
066:                String webappsDir = esbHome + File.separator + "webapp";
067:                String docsDir = esbHome + File.separator + "docs";
068:                String samplesDir = esbHome + File.separator + "samples";
069:
070:                // set the memory realm
071:                MemoryRealm memRealm = new MemoryRealm();
072:                embedded.setRealm(memRealm);
073:
074:                // Create an engine
075:                String host = NetworkUtils.getLocalHostname();
076:                manager.setHost(host);
077:                engine = embedded.createEngine();
078:                engine.setName("Catalina");
079:                engine.setDefaultHost(manager.getHost());
080:                embedded.addEngine(engine);
081:
082:                // Create a default virtual host
083:                Host defaultHost = embedded.createHost(host, webappsDir);
084:                engine.addChild(defaultHost);
085:                String esbContextPath = XmlConfigurationFactory
086:                        .getXmlConfiguration(
087:                                ServiceBusConstants.ESB_WEB_XML_KEY)
088:                        .getUniqueValue(
089:                                "//ns:Mapping[@name=\"admin\"]/ns:ContextPath");
090:
091:                if (esbContextPath != null) {
092:                    if (esbContextPath.equals("/")) {
093:                        esbContextPath = "";
094:                    } else {
095:                        if (!esbContextPath.startsWith("/")) {
096:                            esbContextPath = "/" + esbContextPath;
097:                        }
098:                    }
099:                } else {
100:                    esbContextPath = "/esb";
101:                }
102:
103:                Context esbContext = embedded.createContext(esbContextPath,
104:                        new File(webappsDir).getAbsolutePath());
105:                defaultHost.addChild(esbContext);
106:
107:                Context docsContext = embedded.createContext("/docs", new File(
108:                        docsDir).getAbsolutePath());
109:                defaultHost.addChild(docsContext);
110:
111:                Context samplesContext = embedded.createContext("/samples",
112:                        new File(samplesDir).getAbsolutePath());
113:                defaultHost.addChild(samplesContext);
114:
115:                defaultHost.setDeployOnStartup(true);
116:                embedded.setUseNaming(true);
117:
118:                // add the ssl listner for https transport - admin console
119:                addSSLConnector();
120:
121:                // Start the embedded server
122:                try {
123:                    embedded.start();
124:                    log.info("Tomcat Server Started at  " + "https://" + host
125:                            + ":" + manager.getHttpsPort() + esbContextPath);
126:                } catch (Exception e) {
127:                    log.fatal("Error starting embedded tomcat server : " + e);
128:                    throw new ServiceBusException(e);
129:                }
130:
131:            }
132:
133:            private void addSSLConnector() {
134:                ServiceBusConfiguration esbConfiguration = ServiceBusConfiguration
135:                        .getInstance();
136:                ServiceBusManager manager = ServiceBusManager.getInstance();
137:                String portString = esbConfiguration
138:                        .getFirstProperty("AdminConsole.Port");
139:                if (portString != null) {
140:                    int port = Integer.parseInt(portString);
141:                    if (port > 0) {
142:                        manager.setHttpsPort(port);
143:                    }
144:                }
145:                String ksLocation = esbConfiguration
146:                        .getFirstProperty("AdminConsole.KeyStore.Location");
147:                String absKsLocation;
148:                if (!new File(ksLocation).isAbsolute()) {
149:                    absKsLocation = new File(System
150:                            .getProperty(ServiceBusConstants.ESB_HOME)
151:                            + File.separator + ksLocation).getAbsolutePath();
152:                } else {
153:                    absKsLocation = ksLocation;
154:                }
155:                String ksPassword = esbConfiguration
156:                        .getFirstProperty("AdminConsole.KeyStore.Password");
157:
158:                String sslProtocol = esbConfiguration
159:                        .getFirstProperty("AdminConsole.SslProtocol");
160:                String maxHttpHeaderSize = esbConfiguration
161:                        .getFirstProperty("AdminConsole.MaxHttpHeaderSize");
162:                String maxThreads = esbConfiguration
163:                        .getFirstProperty("AdminConsole.MaxThreads");
164:                String minSpareThreads = esbConfiguration
165:                        .getFirstProperty("AdminConsole.MinSpareThreads");
166:                String maxSpareThreads = esbConfiguration
167:                        .getFirstProperty("AdminConsole.MaxSpareThreads");
168:                String clientAuth = esbConfiguration
169:                        .getFirstProperty("AdminConsole.ClientAuth");
170:                String disableUploadTimeout = esbConfiguration
171:                        .getFirstProperty("AdminConsole.DisableUploadTimeout");
172:                String acceptCount = esbConfiguration
173:                        .getFirstProperty("AdminConsole.AcceptCount");
174:                // SSLConnector
175:                Connector sslConnector = embedded.createConnector(
176:                        (InetAddress) null, manager.getHttpsPort(), true);
177:                sslConnector.setScheme(ServiceBusConstants.HTTPS_TRANSPORT);
178:                if (ksPassword != null) {
179:                    IntrospectionUtils.setProperty(sslConnector, "keypass",
180:                            ksPassword);
181:                }
182:                if (ksLocation != null) {
183:                    IntrospectionUtils.setProperty(sslConnector, "keystore",
184:                            absKsLocation);
185:                }
186:                if (sslProtocol != null) {
187:                    IntrospectionUtils.setProperty(sslConnector, "sslProtocol",
188:                            sslProtocol);
189:                }
190:                if (maxHttpHeaderSize != null) {
191:                    IntrospectionUtils.setProperty(sslConnector,
192:                            "maxHttpHeaderSize", maxHttpHeaderSize);
193:                }
194:                if (maxThreads != null) {
195:                    IntrospectionUtils.setProperty(sslConnector, "maxThreads",
196:                            maxThreads);
197:                }
198:                if (maxSpareThreads != null) {
199:                    IntrospectionUtils.setProperty(sslConnector,
200:                            "maxSpareThreads", maxSpareThreads);
201:                }
202:                if (minSpareThreads != null) {
203:                    IntrospectionUtils.setProperty(sslConnector,
204:                            "minSpareThreads", minSpareThreads);
205:                }
206:                if (disableUploadTimeout != null) {
207:                    IntrospectionUtils.setProperty(sslConnector,
208:                            "disableUploadTimeout", disableUploadTimeout);
209:                }
210:                if (clientAuth != null) {
211:                    IntrospectionUtils.setProperty(sslConnector, "clientAuth",
212:                            clientAuth);
213:                }
214:                if (acceptCount != null) {
215:                    IntrospectionUtils.setProperty(sslConnector, "acceptCount",
216:                            acceptCount);
217:                }
218:                sslConnector.setEnableLookups(true);
219:                sslConnector.setSecure(true);
220:                embedded.addConnector(sslConnector);
221:            }
222:
223:            public void stop() throws Exception {
224:
225:                try {
226:                    embedded.stop();
227:                } catch (LifecycleException e) {
228:                    log
229:                            .error("Error occurred while stopping embedded tomcat server : "
230:                                    + e);
231:                }
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.