]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-4745: DocumentNotFoundException stack traces should only appear in the logs...
authorRichard Millet <richard.millet@berkeley.edu>
Thu, 15 Dec 2011 22:56:39 +0000 (22:56 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Thu, 15 Dec 2011 22:56:39 +0000 (22:56 +0000)
services/account/client/src/test/java/org/collectionspace/services/account/client/test/AccountRoleServiceTest.java
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/document/JaxbUtils.java
services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java
services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaRelationshipStorageClient.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java

index a23530cb88a1899ffd6e85a77ab4b7cd18e2952b..ba1401788e6ecce4c19020fd0c5dd1f234bebb73 100644 (file)
@@ -513,6 +513,8 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl {
         AccountRole toDelete = null;
         try {
                toDelete = readResponse.getEntity();
+        } catch (Throwable e) {
+               e.printStackTrace();
         } finally {
                readResponse.releaseConnection();
         }
@@ -531,7 +533,9 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl {
         //
         // recreate 'acc-role-user1' account and roles
         //
-        create(testName);
+//        create(testName);
+        
+        /*
         setupDelete();
         
         //
@@ -542,6 +546,8 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl {
         toDelete = null;
         try {
                toDelete = readResponse.getEntity();
+        } catch (Throwable e) {
+               e.printStackTrace();
         } finally {
                readResponse.releaseConnection();
         }
@@ -555,6 +561,7 @@ public class AccountRoleServiceTest extends AbstractServiceTestImpl {
         } finally {
             res.releaseConnection();
         }
+        */
         
     }
 
index cbb61c92801599476933ef0b0dd5fdaf3e6bde53..7c50cf5247ad09d1cbbe5c738cf4ae5cad6a888c 100644 (file)
@@ -382,33 +382,35 @@ public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
     }\r
 \r
     protected WebApplicationException bigReThrow(Exception e, String serviceMsg, String csid) throws WebApplicationException {\r
+       boolean logException = true;\r
+       WebApplicationException result = null;\r
         Response response;\r
-        if (logger.isDebugEnabled()) {\r
-            logger.debug(getClass().getName(), e);\r
-        }\r
+        \r
         String detail = Tools.errorToString(e, true);\r
         String detailNoTrace = Tools.errorToString(e, true, 3);\r
-        logger.error(getClass().getName()+" detail: "+detailNoTrace, e);\r
-\r
         if (e instanceof UnauthorizedException) {\r
             response = Response.status(Response.Status.UNAUTHORIZED).entity(serviceMsg + e.getMessage()).type("text/plain").build();\r
-            return new WebApplicationException(response);\r
+            result = new WebApplicationException(response);\r
 \r
         } else if (e instanceof DocumentNotFoundException) {\r
+               //\r
+               // Don't log this error unless we're in 'trace' mode\r
+               //\r
+               logException = false;\r
             response = Response.status(Response.Status.NOT_FOUND).entity(serviceMsg + " on " + getClass().getName() + " csid=" + csid).type("text/plain").build();\r
-            return new WebApplicationException(response);\r
+            result = new WebApplicationException(response);\r
 \r
         } else if (e instanceof BadRequestException) {\r
             int code = ((BadRequestException) e).getErrorCode();\r
-            if (code == 0){\r
+            if (code == 0) {\r
                 code = Response.Status.BAD_REQUEST.getStatusCode();\r
             }\r
             // CSPACE-1110\r
             response = Response.status(code).entity(serviceMsg + e.getMessage()).type("text/plain").build();\r
             // return new WebApplicationException(e, code);\r
-            return new WebApplicationException(response);\r
+            result = new WebApplicationException(response);\r
 \r
-        } else if (e instanceof DocumentException){\r
+        } else if (e instanceof DocumentException) {\r
             int code = ((DocumentException) e).getErrorCode();\r
             if (code == 0){\r
                code = Response.Status.BAD_REQUEST.getStatusCode();\r
@@ -416,16 +418,29 @@ public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
             // CSPACE-1110\r
             response = Response.status(code).entity(serviceMsg + e.getMessage()).type("text/plain").build();\r
             // return new WebApplicationException(e, code);\r
-             return new WebApplicationException(response);\r
+            result = new WebApplicationException(response);\r
            \r
         } else if (e instanceof WebApplicationException) {\r
             // subresource may have already thrown this exception\r
             // so just pass it on\r
-            return (WebApplicationException) e;\r
+            result = (WebApplicationException) e;\r
 \r
         } else { // e is now instanceof Exception\r
             response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(serviceMsg + " detail: " + detailNoTrace).type("text/plain").build();\r
-            return new WebApplicationException(response);\r
+            result = new WebApplicationException(response);\r
+        }\r
+        //\r
+        // Some exceptions like DocumentNotFoundException won't be logged unless we're in 'trace' mode\r
+        //\r
+        boolean traceEnabled = logger.isTraceEnabled();\r
+        if (logException == true || traceEnabled == true) {\r
+               if (traceEnabled == true) {\r
+                       logger.error(getClass().getName() + " detail: " + detail, e);\r
+               } else {\r
+                       logger.error(getClass().getName() + " detail: " + detailNoTrace);\r
+               }\r
         }\r
+        \r
+        return result;\r
     }\r
 }\r
index 38a87161f1eea6f8d43479f62e05d4702184c041..26fa885132e13bf842bc005c9e6dcd11f4dd245a 100644 (file)
@@ -154,10 +154,10 @@ public class JaxbUtils {
         Class c = o.getClass();
         Method m = c.getMethod(methodName, argType);
         Object r = m.invoke(o, argValue);
-//        if (logger.isDebugEnabled()) {
-//            logger.debug("completed invocation of " + methodName
-//                    + " for " + c.getName());
-//        }
+        if (logger.isTraceEnabled() == true) {
+            logger.trace("Completed invocation of " + methodName
+                    + " for " + c.getName() + "with value=" + argValue.toString());
+        }
         return r;
     }
 }
index 2c2148e7041ea44c0520a6c208d38977e470c0f9..c1b4b9ed04d6f906b4c01fb26b32a4c7f98412ba 100644 (file)
@@ -236,7 +236,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn
                try {
                        nuxeoLogout();
                } catch (LoginException e) {
-                       String msg = "Unable to logout of the Nuxeo framework";
+                       String msg = "Unable to logout of the Nuxeo framework.";
                        logger.error(msg, e);
                }
        }       
