From: Richard Millet Date: Fri, 11 Nov 2011 01:10:45 +0000 (+0000) Subject: CSPACE-4526: Updated client props to use port 8081 instead of 8180. Added code to... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=1dc399193e7cc4400184a8db9969e90268bf7b25;p=tmp%2Fjakarta-migration.git CSPACE-4526: Updated client props to use port 8081 instead of 8180. Added code to cache result from JNDI lookups -improves performance as well as shields us from some forms of JNDI overwrites/corruption. --- 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..9a1d87478 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 @@ -13,10 +13,10 @@ public class CSpaceResteasyBootstrap extends ResteasyBootstrap { // private static final String public void contextInitialized(ServletContextEvent event) { if (true) { - System.out.print("Pausing 1 seconds in RESTEasy bootstrap for you to attached the debugger"); + System.out.print("Pausing 10 seconds in RESTEasy bootstrap for you to attached the debugger"); long startTime, currentTime; currentTime = startTime = System.currentTimeMillis(); - long stopTime = startTime + 1 * 1000; //5 seconds + long stopTime = startTime + 10 * 1000; //5 seconds do { if (currentTime % 1000 == 0) { System.out.print("."); diff --git a/services/authority/pom.xml b/services/authority/pom.xml index eb504088b..a76f642f8 100644 --- a/services/authority/pom.xml +++ b/services/authority/pom.xml @@ -5,7 +5,7 @@ org.collectionspace.services org.collectionspace.services.main - 1.12-SNAPSHOT + 1.14-SNAPSHOT 4.0.0 @@ -14,9 +14,255 @@ services.authority pom - + + + + + + + + + log4j + log4j + 1.2.14 + provided + + + org.apache.commons + commons-jexl + 2.0.1 + + + commons-codec + commons-codec + 1.4 + + + + + javax.servlet + servlet-api + 2.5 + provided + + + + javax.security + jaas + 1.0.01 + provided + + + javax.security + jacc + 1.0 + provided + + + + mysql + mysql-connector-java + + + postgresql + postgresql + + + javax.persistence + persistence-api + + + + + org.jboss.resteasy + jaxrs-api + + + org.jboss.resteasy + resteasy-jaxrs + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + + org.hibernate + hibernate-entitymanager + + + + jboss + jbosssx + 4.2.3.GA + provided + + + jboss + jboss-remoting + 2.2.2.SP8 + provided + + + + + + + jaxb service - + + diff --git a/services/client/src/main/resources/collectionspace-client.properties b/services/client/src/main/resources/collectionspace-client.properties index 332c68654..eefe496f6 100644 --- a/services/client/src/main/resources/collectionspace-client.properties +++ b/services/client/src/main/resources/collectionspace-client.properties @@ -1,5 +1,5 @@ #url of the collectionspace server -cspace.url=http://localhost:8180/cspace-services/ +cspace.url=http://localhost:8081/cspace-services/ #cspace.url=http://nightly.collectionspace.org:8180/cspace-services/ #cspace.url=http://localhost:8200/cspace-services/ 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 2a11dd8cf..761be0b62 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 @@ -66,9 +66,6 @@ public class ServiceMain { private static final String DEFAULT_READER_PASSWORD = "reader"; private static final String SERVER_HOME_PROPERTY = "catalina.home"; - private static DataSource cspaceDataSource = null; - private static DataSource nuxeoDataSource = null; - private ServiceMain() { //empty } @@ -159,7 +156,7 @@ public class ServiceMain { // Invoke all post-initialization handlers, passing in a DataSource instance of the Nuxeo db. // Typically, these handlers modify column types and add indexes to the Nuxeo db schema. // - firePostInitHandlers(ServiceMain.nuxeoDataSource); + firePostInitHandlers(JDBCTools.getDataSource(JDBCTools.NUXEO_REPOSITORY_NAME)); } catch(Exception e) { logger.error("ServiceMain.initialize firePostInitHandlers failed on exception: " + e.getLocalizedMessage()); } @@ -638,7 +635,7 @@ public class ServiceMain { return null; } - private Connection getConnection() throws LoginException, SQLException { + private Connection getConnection() throws NamingException, SQLException { return JDBCTools.getConnection(JDBCTools.CSPACE_REPOSITORY_NAME); } @@ -679,8 +676,16 @@ public class ServiceMain { * static members. */ private void setDataSources() throws NamingException { - ServiceMain.cspaceDataSource = JDBCTools.getDataSource(JDBCTools.CSPACE_REPOSITORY_NAME); - ServiceMain.nuxeoDataSource = JDBCTools.getDataSource(JDBCTools.NUXEO_REPOSITORY_NAME); + // + // As a side-effect of calling JDBCTools.getDataSource(...), the DataSource instance will be + // cached in a static hash map of the JDBCTools class. This will speed up lookups as well as protect our + // code from JNDI lookup problems -for example, if the JNDI context gets stepped on or corrupted. + // + DataSource cspaceDataSource = JDBCTools.getDataSource(JDBCTools.CSPACE_REPOSITORY_NAME); + DataSource nuxeoDataSource = JDBCTools.getDataSource(JDBCTools.NUXEO_REPOSITORY_NAME); + // + // Set our AuthN's datasource to be the cspaceDataSource + // AuthN.setDataSource(cspaceDataSource); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/JDBCTools.java b/services/common/src/main/java/org/collectionspace/services/common/storage/JDBCTools.java index 01b4e2522..bf9e5310c 100755 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/JDBCTools.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/JDBCTools.java @@ -32,6 +32,7 @@ import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.HashMap; /** * User: laramie @@ -39,48 +40,62 @@ import java.sql.Statement; * $LastChangedDate: $ */ public class JDBCTools { + public static HashMap cachedDataSources = new HashMap(); public static String CSPACE_REPOSITORY_NAME = "CspaceDS"; public static String NUXEO_REPOSITORY_NAME = "NuxeoDS"; - public static String DEFAULT_REPOSITORY_NAME = NUXEO_REPOSITORY_NAME; + // + // Private constants + // + private static String DEFAULT_REPOSITORY_NAME = NUXEO_REPOSITORY_NAME; private static String DBProductName = null; private static DatabaseProductType DBProductType = DatabaseProductType.UNRECOGNIZED; //todo: make sure this will get instantiated in the right order final static Logger logger = LoggerFactory.getLogger(JDBCTools.class); - + public static DataSource getDataSource(String repositoryName) throws NamingException { DataSource result = null; - InitialContext ctx = new InitialContext(); - Context envCtx = null; - if (logger.isDebugEnabled() == true) { - logger.debug("Looking up datasource in JNDI with name: " + repositoryName); - } - - try { - envCtx = (Context) ctx.lookup("java:comp/env"); - DataSource ds = (DataSource) envCtx.lookup("jdbc/" + repositoryName); - if (ds == null) { - throw new IllegalArgumentException("datasource not found: " + repositoryName); - } else { - result = ds; + // + // First, see if we already have this DataSource instance cached + // + result = cachedDataSources.get(repositoryName); + if (result == null) { + InitialContext ctx = new InitialContext(); + Context envCtx = null; + + if (logger.isDebugEnabled() == true) { + logger.debug("Looking up DataSource instance in JNDI with name: " + repositoryName); } - } finally { - if (ctx != null) { - try { - ctx.close(); - } catch (Exception e) { - logger.error("Error getting DataSource for: " + repositoryName, e); - } - } - if (envCtx != null) { - try { - envCtx.close(); - } catch (Exception e) { - logger.error("Error getting DataSource for: " + repositoryName, e); - } - } + + try { + envCtx = (Context) ctx.lookup("java:comp/env"); + DataSource ds = (DataSource) envCtx.lookup("jdbc/" + repositoryName); + if (ds == null) { + throw new IllegalArgumentException("DataSource instance not found: " + repositoryName); + } else { + result = ds; + // now cache this DataSource instance for future references + cachedDataSources.put(repositoryName, result); + } + } finally { + if (ctx != null) { + try { + ctx.close(); + } catch (Exception e) { + logger.error("Error getting DataSource for: " + repositoryName, e); + } + } + if (envCtx != null) { + try { + envCtx.close(); + } catch (Exception e) { + logger.error("Error getting DataSource for: " + repositoryName, e); + } + } + } } + return result; } @@ -93,30 +108,23 @@ public class JDBCTools { return result; } - public static Connection getConnection(String repositoryName) throws LoginException, SQLException { + public static Connection getConnection(String repositoryName) throws NamingException, SQLException { Connection result = null; if (Tools.isEmpty(repositoryName)) { repositoryName = getDefaultRepositoryName(); + if (logger.isWarnEnabled() == true) { + logger.warn("getConnection() method was called with an empty or null repository name. Using " + repositoryName + " instead."); + } } - Connection conn = null; - try { - DataSource ds = getDataSource(repositoryName); - conn = ds.getConnection(); - result = conn; - } catch (NamingException ex) { - LoginException le = new LoginException("Error looking up DataSource from: " + repositoryName); - le.initCause(ex); - throw le; - } catch (SQLException e) { - throw e; - } + DataSource ds = getDataSource(repositoryName); + Connection conn = getConnection(ds); + result = conn; return result; } - /* THIS IS BROKEN - If you close the statement, it closes the ResultSet!!! public static ResultSet executeQuery(String repoName, String sql) throws Exception { Connection conn = null; @@ -242,7 +250,7 @@ public class JDBCTools { return DBProductType; } - public static String getDefaultRepositoryName() { + private static String getDefaultRepositoryName() { return DEFAULT_REPOSITORY_NAME; } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index 5339dcbe5..85b2bf114 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -609,7 +609,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient in updateLastID"); @@ -298,6 +300,7 @@ public class IDServiceJdbcImpl implements IDService { conn.close(); } } catch (SQLException e) { + logger.error("Error closing JDBC connection: ", e); // Do nothing here } } @@ -935,14 +938,14 @@ public class IDServiceJdbcImpl implements IDService { * @throws LoginException * @throws SQLException if a storage-related error occurred. */ - public Connection getJdbcConnection() throws LoginException, SQLException { + public Connection getJdbcConnection() throws NamingException, SQLException { logger.debug("> in getJdbcConnection"); Connection conn = null; try { conn = JDBCTools.getConnection(JDBCTools.NUXEO_REPOSITORY_NAME); - } catch (LoginException e) { + } catch (NamingException e) { throw e; } catch (SQLException e) { throw e; diff --git a/services/pom.xml b/services/pom.xml index c7c4c1b44..5508476d1 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -30,7 +30,9 @@ common-api authentication authorization + client jaxb hyperjaxb @@ -52,7 +54,9 @@ intake loanin loanout + objectexit batch imports diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java index af72ae538..048da5ab6 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationValidatorHandler.java @@ -10,14 +10,11 @@ import org.collectionspace.services.common.api.RefName.AuthorityItem; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.relation.RelationsCommon; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; //import org.testng.Assert; -public class RelationValidatorHandler extends ValidatorHandlerImpl { +public class RelationValidatorHandler extends ValidatorHandlerImpl { /** The logger. */ private final Logger logger = LoggerFactory.getLogger(RelationValidatorHandler.class); @@ -25,74 +22,74 @@ public class RelationValidatorHandler extends ValidatorHandlerImpl getCommonPartClass() { - return RelationsCommon.class; + return RelationsCommon.class; } - + @Override protected void handleCreate() - throws InvalidDocumentException { - try { - RelationsCommon relationsCommon = (RelationsCommon) getCommonPart(); - assert (relationsCommon != null); - if (logger.isTraceEnabled() == true) { - logger.trace(relationsCommon.toString()); - } - + throws InvalidDocumentException{ + try { + RelationsCommon relationsCommon = (RelationsCommon)getCommonPart(); + CS_ASSERT(relationsCommon != null); + if (logger.isTraceEnabled() == true) { + logger.trace(relationsCommon.toString()); + } + String subjectCsid = getSubjectCsid(relationsCommon); String objectCsid = getObjectCsid(relationsCommon); - + // If no CSID for a subject or object is included in the create payload, // a refName must be provided for that subject or object as an alternate identifier. - assert (hasCsid(subjectCsid) || hasSubjectRefname(relationsCommon)); - assert (hasCsid(objectCsid) || hasObjectRefname(relationsCommon)); - + CS_ASSERT(hasCsid(subjectCsid) || hasSubjectRefname(relationsCommon)); + CS_ASSERT(hasCsid(objectCsid) || hasObjectRefname(relationsCommon)); + // The Subject identifier and Object ID must not be identical: // that is, a resource cannot be related to itself. if (hasCsid(subjectCsid) && hasCsid(objectCsid)) { - assert (subjectCsid.trim().equalsIgnoreCase(objectCsid.trim()) == false) : - SUBJECT_EQUALS_OBJECT_ERROR; + CS_ASSERT (subjectCsid.trim().equalsIgnoreCase(objectCsid.trim()) == false, + SUBJECT_EQUALS_OBJECT_ERROR); } // A relationship type must be provided. - assert (relationsCommon.getRelationshipType() != null); - - } catch (AssertionError e) { - if (logger.isErrorEnabled() == true) { - logger.error(e.getMessage(), e); - } - throw new InvalidDocumentException(VALIDATION_ERROR, e); - } + CS_ASSERT(relationsCommon.getRelationshipType() != null); + + } catch (AssertionError e) { + if (logger.isErrorEnabled() == true) { + logger.error(e.getMessage(), e); + } + throw new InvalidDocumentException(VALIDATION_ERROR, e); + } } - @Override - protected void handleGet() { - // TODO Auto-generated method stub - } + @Override + protected void handleGet() { + // TODO Auto-generated method stub + } - @Override - protected void handleGetAll() { - // TODO Auto-generated method stub - } + @Override + protected void handleGetAll() { + // TODO Auto-generated method stub + } - @Override - protected void handleUpdate() { - // TODO Auto-generated method stub - } + @Override + protected void handleUpdate() { + // TODO Auto-generated method stub + } - @Override - protected void handleDelete() { - // TODO Auto-generated method stub + @Override + protected void handleDelete() { + // TODO Auto-generated method stub } - + private String getSubjectCsid(RelationsCommon relationsCommon) { String subjectCsid = relationsCommon.getSubjectCsid(); // FIXME: Remove this entire 'if' statement when legacy fields are removed from the Relation record: if (Tools.isBlank(subjectCsid)) { subjectCsid = relationsCommon.getDocumentId1(); - } + } return subjectCsid; } @@ -101,7 +98,7 @@ public class RelationValidatorHandler extends ValidatorHandlerImpl