}\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
// 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
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);
}
}
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();
//
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
//
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;
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;
// 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);
}
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);
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);
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) {
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);
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
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;
}
}
+ 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
*
* @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);
DocumentException {
if (logger.isDebugEnabled()) {
- logger.debug("deleting document with id=" + id);
+ logger.debug("Deleting document with CSID=" + id);
}
RepositoryInstance repoSession = null;
try {
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();