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
<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
@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) {
//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
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
*/\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
}\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
* @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
}\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
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