]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4526: Cleaning up some of the servlet initialization settings and log messages.
authorRichard Millet <richard.millet@berkeley.edu>
Tue, 15 Nov 2011 17:56:13 +0000 (17:56 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Tue, 15 Nov 2011 17:56:13 +0000 (17:56 +0000)
services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CSpaceResteasyBootstrap.java
services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml
services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceServiceContextListener.java
services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java
services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java

index c7fcf779079feb75ef3fad02caed4edf463a4cba..bc8108312079c1410234eaecc688e7bca09bc3d4 100644 (file)
@@ -28,11 +28,20 @@ public class CSpaceResteasyBootstrap extends ResteasyBootstrap {
                System.out.println("Resuming RESTEasy bootstrap initialization.");\r
        }\r
                \r
-       // Save a copy of the ServletContext inside our ServiceMain singleton\r
-               ServletContext servletContext = event.getServletContext();\r
-               ServiceMain.getInstance(servletContext); //First access causes initialization of the Services' main class\r
+//     // Save a copy of the ServletContext inside our ServiceMain singleton\r
+//             ServletContext servletContext = event.getServletContext();\r
+//             try {\r
+//                     ServiceMain.getInstance(servletContext); //First access causes initialization of the Services' main class\r
+//             } catch (RuntimeException e) {\r
+//                     e.printStackTrace();\r
+//                     //rethrow the exception\r
+//                     throw e;\r
+//             }\r
                \r
-               // This call to super instantiates and initializes our JAX-RS application class (org.collectionspace.services.jaxrs.CollectionSpaceJaxRsApplication)\r
+               //\r
+       // This call to super instantiates and initializes our JAX-RS application class.\r
+       // The application class is org.collectionspace.services.jaxrs.CollectionSpaceJaxRsApplication.\r
+       //\r
                super.contextInitialized(event);\r
                CollectionSpaceJaxRsApplication app = \r
                        (CollectionSpaceJaxRsApplication)deployment.getApplication();\r
index 9b3b0bb88209815da5333642ebb68f081cce3dc2..2bd365af98aac66e2bff12b3f7541031ddb70f11 100644 (file)
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">    \r
     <display-name>CollectionSpace Services</display-name>\r
        \r
-       <!--    \r
-    <security-constraint>\r
-        <web-resource-collection>\r
-            <web-resource-name>CollectionSpace Services</web-resource-name>\r
-            <url-pattern>/*</url-pattern>\r
-        </web-resource-collection>\r
-        <auth-constraint>\r
-            <role-name>*</role-name>\r
-        </auth-constraint>\r
-        <user-data-constraint>\r
-            <transport-guarantee>NONE</transport-guarantee>\r
-        </user-data-constraint>\r
-    </security-constraint>\r
-       -->\r
-\r
     <login-config>\r
         <auth-method>BASIC</auth-method>\r
         <realm-name>CollectionSpace realm</realm-name>\r
        </filter-mapping>\r
     \r
 \r
-    <!-- Listeners -->\r
+    <!--\r
+       ***\r
+       *** Servlet Context Listeners\r
+       ***\r
+    -->\r
 \r
     <!--\r
       - Loads the root application context of this web app at startup.\r
         <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>\r
     </listener-->\r
 \r
+       <!-- A general listener for the CollectionSpace services.  In particular, this listener starts the embedded Nuxeo EP server instance. -->\r
     <listener>\r
         <listener-class>\r
-            org.collectionspace.services.jaxrs.CSpaceResteasyBootstrap\r
+            org.collectionspace.services.common.CollectionSpaceServiceContextListener\r
         </listener-class>\r
     </listener>\r
-\r
+    \r
+       <!-- The CollectionSpace listener that starts up the RESTEasy/JAX-RS service framework. -->\r
     <listener>\r
         <listener-class>\r
-            org.collectionspace.services.common.CollectionSpaceServiceContextListener\r
+            org.collectionspace.services.jaxrs.CSpaceResteasyBootstrap\r
         </listener-class>\r
     </listener>\r
 \r
index 45dd1ad7e8215a1563568b72674a1fdb134238b7..add321433eebd6be199e730ff4fe1e649e0809b4 100644 (file)
@@ -18,12 +18,16 @@ public class CollectionSpaceServiceContextListener implements ServletContextList
     @Override
     public void contextInitialized(ServletContextEvent event) {
         try {
-            //create repository select to stop jboss from jamming
+            //create logging repository select to stop jboss from jamming
             //our log on top of theirs
 //            LogManager.setRepositorySelector(new CollectionSpaceLog4jRepositorySelector(),
 //                    null);
 
-            ServiceMain svcMain = ServiceMain.getInstance();
+               //
+               // Initialize/start the Nuxeo EP server instance and create/retrieve the service workspaces
+               //
+               ServletContext servletContext = event.getServletContext();
+            ServiceMain svcMain = ServiceMain.getInstance(servletContext);
             svcMain.retrieveAllWorkspaceIds();
 
         } catch (Exception e) {
index 3d348503ac9979b06e82232d1e84c760d8d14ac0..c11d19f6a008eafa8d87b85ce6295bd60c894488 100644 (file)
@@ -65,6 +65,10 @@ public abstract class ResourceBase
     //FIXME retrieve client type from configuration\r
     static ClientType CLIENT_TYPE;\r
 \r
+    /*\r
+     * REM - 11/14/2011 - I discovered this static block of code and don't understand why it exists.  However, a side-effect of this static block is that ServiceMain is trying\r
+     * to create a valid instance of entire CSpace services include an embedded Nuxeo instance.  This block of code seems goofy and unnecessary and probably should be removed?\r
+     */\r
     static {\r
         try {\r
             // I put this in a try-catch static block instead of file-level static var initializer so that static methods of\r
@@ -76,8 +80,7 @@ public abstract class ResourceBase
             System.out.println("Static initializer failed in ResourceBase because not running from deployment.  OK to use Resource classes statically for tests.");\r
         }\r
     }\r
-\r
-\r
+    \r
     //======================= CREATE ====================================================\r
     \r
     @POST\r
index 761be0b62a8ca1dc49919e18d7c0637171aab3a4..446b915e50bd67680e4080a69c27b32c10ec00ab 100644 (file)
@@ -45,13 +45,15 @@ import org.slf4j.LoggerFactory;
  */\r
 public class ServiceMain {\r
 \r
+    final Logger logger = LoggerFactory.getLogger(ServiceMain.class);\r
     /**\r
      * volatile is used here to assume about ordering (post JDK 1.5)\r
      */\r
     private static volatile ServiceMain instance = null;\r
-    final Logger logger = LoggerFactory.getLogger(ServiceMain.class);\r
+    private static volatile boolean initFailed = false;\r
+    \r
     private NuxeoConnectorEmbedded nuxeoConnector;\r
-    private static ServletContext servletContext;\r
+    private static ServletContext servletContext = null;\r
     private String serverRootDir = null;\r
     private ServicesConfigReaderImpl servicesConfigReader;\r
     private TenantBindingConfigReaderImpl tenantBindingConfigReader;\r
@@ -84,6 +86,10 @@ public class ServiceMain {
                }\r
     }\r
     \r
+    public boolean inServletContext() {\r
+       return ServiceMain.servletContext != null;\r
+    }\r
+    \r
     public static ServiceMain getInstance(ServletContext servletContext) {\r
        ServiceMain.servletContext = servletContext;\r
        return ServiceMain.getInstance();\r
@@ -95,12 +101,16 @@ public class ServiceMain {
      * @return\r
      */\r
     public static ServiceMain getInstance() {\r
-        if (instance == null) {\r
+        if (instance == null && initFailed == false) {\r
             synchronized (ServiceMain.class) {\r
-                if (instance == null) {\r
+                if (instance == null && initFailed == false) {\r
                     ServiceMain temp = new ServiceMain();\r
                     try {\r
+                       //assume the worse\r
+                       initFailed = true;\r
                         temp.initialize();\r
+                       //celebrate success\r
+                        initFailed = false;\r
                     } catch (Exception e) {\r
                         instance = null;\r
                         if (e instanceof RuntimeException) {\r
@@ -113,15 +123,20 @@ public class ServiceMain {
                 }\r
             }\r
         }\r
+        \r
+        if (instance == null) {\r
+               throw new RuntimeException("Could not initialize the CollectionSpace services.  Please see the CollectionSpace services log file(s) for details.");\r
+        }\r
+        \r
         return instance;\r
     }\r
 \r
     private void initialize() throws Exception {\r
        if (logger.isDebugEnabled() == true) {\r
-               System.out.print("Pausing 1 seconds for you to attached the debugger");\r
+               System.out.print("Pausing 5 seconds for you to attached the debugger");\r
                long startTime, currentTime;\r
                currentTime = startTime = System.currentTimeMillis();\r
-               long stopTime = startTime + 1 * 1000; //5 seconds\r
+               long stopTime = startTime + 5 * 1000; //5 seconds\r
                do {\r
                        if (currentTime % 1000 == 0) {\r
                                System.out.print(".");\r
@@ -149,6 +164,11 @@ public class ServiceMain {
             nuxeoConnector = NuxeoConnectorEmbedded.getInstance();\r
             nuxeoConnector.initialize(getServicesConfigReader().getConfiguration().getRepositoryClient(),\r
                        ServiceMain.servletContext);\r
+        } else {\r
+               //\r
+               // Exit if we don't have the correct/known client type\r
+               //\r
+               throw new RuntimeException("Unknown CollectionSpace services client type: " + getClientType());\r
         }\r
 \r
         try {\r