svn commit r9382 - trunk/esb/java/modules/core/src/main/java/org/wso2/esb/transport/tomcat

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit r9382 - trunk/esb/java/modules/core/src/main/java/org/wso2/esb/transport/tomcat

svn-9
Author: indika
Date: Thu Nov  1 04:48:43 2007
New Revision: 9382

Modified:
   trunk/esb/java/modules/core/src/main/java/org/wso2/esb/transport/tomcat/StartUpServlet.java
Log:
fixed an issue when esb deploying  in the tomcat as a web application


Modified: trunk/esb/java/modules/core/src/main/java/org/wso2/esb/transport/tomcat/StartUpServlet.java
==============================================================================
--- trunk/esb/java/modules/core/src/main/java/org/wso2/esb/transport/tomcat/StartUpServlet.java (original)
+++ trunk/esb/java/modules/core/src/main/java/org/wso2/esb/transport/tomcat/StartUpServlet.java Thu Nov  1 04:48:43 2007
@@ -59,31 +59,27 @@
 
     public void init(ServletConfig servletConfig) throws ServletException {
 
-        ServiceBusManager serviceBusManager = ServiceBusManager.getInstance();
         ServletContext servletContext = servletConfig.getServletContext();
         if (TRUE.equals(servletContext.getAttribute(HAS_ALREADY_INIT))) {
             return;
         }
-        String esbhome = System.getProperty(ServiceBusConstants.ESB_HOME);
-        if (esbhome == null || "".equals(esbhome)) {
-            esbhome = servletConfig.getInitParameter(ServiceBusConstants.ESB_HOME);
-            if (esbhome != null) {
-                if (esbhome.endsWith("/")) {
-                    esbhome = esbhome.substring(0, esbhome.lastIndexOf("/"));
-                }
-                System.setProperty(ServiceBusConstants.ESB_HOME, esbhome);
-                try {
-                    URL url = new URL("file:" + esbhome + File.separator
-                        + ServiceBusConstants.ESB_CONF_DIRECTORY + "log4j.properties");
-                    PropertyConfigurator.configure(url);
-                } catch (MalformedURLException ignore) {
-                }
-            } else {
-                String msg = "esb.home had not set : startup failed";
-                log.fatal(msg);
-                throw new ServletException(msg);
+
+        String esbhome = resolveEsbHome(servletConfig);
+        if (esbhome != null || !"".equals(esbhome)) {
+            System.setProperty(ServiceBusConstants.ESB_HOME, esbhome);
+            ServiceBusManager.initSystemProperties();
+            try {
+                URL url = new URL("file:" + esbhome + File.separator
+                    + ServiceBusConstants.ESB_CONF_DIRECTORY + "log4j.properties");
+                PropertyConfigurator.configure(url);
+            } catch (MalformedURLException ignore) {
             }
+        } else {
+            String msg = "esb.home had not set : startup failed";
+            log.fatal(msg);
+            throw new ServletException(msg);
         }
+        ServiceBusManager serviceBusManager = ServiceBusManager.getInstance();            
         try {
             serviceBusManager.start();
         } catch (Exception e) {
@@ -131,4 +127,31 @@
             log.error("Error occurred while Shutting down WSO2 ESB : " + e);
         }
     }
+
+    private String resolveEsbHome(ServletConfig servletConfig) {
+        // If esb.home has provided as init-param,the it will take as esb home
+        String esbHomeAsParam = servletConfig.getInitParameter(ServiceBusConstants.ESB_HOME);
+        if (esbHomeAsParam != null) {
+            if (esbHomeAsParam.endsWith("/")) {
+                return esbHomeAsParam.substring(0, esbHomeAsParam.lastIndexOf("/"));
+            }
+        }
+        //if esb.home has set as a system property , then use it
+        String esbHome = System.getProperty(ServiceBusConstants.ESB_HOME);
+        //Setting the all required system properties
+        if (esbHome == null || "".equals(esbHome)) {
+            ServletContext servletContext = servletConfig.getServletContext();
+            //if esb.home stil can not find ,then resolve it using real path of the WEB-INF
+            String webinfPath = servletContext.getRealPath("WEB-INF");
+            if (webinfPath != null) {
+                esbHome = webinfPath.substring(0, webinfPath.lastIndexOf("webapp/WEB-INF"));
+                if (esbHome != null) {
+                    if (esbHome.endsWith("/")) {
+                        esbHome = esbHome.substring(0, esbHome.lastIndexOf("/"));
+                    }
+                }
+            }
+        }
+        return esbHome;
+    }
 }

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