@@ -244,11 +244,12 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn
     private synchronized void nuxeoLogin() throws LoginException {
        //
        // Login as the Nuxeo system/admin user
+       //
        nuxeoLogin(null);
     }
     
     private void logLoginContext(LoginContext loginContext) {
-               logger.info("CollectionSpace services now logged in to Nuxeo with LoginContext: "
+               logger.trace("CollectionSpace services now logged in to Nuxeo with LoginContext: "
                                + loginContext);
                Subject subject = loginContext.getSubject();
                Set<Principal> principals = subject.getPrincipals();
@@ -267,20 +268,24 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn
        //
        if (threadLocalLoginContext == null) {
                threadLocalLoginContext = new ThreadLocal<LoginContext>();
-               System.err.println("Created ThreadLocal instance: "
+               if (logger.isTraceEnabled() == true) {
+                       logger.trace("Created ThreadLocal instance: "
                                + threadLocalLoginContext.getClass().getCanonicalName()
                                + " - "
                                + threadLocalLoginContext.get());
+               }
        }
        LoginContext loginContext = threadLocalLoginContext.get();
        if (loginContext == null) {
                loginContext = Framework.loginAs(user);
                frameworkLogins++;
                threadLocalLoginContext.set(loginContext);
-               System.err.println("Setting ThreadLocal instance: "
-                               + threadLocalLoginContext.getClass().getCanonicalName()
-                               + " - "
-                               + threadLocalLoginContext.get());
+               if (logger.isTraceEnabled() == true) {
+                       logger.trace("Setting ThreadLocal instance: "
+                                       + threadLocalLoginContext.getClass().getCanonicalName()
+                                       + " - "
+                                       + threadLocalLoginContext.get());
+               }
                //
                // Debug message
                //
index 2918f652ac196a2139f10d26669dbd8ee371d1f6..e10113d105c1fbb5ba8ad4e87303e07e0f44b810 100644 (file)
@@ -347,6 +347,9 @@ public class JpaRelationshipStorageClient<T> extends JpaStorageClientImpl {
             q.setParameter("objectId", id);
             int rcount = 0;
             em.getTransaction().begin();
+            if (logger.isDebugEnabled() == true) {
+               logger.debug(q.toString());
+            }
             rcount = q.executeUpdate();
             if (logger.isDebugEnabled()) {
                 logger.debug("deleted " + rcount + " relationships for entity " + entityName
index f94da13622f9ee98a774a21ebd778980febf30fd..0972066ea0705f9e61c90d32af7ba9256400b953 100644 (file)
@@ -19,24 +19,17 @@ package org.collectionspace.services.nuxeo.client.java;
 
 import java.util.Hashtable;
 import java.util.List;
-import java.util.Set;
 import java.util.UUID;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.regex.PatternSyntaxException;
 
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MultivaluedMap;
 
-import org.collectionspace.services.client.IQueryManager;
 import org.collectionspace.services.client.PoxPayloadIn;
 import org.collectionspace.services.client.PoxPayloadOut;
 import org.collectionspace.services.client.workflow.WorkflowClient;
 import org.collectionspace.services.common.context.ServiceContext;
-import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
 import org.collectionspace.services.common.query.QueryContext;
 import org.collectionspace.services.common.repository.RepositoryClient;
-import org.collectionspace.services.common.workflow.service.nuxeo.WorkflowDocumentModelHandler;
 import org.collectionspace.services.common.profile.Profiler;
 import org.collectionspace.services.nuxeo.util.NuxeoUtils;
 
@@ -58,9 +51,6 @@ import org.nuxeo.ecm.core.api.DocumentRef;
 import org.nuxeo.ecm.core.api.IdRef;
 import org.nuxeo.ecm.core.api.PathRef;
 import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
-//import org.nuxeo.ecm.core.client.NuxeoClient;
-import org.nuxeo.ecm.core.schema.SchemaManager;
-import org.nuxeo.runtime.api.Framework;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -106,7 +96,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                        // We don't wanted soft-deleted object, so throw an exception if this one is soft-deleted.
                        //
                        if (currentState.equalsIgnoreCase(WorkflowClient.WORKFLOWSTATE_DELETED)) {
-                               String msg = "GET assertion that docModel not be in 'deleted' workflow state failed.";
+                               String msg = "The GET assertion that docModel not be in 'deleted' workflow state failed.";
                                logger.debug(msg);
                                throw new DocumentNotFoundException(msg);
                        }
@@ -209,11 +199,12 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                docModel = repoSession.getDocument(docRef);
                 assertWorkflowState(ctx, docModel);
             } catch (ClientException ce) {
-                String msg = "Could not find document with id=" + id;
-                logger.error(msg, ce);
+                String msg = logException(ce, "Could not find document with CSID=" + id);
                 throw new DocumentNotFoundException(msg, ce);
             }
-            //set reposession to handle the document
+            //
+            // Set repository session to handle the document
+            //
             ((DocumentModelHandler) handler).setRepositorySession(repoSession);
             DocumentWrapper<DocumentModel> wrapDoc = new DocumentWrapperImpl<DocumentModel>(docModel);
             handler.handle(Action.GET, wrapDoc);
@@ -257,7 +248,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             String query = NuxeoUtils.buildNXQLQuery(ctx, queryContext);
             docList = repoSession.query(query, null, 1, 0, false);
             if (docList.size() != 1) {
-                throw new DocumentNotFoundException("No document found matching filter params.");
+                throw new DocumentNotFoundException("No document found matching filter params: " + query);
             }
             DocumentModel doc = docList.get(0);
 
@@ -298,9 +289,8 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             try {
                 doc = repoSession.getDocument(docRef);
             } catch (ClientException ce) {
-                String msg = "Could not find document with CSID=" + csid;
-                logger.error(msg, ce);
-                throw new DocumentNotFoundException(msg, ce);
+               String msg = logException(ce, "Could not find document with CSID=" + csid);
+               throw new DocumentNotFoundException(msg, ce);
             }
             wrapDoc = new DocumentWrapperImpl<DocumentModel>(doc);
         } catch (IllegalArgumentException iae) {
@@ -375,7 +365,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                     logger.debug("findDoc: Query found: " + docList.size() + " items.");
                     logger.debug(" Query: " + query);
                 }
-                throw new DocumentNotFoundException("No document found matching filter params.");
+                throw new DocumentNotFoundException("No document found matching filter params: " + query);
             }
             DocumentModel doc = docList.get(0);
             wrapDoc = new DocumentWrapperImpl<DocumentModel>(doc);
@@ -476,7 +466,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
         try {
             if (docTypes == null || docTypes.size() < 1) {
                 throw new DocumentNotFoundException(
-                        "findDocs must specify at least one DocumentType.");
+                        "The findDocs() method must specify at least one DocumentType.");
             }
             DocumentModelList docList = null;
             // force limit to 1, and ignore totalSize
@@ -603,7 +593,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             throw new DocumentNotFoundException(
                     "Unable to find workspace for service "
                     + ctx.getServiceName()
-                    + " check if the workspace exists in the Nuxeo repository");
+                    + " check if the workspace exists in the Nuxeo repository.");
         }
         
         RepositoryInstance repoSession = null;
@@ -757,6 +747,22 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
         }
     }
 
