Author: asankha
Date: Sat May 10 07:37:32 2008
New Revision: 16775

Log:
add startup module, extremely sorry for missing this! :(


Added:
   trunk/esb/java/modules/startup/
   trunk/esb/java/modules/startup/pom.xml
   trunk/esb/java/modules/startup/src/
   trunk/esb/java/modules/startup/src/main/
   trunk/esb/java/modules/startup/src/main/java/
   trunk/esb/java/modules/startup/src/main/java/org/
   trunk/esb/java/modules/startup/src/main/java/org/wso2/
   trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/
   trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/ServiceBus.java
   
trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/ServiceBusConstants.java
   
trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/ServiceBusException.java
   trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/TomcatServer.java
   trunk/esb/java/modules/startup/src/main/resources/
   trunk/esb/java/modules/startup/src/main/resources/tomcat.properties

Added: trunk/esb/java/modules/startup/pom.xml
==============================================================================
--- (empty file)
+++ trunk/esb/java/modules/startup/pom.xml      Sat May 10 07:37:32 2008
@@ -0,0 +1,35 @@
+<!--
+  ~ Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<project
+        xmlns="http://maven.apache.org/POM/4.0.0";
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.wso2.esb</groupId>
+        <artifactId>wso2-esb</artifactId>
+        <version>SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.wso2.esb</groupId>
+    <artifactId>wso2-esb-startup</artifactId>
+
+    <name>WSO2 ESB - Startup</name>
+    <description>WSO2 Enterprise Service Bus (ESB) - Startup</description>
+    <packaging>jar</packaging>
+
+</project>

Added: trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/ServiceBus.java
==============================================================================
--- (empty file)
+++ trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/ServiceBus.java   
Sat May 10 07:37:32 2008
@@ -0,0 +1,88 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.wso2.esb;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.log4j.PropertyConfigurator;
+
+import java.io.File;
+
+
+/**
+ * This is the class invoked by the command line scripts wso2-esb.sh and 
wso2-esb-daemon.sh to
+ * invoke the TomcatServer that will start the ESB through the StartupServlet 
deployed on the
+ * embedded Tomcat
+ */
+
+public class ServiceBus {
+
+    private static Log log = LogFactory.getLog(ServiceBus.class);
+    private static final String JAVA_IO_TMP = "java.io.tmpdir";
+
+    public static void main(String[] args) {
+
+        PropertyConfigurator.configure("tomcat" + File.separator + "conf" +
+            File.separator + "tomcat-log4j.properties");
+
+        log.info("[ESB] Starting the WSO2 ESB ...");
+
+        // clean temporary / working directory
+        File tempDir = new File(System.getProperty(JAVA_IO_TMP));
+        if (tempDir.exists()) {
+            if (!deleteDir(tempDir)) {
+                log.warn("Was unable to delete temporary work directory : " + 
tempDir);
+            } else {
+                tempDir.mkdirs();
+            }
+        } else {
+            tempDir.mkdirs();
+        }
+
+        long before = System.currentTimeMillis();
+        try {
+            TomcatServer webServer = new TomcatServer();
+            webServer.start();
+            log.info("[ESB] WSO2 ESB started in " + 
(System.currentTimeMillis() - before) + " ms");
+        } catch (Exception e) {
+            log.fatal("Error starting the WSO2 ESB. See log for details", e);
+        }
+    }
+
+    /**
+     * Deletes all files and subdirectories under dir. Returns true if all 
deletions were successful.
+     * If a deletion fails, the method stops attempting to delete and returns 
false.
+     * @param dir directory to delete
+     * @return true if successful
+     */
+    public static boolean deleteDir(File dir) {
+        if (dir.isDirectory()) {
+            String[] children = dir.list();
+            for (int i = 0; i < children.length; i++) {
+                boolean success = deleteDir(new File(dir, children[i]));
+                if (!success) {
+                    return false;
+                }
+            }
+        }
+
+        // The directory is now empty so delete it
+        return dir.delete();
+    }
+}

Added: 
trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/ServiceBusConstants.java
==============================================================================
--- (empty file)
+++ 
trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/ServiceBusConstants.java
  Sat May 10 07:37:32 2008
@@ -0,0 +1,98 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.esb;
+
+import java.net.URI;
+import java.io.File;
+
+/*
+* ServiceBusConstants use by WSO2 ESB
+*/
+public final class ServiceBusConstants {
+
+    public static final String MESSAGE_MAP_KEY = "Message_Map_Key";
+    public static final String IN_MESSAGE_MAP_KEY = "IN_Message_Map_Key";
+    public static final String OUT_MESSAGE_MAP_KEY = "OUT_Message_Map_Key";
+    public static final String IN_FAULT_MESSAGE_MAP_KEY = 
"IN_FAULT_Message_Map_Key";
+    public static final String OUT_FAULT_MESSAGE_MAP_KEY = 
"OUT_FAULT_Message_Map_Key";
+    public static final String ADMIN_TRANSPORT = "admin/https";
+    public static final String HTTP_TRANSPORT = "http";
+    public static final String HTTPS_TRANSPORT = "https";
+
+    public static final String ADMIN_SERVICE_GROUP = "ESBAdmin";
+    public static final String ESB_INSTANCE = "WSO2 ESB";
+    public static final String ESB_XML_NAMESPACE = 
"http://www.wso2.org/projects/esb";;
+    public static final String ESB_WEB_XML_KEY = "ESB_WEB_XML_KEY";
+    public static final String ESB_HOME = "esb.home";
+
+    public static final String WELCOME_PAGE = "INDEX_HTML_FILE";
+    public static final String GENERATED_PAGES = "wso2esb.generated.pages";
+
+    // ServiceBusConstants for ESB registry
+    public static final int LOCAL_HOST_REGISTRY = 100;
+    public static final int REMOTE_HOST_REGISTRY = 101;
+    public static final int REGISTRY_MODE = LOCAL_HOST_REGISTRY;
+    // this will be overwritten if localRegistry parameter is set
+    public static final String LOCAL_REGISTRY_ROOT = "registry/";
+    public static final String REGISTRY_FILE = "file";
+    public static final String REGISTRY_FOLDER = "folder";
+    public static final URI folder =
+            URI.create("http://wso2.org/projects/esb/registry/types/folder";);
+    // use if the exact file type is not known
+    public static final URI file =
+            URI.create("http://wso2.org/projects/esb/registry/types/file";);
+
+
+    public static final String WSO2ESB_HB_CONFIG_KEY = 
"wso2esb_hb_configuration_key";
+
+    public static final String LOG4J_PROPS = "log4j.properties";
+    public static final String SERVER_XML = "server.xml";
+    public static final String SYNAPSE_XML = "synapse.xml";
+    public static final String RESOLVE_ROOT = "resolve.root";
+    public static final String AXIS2_XML = "axis2.xml";
+    public static final String AXIS2_REPO = "axis2.repo";
+    public static final String ESB_SERVER_WEB_XML = "server-web.xml";
+    public static final String UI_EXTENSIONS_CONFIG_XML = 
"conf/ui-extensions-config.xml";
+    public static final String HIBERNATE_CFG_XML = 
"conf/wso2esb.hibernate.cfg.xml";
+    public static final String ESB_CONF_DIRECTORY = "webapp" + File.separator 
+ "WEB-INF" + File.separator + "classes" + File.separator + "conf" + 
File.separator;
+    public static final String JMX_AGENT_NAME = "jmx.agent.name";
+    public static final String DEFAULT_JMX_AGENT_NAME = "org.wso2.esb";
+
+    public static String REGISTRY = "Registry";
+    public static String USERMANAGER_CONFIG = "UsermanagerConfig";
+    public static String CONFIGURATION = "configuration";
+    public static String DRIVER_CLASS = "driverClass";
+    public static String URL = "url";
+    public static String USERNAME = "username";
+    public static String PASSWORD = "password";
+    public static String IMPORT_ROOT = "importRoot";
+    public static String TYPE = "type";
+
+
+    public static class Logging {
+        public static String ESB_CONSOLE_APPENDER = "ESB_CONSOLE_APPENDER";
+        public static String ESB_LOG_FILE_APPENDER = "ESB_LOG_FILE_APPENDER";
+        public static String ESB_MEMORY_APPENDER = "ESB_MEMORY_APPENDER";
+    }
+
+    // ServiceBusConstants for DataBase Access
+    public static class DBAccess {
+        public static final String DERBY_NETWOEK_SERVER_DRIVER
+                = "org.apache.derby.jdbc.ClientDriver";
+        public static final String STATISTICS_DO = "StatisticsDO";
+    }
+}

Added: 
trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/ServiceBusException.java
==============================================================================
--- (empty file)
+++ 
trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/ServiceBusException.java
  Sat May 10 07:37:32 2008
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2006, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.esb;
+
+/*
+*
+*/
+public class ServiceBusException extends RuntimeException {
+
+    private static final long serialVersionUID = 5967324819038387267L;
+
+    public ServiceBusException() {
+        super();
+    }
+
+    public ServiceBusException(String message) {
+        super(message);
+    }
+
+    public ServiceBusException(Throwable cause) {
+        super(cause);
+    }
+
+    public ServiceBusException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Added: 
trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/TomcatServer.java
==============================================================================
--- (empty file)
+++ trunk/esb/java/modules/startup/src/main/java/org/wso2/esb/TomcatServer.java 
Sat May 10 07:37:32 2008
@@ -0,0 +1,199 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.wso2.esb;
+
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.LifecycleException;
+import org.apache.catalina.connector.Connector;
+import org.apache.catalina.realm.MemoryRealm;
+import org.apache.catalina.startup.Embedded;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.tomcat.util.IntrospectionUtils;
+
+
+import java.io.File;
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.Properties;
+
+/**
+ * The embedded Tomcat server that will host the ESB console
+ */
+
+public class TomcatServer {
+
+    private static Log log = LogFactory.getLog(TomcatServer.class);
+    private Embedded embedded;
+    private Properties props = null;
+
+    public TomcatServer() {
+        props = new Properties();
+        try {
+            
props.load(this.getClass().getClassLoader().getResourceAsStream("tomcat.properties"));
+        } catch (IOException ignore) {}
+        embedded = new Embedded();
+    }
+
+    /**
+     * Start the embedded Tomcat server
+     * @throws Exception on error
+     */
+    public void start() throws Exception {
+
+        log.info("Starting the embedded Tomcat server..");
+
+        embedded.setCatalinaHome(
+            new File(".").getAbsolutePath() + File.separator + "tomcat");
+
+        String webappsDir = "webapp";
+        String docsDir    = "docs";
+        String samplesDir = "samples";
+
+        // set the memory realm
+        MemoryRealm memRealm = new MemoryRealm();
+        embedded.setRealm(memRealm);
+
+        // Create an engine
+        String host = InetAddress.getLocalHost().getHostName();
+        Engine engine = embedded.createEngine();
+        engine.setName("Catalina");
+        engine.setDefaultHost(host);
+        embedded.addEngine(engine);
+
+        // Create a default virtual host
+        Host defaultHost = embedded.createHost(host, webappsDir);
+        engine.addChild(defaultHost);
+        String esbContextPath = getTomcatProperty("ContextPath", "/esb");
+
+        Context esbContext = embedded.createContext(esbContextPath, new 
File(webappsDir).getAbsolutePath());
+        defaultHost.addChild(esbContext);
+
+        Context docsContext = embedded.createContext("/docs", new 
File(docsDir).getAbsolutePath());
+        defaultHost.addChild(docsContext);
+
+        Context samplesContext = embedded.createContext("/samples", new 
File(samplesDir).getAbsolutePath());
+        defaultHost.addChild(samplesContext);
+
+        defaultHost.setDeployOnStartup(true);
+        embedded.setUseNaming(true);
+
+        // add the ssl listner for https transport - admin console
+        addSSLConnector();
+
+        // Start the embedded server
+        try {
+            embedded.start();
+            log.info("Tomcat Server started at " + "https://"; + host + ":"
+                + getTomcatProperty("ConsolePort", "9443") + esbContextPath);
+        } catch (Exception e) {
+            log.fatal("Error starting embedded Tomcat server : ", e);
+            throw new ServiceBusException(e);
+        }
+    }
+
+    private void addSSLConnector() {
+
+        String ksLocation = getTomcatProperty("KeyStore.Location", 
"webapp/WEB-INF/classes/conf/identity.jks");
+        String ksPassword = getTomcatProperty("KeyStore.Password", "password");
+
+        String absKsLocation;
+        if (!new File(ksLocation).isAbsolute()) {
+            absKsLocation = new File(ksLocation).getAbsolutePath();
+        } else {
+            absKsLocation = ksLocation;
+        }
+
+        String sslProtocol          = getTomcatProperty("SslProtocol");
+        String maxHttpHeaderSize    = getTomcatProperty("MaxHttpHeaderSize");
+        String maxThreads           = getTomcatProperty("MaxThreads");
+        String minSpareThreads      = getTomcatProperty("MinSpareThreads");
+        String maxSpareThreads      = getTomcatProperty("MaxSpareThreads");
+        String clientAuth           = getTomcatProperty("ClientAuth");
+        String disableUploadTimeout = 
getTomcatProperty("DisableUploadTimeout");
+        String acceptCount          = getTomcatProperty("AcceptCount");
+
+        // SSLConnector
+        Connector sslConnector = embedded.createConnector(
+            (InetAddress) null, 
Integer.parseInt(getTomcatProperty("ConsolePort", "9443")), true);
+        sslConnector.setScheme(ServiceBusConstants.HTTPS_TRANSPORT);
+
+        if (ksPassword != null) {
+            IntrospectionUtils.setProperty(sslConnector, "keypass", 
ksPassword);
+        }
+        if (ksLocation != null) {
+            IntrospectionUtils.setProperty(sslConnector, "keystore", 
absKsLocation);
+        }
+        if (sslProtocol != null) {
+            IntrospectionUtils.setProperty(sslConnector, "sslProtocol", 
sslProtocol);
+        }
+        if (maxHttpHeaderSize != null) {
+            IntrospectionUtils.setProperty(sslConnector, "maxHttpHeaderSize", 
maxHttpHeaderSize);
+        }
+        if (maxThreads != null) {
+            IntrospectionUtils.setProperty(sslConnector, "maxThreads", 
maxThreads);
+        }
+        if (maxSpareThreads != null) {
+            IntrospectionUtils.setProperty(sslConnector, "maxSpareThreads", 
maxSpareThreads);
+        }
+        if (minSpareThreads != null) {
+            IntrospectionUtils.setProperty(sslConnector, "minSpareThreads", 
minSpareThreads);
+        }
+        if (disableUploadTimeout != null) {
+            IntrospectionUtils.setProperty(sslConnector, 
"disableUploadTimeout", disableUploadTimeout);
+        }
+        if (clientAuth != null) {
+            IntrospectionUtils.setProperty(sslConnector, "clientAuth", 
clientAuth);
+        }
+        if (acceptCount != null) {
+            IntrospectionUtils.setProperty(sslConnector, "acceptCount", 
acceptCount);
+        }
+
+        sslConnector.setEnableLookups(true);
+        sslConnector.setSecure(true);
+        embedded.addConnector(sslConnector);
+    }
+
+    /**
+     * Stop the Tomcat server
+     */
+    public void stop() {
+        log.info("Stopping the embedded Tomcat server..");
+        try {
+            embedded.stop();
+        } catch (LifecycleException e) {
+            log.error("Error occurred while stopping the embedded Tomcat 
server", e);
+        }
+    }
+
+    private String getTomcatProperty(String key, String def) {
+        String res = props.getProperty(key);
+        if (res == null) {
+            return def;
+        } else {
+            return res;
+        }
+    }
+
+    private String getTomcatProperty(String key) {
+        return props.getProperty(key);
+    }
+}

Added: trunk/esb/java/modules/startup/src/main/resources/tomcat.properties
==============================================================================
--- (empty file)
+++ trunk/esb/java/modules/startup/src/main/resources/tomcat.properties Sat May 
10 07:37:32 2008
@@ -0,0 +1,11 @@
+# configuration for the embedded tomcat
+
+ConsolePort=9443
+ContextPath=/esb
+KeyStore.Location=webapp/WEB-INF/classes/conf/identity.jks
+KeyStore.Type=JKS
+KeyStore.Password=password
+KeyStore.KeyPassword=password
+TrustStore.Location=webapp/WEB-INF/classes/conf/trust.jks
+TrustStore.Type=JKS
+TrustStore.Password=password
\ No newline at end of file

_______________________________________________
Esb-java-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev

Reply via email to