From 6faa301939aebc5efe5ff72b925bb9bfa2773543 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Tue, 15 Nov 2011 17:56:13 +0000 Subject: [PATCH] CSPACE-4526: Cleaning up some of the servlet initialization settings and log messages. --- .../jaxrs/CSpaceResteasyBootstrap.java | 17 +++++++--- .../src/main/webapp/WEB-INF/web.xml | 29 ++++++----------- ...CollectionSpaceServiceContextListener.java | 8 +++-- .../services/common/ResourceBase.java | 7 ++-- .../services/common/ServiceMain.java | 32 +++++++++++++++---- 5 files changed, 60 insertions(+), 33 deletions(-) diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CSpaceResteasyBootstrap.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CSpaceResteasyBootstrap.java index c7fcf7790..bc8108312 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CSpaceResteasyBootstrap.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CSpaceResteasyBootstrap.java @@ -28,11 +28,20 @@ public class CSpaceResteasyBootstrap extends ResteasyBootstrap { System.out.println("Resuming RESTEasy bootstrap initialization."); } - // Save a copy of the ServletContext inside our ServiceMain singleton - ServletContext servletContext = event.getServletContext(); - ServiceMain.getInstance(servletContext); //First access causes initialization of the Services' main class +// // Save a copy of the ServletContext inside our ServiceMain singleton +// ServletContext servletContext = event.getServletContext(); +// try { +// ServiceMain.getInstance(servletContext); //First access causes initialization of the Services' main class +// } catch (RuntimeException e) { +// e.printStackTrace(); +// //rethrow the exception +// throw e; +// } - // This call to super instantiates and initializes our JAX-RS application class (org.collectionspace.services.jaxrs.CollectionSpaceJaxRsApplication) + // + // This call to super instantiates and initializes our JAX-RS application class. + // The application class is org.collectionspace.services.jaxrs.CollectionSpaceJaxRsApplication. + // super.contextInitialized(event); CollectionSpaceJaxRsApplication app = (CollectionSpaceJaxRsApplication)deployment.getApplication(); diff --git a/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml b/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml index 9b3b0bb88..2bd365af9 100644 --- a/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml +++ b/services/JaxRsServiceProvider/src/main/webapp/WEB-INF/web.xml @@ -10,21 +10,6 @@ CollectionSpace Services - - BASIC CollectionSpace realm @@ -78,7 +63,11 @@ - + + - org.collectionspace.services.jaxrs.CSpaceResteasyBootstrap + org.collectionspace.services.common.CollectionSpaceServiceContextListener - + + - org.collectionspace.services.common.CollectionSpaceServiceContextListener + org.collectionspace.services.jaxrs.CSpaceResteasyBootstrap diff --git a/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceServiceContextListener.java b/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceServiceContextListener.java index 45dd1ad7e..add321433 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceServiceContextListener.java +++ b/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceServiceContextListener.java @@ -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) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java index 3d348503a..c11d19f6a 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java @@ -65,6 +65,10 @@ public abstract class ResourceBase //FIXME retrieve client type from configuration static ClientType CLIENT_TYPE; + /* + * 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 + * 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? + */ static { try { // I put this in a try-catch static block instead of file-level static var initializer so that static methods of @@ -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."); } } - - + //======================= CREATE ==================================================== @POST diff --git a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java index 761be0b62..446b915e5 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ServiceMain.java @@ -45,13 +45,15 @@ import org.slf4j.LoggerFactory; */ public class ServiceMain { + final Logger logger = LoggerFactory.getLogger(ServiceMain.class); /** * volatile is used here to assume about ordering (post JDK 1.5) */ private static volatile ServiceMain instance = null; - final Logger logger = LoggerFactory.getLogger(ServiceMain.class); + private static volatile boolean initFailed = false; + private NuxeoConnectorEmbedded nuxeoConnector; - private static ServletContext servletContext; + private static ServletContext servletContext = null; private String serverRootDir = null; private ServicesConfigReaderImpl servicesConfigReader; private TenantBindingConfigReaderImpl tenantBindingConfigReader; @@ -84,6 +86,10 @@ public class ServiceMain { } } + public boolean inServletContext() { + return ServiceMain.servletContext != null; + } + public static ServiceMain getInstance(ServletContext servletContext) { ServiceMain.servletContext = servletContext; return ServiceMain.getInstance(); @@ -95,12 +101,16 @@ public class ServiceMain { * @return */ public static ServiceMain getInstance() { - if (instance == null) { + if (instance == null && initFailed == false) { synchronized (ServiceMain.class) { - if (instance == null) { + if (instance == null && initFailed == false) { ServiceMain temp = new ServiceMain(); try { + //assume the worse + initFailed = true; temp.initialize(); + //celebrate success + initFailed = false; } catch (Exception e) { instance = null; if (e instanceof RuntimeException) { @@ -113,15 +123,20 @@ public class ServiceMain { } } } + + if (instance == null) { + throw new RuntimeException("Could not initialize the CollectionSpace services. Please see the CollectionSpace services log file(s) for details."); + } + return instance; } private void initialize() throws Exception { if (logger.isDebugEnabled() == true) { - System.out.print("Pausing 1 seconds for you to attached the debugger"); + System.out.print("Pausing 5 seconds for you to attached the debugger"); long startTime, currentTime; currentTime = startTime = System.currentTimeMillis(); - long stopTime = startTime + 1 * 1000; //5 seconds + long stopTime = startTime + 5 * 1000; //5 seconds do { if (currentTime % 1000 == 0) { System.out.print("."); @@ -149,6 +164,11 @@ public class ServiceMain { nuxeoConnector = NuxeoConnectorEmbedded.getInstance(); nuxeoConnector.initialize(getServicesConfigReader().getConfiguration().getRepositoryClient(), ServiceMain.servletContext); + } else { + // + // Exit if we don't have the correct/known client type + // + throw new RuntimeException("Unknown CollectionSpace services client type: " + getClientType()); } try { -- 2.47.3