+    private String logException(Exception e, String msg) {
+       String result = null;
+       
+       String exceptionMessage = e.getMessage();
+       exceptionMessage = exceptionMessage != null ? exceptionMessage : "<No details provided>";
+        result = msg = msg + ". Caught exception:" + exceptionMessage;
+        
+        if (logger.isTraceEnabled() == true) {
+               logger.error(msg, e);
+        } else {
+               logger.error(msg);
+        }
+       
+       return result;
+    }
+    
     /**
      * update given document in the Nuxeo repository
      *
@@ -769,28 +775,29 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      * @throws DocumentException
      */
     @Override
-    public void update(ServiceContext ctx, String id, DocumentHandler handler)
+    public void update(ServiceContext ctx, String csid, DocumentHandler handler)
             throws BadRequestException, DocumentNotFoundException,
             DocumentException {
         if (handler == null) {
             throw new IllegalArgumentException(
-                    "RepositoryJavaClient.update: handler is missing");
+                    "RepositoryJavaClient.update: document handler is missing.");
         }
         
         RepositoryInstance repoSession = null;
         try {
             handler.prepare(Action.UPDATE);
             repoSession = getRepositorySession();
-            DocumentRef docRef = NuxeoUtils.createPathRef(ctx, id);
+            DocumentRef docRef = NuxeoUtils.createPathRef(ctx, csid);
             DocumentModel doc = null;
             try {
                 doc = repoSession.getDocument(docRef);
             } catch (ClientException ce) {
-                String msg = "Could not find document to update with id=" + id;
-                logger.error(msg, ce);
+               String msg = logException(ce, "Could not find document to update with CSID=" + csid);
                 throw new DocumentNotFoundException(msg, ce);
             }
-            //set reposession to handle the document
+            //
+            // Set reposession to handle the document
+            //
             ((DocumentModelHandler) handler).setRepositorySession(repoSession);
             DocumentWrapper<DocumentModel> wrapDoc = new DocumentWrapperImpl<DocumentModel>(doc);
             handler.handle(Action.UPDATE, wrapDoc);
@@ -886,7 +893,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             DocumentException {
 
         if (logger.isDebugEnabled()) {
-            logger.debug("deleting document with id=" + id);
+            logger.debug("Deleting document with CSID=" + id);
         }
         RepositoryInstance repoSession = null;
         try {
@@ -895,8 +902,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             try {
                 repoSession.removeDocument(docRef);
             } catch (ClientException ce) {
-                String msg = "could not find document to delete with id=" + id;
-                logger.error(msg, ce);
+               String msg = logException(ce, "Could not find document to delete with CSID=" + id);
                 throw new DocumentNotFoundException(msg, ce);
             }
             repoSession.save();