From fe6e57140d42b11e2bef1f581a8602d790924221 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Wed, 29 Jan 2014 12:51:23 -0800 Subject: [PATCH] PAHMA-963: Adding CSWebApplicationException class that extends WebApplicationException with the purpose of setting the response type to 'text/neterr' so we can catch and reattempt requests that fail due to network errors. --- .../5.5-HF07/config/default-repo-config.xml | 2 + .../config/lifesci_domain-repo-config.xml | 2 + build.properties | 5 +- .../common/vocabulary/AuthorityResource.java | 15 ++-- .../services/authorization/RoleResource.java | 4 +- .../services/blob/BlobResource.java | 10 +-- .../AbstractCollectionSpaceResourceImpl.java | 36 +++++----- .../services/common/ResourceBase.java | 2 +- .../services/common/profile/CSpaceFilter.java | 69 ++++++++++++++++++- .../common/relation/RelationResource.java | 4 +- .../common/security/SecurityInterceptor.java | 33 +++++---- .../common/storage/jpa/JpaStorageUtils.java | 2 +- .../java/RemoteDocumentModelHandlerImpl.java | 5 +- .../client/java/RepositoryJavaClientImpl.java | 10 ++- .../AuthorityResourceWithContacts.java | 5 +- .../services/query/QueryResource.java | 12 ++-- .../services/report/ReportResource.java | 3 +- .../nuxeo/ReportDocumentModelHandler.java | 12 ++-- .../servicegroup/ServiceGroupResource.java | 3 +- .../ServiceGroupDocumentModelHandler.java | 6 +- .../services/workflow/WorkflowResource.java | 3 +- 21 files changed, 170 insertions(+), 73 deletions(-) diff --git a/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/default-repo-config.xml b/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/default-repo-config.xml index 2c1b6d4b4..58f420c59 100644 --- a/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/default-repo-config.xml +++ b/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/default-repo-config.xml @@ -5,6 +5,8 @@ + diff --git a/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/lifesci_domain-repo-config.xml b/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/lifesci_domain-repo-config.xml index 2f835f1f8..1e09a526f 100644 --- a/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/lifesci_domain-repo-config.xml +++ b/3rdparty/nuxeo/nuxeo-server/5.5-HF07/config/lifesci_domain-repo-config.xml @@ -5,6 +5,8 @@ + diff --git a/build.properties b/build.properties index 980c44651..245a59236 100644 --- a/build.properties +++ b/build.properties @@ -120,7 +120,10 @@ db.nuxeo.user=nuxeo db.nuxeo.user.password=${env.DB_PASSWORD_NUXEO} db.cspace.user=cspace db.cspace.user.password=${env.DB_PASSWORD_CSPACE} -db.host=dba-postgres-qa-21.ist.berkeley.edu +#db.host=dba-postgres-qa-21.ist.berkeley.edu +#db.host=173.255.228.202 +db.host=169.229.248.106 +#db.host=169.229.199.44 db.jdbc.baseurl=jdbc:${db}://${db.host}:${db.port} # diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index d18fa32d3..95693d738 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -25,6 +25,7 @@ package org.collectionspace.services.common.vocabulary; import java.util.List; import java.util.Map; + import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -40,11 +41,13 @@ import javax.ws.rs.core.Request; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; + import org.collectionspace.services.client.IClientQueryParams; 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.CSWebApplicationException; import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.ResourceMap; import org.collectionspace.services.common.ServiceMain; @@ -140,7 +143,7 @@ public abstract class AuthorityResource } } - protected Specifier getSpecifier(String specifierIn, String method, String op) throws WebApplicationException { + protected Specifier getSpecifier(String specifierIn, String method, String op) throws CSWebApplicationException { if (logger.isDebugEnabled()) { logger.debug("getSpecifier called by: " + method + " with specifier: " + specifierIn); } @@ -168,7 +171,7 @@ public abstract class AuthorityResource Response response = Response.status(Response.Status.BAD_REQUEST).entity( op + " failed on bad or missing Authority specifier").type( "text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } /** @@ -416,7 +419,7 @@ public abstract class AuthorityResource Response response = Response.status(Response.Status.NOT_FOUND).entity( "Get failed, the requested Authority specifier:" + specifier + ": was not found.").type( "text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } return result.getBytes(); @@ -657,12 +660,14 @@ public abstract class AuthorityResource } catch (Exception e) { throw bigReThrow(e, ServiceMessages.GET_FAILED); } + if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( "Get failed, the requested AuthorityItem specifier:" + itemspecifier + ": was not found.").type( "text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } + return result.getBytes(); } @@ -808,7 +813,7 @@ public abstract class AuthorityResource Response response = Response.status(Response.Status.NOT_FOUND).entity( "Get failed, the requested Item CSID:" + itemspecifier + ": was not found.").type( "text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } return authRefDocList; } diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java index 8bbd027a9..96a948c08 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java @@ -32,6 +32,8 @@ import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.context.ServiceContextFactory; import org.collectionspace.services.common.storage.StorageClient; import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl; +import org.collectionspace.services.common.CSWebApplicationException; + import org.jboss.resteasy.util.HttpResponseCodes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -133,7 +135,7 @@ public class RoleResource extends SecurityResourceBase { if(RoleClient.IMMUTABLE.equals(role.getMetadataProtection())) { Response response = Response.status(Response.Status.FORBIDDEN).entity("Role: "+csid+" is immutable.").type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } return (Role)update(csid, theUpdate, Role.class); } catch (Exception e) { diff --git a/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java b/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java index 576d3bf8d..5e182268d 100644 --- a/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java +++ b/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java @@ -38,6 +38,8 @@ import org.collectionspace.services.common.blob.BlobUtil; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.publicitem.PublicItemUtil; import org.collectionspace.services.nuxeo.client.java.CommonList; +import org.collectionspace.services.common.CSWebApplicationException; + import org.jboss.resteasy.plugins.providers.multipart.InputPart; import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput; @@ -122,7 +124,7 @@ public class BlobResource extends ResourceBase { private InputStream getBlobContent(ServiceContext ctx, String csid, String derivativeTerm, - StringBuffer outMimeType) throws WebApplicationException { + StringBuffer outMimeType) throws CSWebApplicationException { InputStream result = null; try { @@ -152,7 +154,7 @@ public class BlobResource extends ResourceBase { Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( "Index failed. Could not get the contents for the Blob.").type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } return result; @@ -366,7 +368,7 @@ public class BlobResource extends ResourceBase { if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } } catch (Exception e) { throw bigReThrow(e, ServiceMessages.READ_FAILED, csid); @@ -387,7 +389,7 @@ public class BlobResource extends ResourceBase { if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } } catch (Exception e) { throw bigReThrow(e, ServiceMessages.READ_FAILED, csid); diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java index c04368c1c..d85062628 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java @@ -33,6 +33,7 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.context.ServiceContextProperties; @@ -46,6 +47,7 @@ import org.collectionspace.services.common.repository.RepositoryClientFactory; import org.collectionspace.services.common.security.UnauthorizedException; import org.collectionspace.services.common.storage.StorageClient; import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl; + import org.jboss.resteasy.core.ResourceMethod; import org.jboss.resteasy.spi.HttpRequest; @@ -404,45 +406,45 @@ public abstract class AbstractCollectionSpaceResourceImpl return result; } - public void checkResult(Object resultToCheck, String csid, String serviceMessage) throws WebApplicationException { + public void checkResult(Object resultToCheck, String csid, String serviceMessage) throws CSWebApplicationException { if (resultToCheck == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( serviceMessage + "csid=" + csid + ": was not found.").type( "text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } } - protected void ensureCSID(String csid, String crudType) throws WebApplicationException { + protected void ensureCSID(String csid, String crudType) throws CSWebApplicationException { ensureCSID(csid, crudType, "csid"); } - protected void ensureCSID(String csid, String crudType, String whichCsid) throws WebApplicationException { + protected void ensureCSID(String csid, String crudType, String whichCsid) throws CSWebApplicationException { if (logger.isDebugEnabled()) { logger.debug(crudType + " for " + getClass().getName() + " with csid=" + csid); } if (csid == null || "".equals(csid)) { logger.error(crudType + " for " + getClass().getName() + " missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity(crudType + " failed on " + getClass().getName() + ' '+whichCsid+'=' + csid).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } } - protected WebApplicationException bigReThrow(Exception e, String serviceMsg) throws WebApplicationException { + protected CSWebApplicationException bigReThrow(Exception e, String serviceMsg) throws CSWebApplicationException { return bigReThrow(e, serviceMsg, ""); } - protected WebApplicationException bigReThrow(Exception e, String serviceMsg, String csid) throws WebApplicationException { + protected CSWebApplicationException bigReThrow(Exception e, String serviceMsg, String csid) throws CSWebApplicationException { boolean logException = true; - WebApplicationException result = null; + CSWebApplicationException result = null; Response response; - String detail = Tools.errorToString(e, true); String detailNoTrace = Tools.errorToString(e, true, 3); + if (e instanceof UnauthorizedException) { response = Response.status(Response.Status.UNAUTHORIZED).entity(serviceMsg + e.getMessage()).type("text/plain").build(); - result = new WebApplicationException(response); + result = new CSWebApplicationException(e, response); } else if (e instanceof DocumentNotFoundException) { // @@ -450,12 +452,12 @@ public abstract class AbstractCollectionSpaceResourceImpl // logException = false; response = Response.status(Response.Status.NOT_FOUND).entity(serviceMsg + " on " + getClass().getName() + " csid=" + csid).type("text/plain").build(); - result = new WebApplicationException(response); + result = new CSWebApplicationException(e, response); } else if (e instanceof TransactionException) { int code = ((TransactionException) e).getErrorCode(); response = Response.status(code).entity(e.getMessage()).type("text/plain").build(); - result = new WebApplicationException(response); + result = new CSWebApplicationException(e, response); } else if (e instanceof BadRequestException) { int code = ((BadRequestException) e).getErrorCode(); @@ -465,7 +467,7 @@ public abstract class AbstractCollectionSpaceResourceImpl // CSPACE-1110 response = Response.status(code).entity(serviceMsg + e.getMessage()).type("text/plain").build(); // return new WebApplicationException(e, code); - result = new WebApplicationException(response); + result = new CSWebApplicationException(e, response); } else if (e instanceof DocumentException) { int code = ((DocumentException) e).getErrorCode(); @@ -475,16 +477,16 @@ public abstract class AbstractCollectionSpaceResourceImpl // CSPACE-1110 response = Response.status(code).entity(serviceMsg + e.getMessage()).type("text/plain").build(); // return new WebApplicationException(e, code); - result = new WebApplicationException(response); + result = new CSWebApplicationException(e, response); - } else if (e instanceof WebApplicationException) { + } else if (e instanceof CSWebApplicationException) { // subresource may have already thrown this exception // so just pass it on - result = (WebApplicationException) e; + result = (CSWebApplicationException) e; } else { // e is now instanceof Exception response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(serviceMsg + " detail: " + detailNoTrace).type("text/plain").build(); - result = new WebApplicationException(response); + result = new CSWebApplicationException(e, response); } // // Some exceptions like DocumentNotFoundException won't be logged unless we're in 'trace' mode 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 2d1dcb27f..58117049f 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 @@ -253,7 +253,7 @@ public abstract class ResourceBase if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } } catch (Exception e) { throw bigReThrow(e, ServiceMessages.READ_FAILED, csid); diff --git a/services/common/src/main/java/org/collectionspace/services/common/profile/CSpaceFilter.java b/services/common/src/main/java/org/collectionspace/services/common/profile/CSpaceFilter.java index 989e64711..459cb4193 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/profile/CSpaceFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/common/profile/CSpaceFilter.java @@ -17,6 +17,8 @@ package org.collectionspace.services.common.profile; import java.io.IOException; +import java.net.SocketException; + import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; @@ -26,9 +28,9 @@ import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; //import javax.servlet.ServletContext; + import org.collectionspace.services.client.Profiler; import org.collectionspace.services.common.ServletTools; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,6 +53,8 @@ public class CSpaceFilter implements Filter { FilterConfig filterConfig = null; private final String CLASS_NAME = this.getClass().getSimpleName(); + private static final int MAX_RETRY_SECONDS = 5; + /* (non-Javadoc) * @see javax.servlet.Filter#destroy() @@ -96,7 +100,13 @@ public class CSpaceFilter implements Filter { profiler.log(csvMsg, FORMAT_LOG_MESSAGE); // Process the request. - chain.doFilter(request, response); + //chain.doFilter(request, response); + try { + invoke(request, response, chain); + } catch (Throwable e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } // Stop timing and log performance-related metrics. profiler.stop(); @@ -116,6 +126,61 @@ public class CSpaceFilter implements Filter { profiler.reset(); } } + + public void invoke(ServletRequest request, ServletResponse response, + FilterChain chain) throws Throwable { + Throwable lastException = null; + int attempt = 0; + + long quittingTime = System.currentTimeMillis() + MAX_RETRY_SECONDS * 1000; + do { + try { + // proceed to original method call + chain.doFilter(request, response); + String contentType = response.getContentType(); + lastException = null; + break; + } catch (Exception e) { + lastException = e; + if (exceptionChainContains(lastException, SocketException.class) == false) { + // Break if the exception chain does not contain a + // SocketException. + break; + } + attempt++; + System.out + .println(String + .format("'%s' URL request failed with exception '%s' at attemp '%d'", + ServletTools.getURL((HttpServletRequest) request), + lastException.getClass().getName(), + attempt)); + } + } while (System.currentTimeMillis() < quittingTime); + + if (lastException != null) { + throw lastException; + } + + System.out.println("Success!"); + } + + private boolean exceptionChainContains(Throwable exceptionChain, + Class target) { + boolean result = false; + Throwable top = exceptionChain; + + while (top != null) { + System.out.println(top.getClass().getCanonicalName()); + if (target.isInstance(top) == true) { + result = true; + break; + } + top = top.getCause(); + } + + return result; + } + /* (non-Javadoc) * @see javax.servlet.Filter#init(javax.servlet.FilterConfig) diff --git a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java index 02d3d8b7b..ee137fe93 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java +++ b/services/common/src/main/java/org/collectionspace/services/common/relation/RelationResource.java @@ -29,6 +29,7 @@ package org.collectionspace.services.common.relation; import org.collectionspace.services.client.IQueryManager; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.context.ServiceContext; @@ -38,7 +39,6 @@ import org.collectionspace.services.client.IRelationsManager; import org.collectionspace.services.common.relation.nuxeo.RelationsUtils; import org.collectionspace.services.relation.RelationsCommon; import org.collectionspace.services.relation.RelationsCommonList; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,7 +101,7 @@ public class RelationResource extends ResourceBase { String subjectCsid, String subjectType, String predicate, String objectCsid, - String objectType) throws WebApplicationException { + String objectType) throws CSWebApplicationException { try { ServiceContext ctx = createServiceContext(uriInfo); if (parentCtx != null) { // If the parent context has an open repository session then use it diff --git a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java index 49752e485..ce5189c65 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java +++ b/services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java @@ -53,11 +53,11 @@ import org.collectionspace.services.authorization.AuthZ; import org.collectionspace.services.authorization.CSpaceResource; import org.collectionspace.services.authorization.URIResourceImpl; import org.collectionspace.services.client.workflow.WorkflowClient; +import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.CollectionSpaceResource; import org.collectionspace.services.common.document.JaxbUtils; import org.collectionspace.services.common.storage.jpa.JpaStorageUtils; import org.collectionspace.services.common.security.SecurityUtils; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -123,7 +123,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn */ @Override public ServerResponse preProcess(HttpRequest request, ResourceMethod resourceMethod) - throws Failure, WebApplicationException { + throws Failure, CSWebApplicationException { ServerResponse result = null; // A null value essentially means success for this method if (isAnonymousRequest(request, resourceMethod) == true) { @@ -138,13 +138,15 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn final int servicesResourceLen = servicesResource.length(); String httpMethod = request.getHttpMethod(); String uriPath = request.getUri().getPath(); + if (logger.isDebugEnabled()) { String fullRequest = request.getUri().getRequestUri().toString(); int servicesResourceIdx = fullRequest.indexOf(servicesResource); String relativeRequest = (servicesResourceIdx<=0)? fullRequest - :fullRequest.substring(servicesResourceIdx+servicesResourceLen); + : fullRequest.substring(servicesResourceIdx+servicesResourceLen); logger.debug("received " + httpMethod + " on " + relativeRequest); } + String resName = SecurityUtils.getResourceName(request.getUri()); String resEntity = SecurityUtils.getResourceEntity(resName); @@ -172,7 +174,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn + " user=" + AuthN.get().getUserId()); Response response = Response.status( Response.Status.FORBIDDEN).entity(uriPath + " " + httpMethod).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } else { // // They passed the first round of security checks, so now let's check to see if they're trying @@ -186,7 +188,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn + " user=" + AuthN.get().getUserId()); Response response = Response.status( Response.Status.FORBIDDEN).entity(uriPath + " " + httpMethod).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } } } @@ -218,10 +220,14 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn /** * checkActive check if account is active - * @throws WebApplicationException + * @throws CSWebApplicationException */ - private void checkActive() throws WebApplicationException { + private void checkActive() throws CSWebApplicationException { String userId = AuthN.get().getUserId(); + + if (true) + throw new CSWebApplicationException(new java.net.SocketException("An faux exception thrown for testing.")); + try { // Need to ensure that user is associated to a tenant String tenantId = AuthN.get().getCurrentTenantId(); @@ -232,8 +238,9 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn // indicates that authorization has been refused for those credentials. Response response = Response.status( Response.Status.UNAUTHORIZED).entity(msg).type("text/plain").build(); - throw new WebApplicationException(ise, response); + throw new CSWebApplicationException(ise, response); } + try { //can't use JAXB here as this runs from the common jar which cannot //depend upon the account service @@ -247,7 +254,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn String msg = "User's account not found, userId=" + userId; Response response = Response.status( Response.Status.FORBIDDEN).entity(msg).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } Object status = JaxbUtils.getValue(account, "getStatus"); if (status != null) { @@ -256,7 +263,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn String msg = "User's account is inactive, userId=" + userId; Response response = Response.status( Response.Status.FORBIDDEN).entity(msg).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } } @@ -264,14 +271,14 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn String msg = "User's account is in invalid state, userId=" + userId; Response response = Response.status( Response.Status.FORBIDDEN).entity(msg).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(e, response); } } // // Nuxeo login support // public ServerResponse nuxeoPreProcess(HttpRequest request, ResourceMethod resourceMethod) - throws Failure, WebApplicationException { + throws Failure, CSWebApplicationException { try { nuxeoLogin(); } catch (LoginException e) { @@ -279,7 +286,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn logger.error(msg, e); Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity(msg).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(e, response); } return null; diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageUtils.java b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageUtils.java index c515451a6..069d94516 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageUtils.java @@ -542,7 +542,7 @@ public class JpaStorageUtils { if (logger.isDebugEnabled()) { logger.debug("could not find entity (2) with where=" + whereClause, e); } - //returns null + throw e; } finally { if (em != null) { releaseEntityManagerFactory(emf); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 057778031..1323e9c1a 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -49,6 +49,7 @@ import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.Profiler; import org.collectionspace.services.client.RelationClient; import org.collectionspace.services.client.workflow.WorkflowClient; +import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.config.ServiceConfigUtils; @@ -80,12 +81,10 @@ import org.collectionspace.services.relation.RelationsCommonList; import org.collectionspace.services.relation.RelationsDocListItem; import org.collectionspace.services.relation.RelationshipType; import org.dom4j.Element; - import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.model.PropertyException; import org.nuxeo.ecm.core.api.repository.RepositoryInstance; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -664,7 +663,7 @@ public abstract class RemoteDocumentModelHandlerImpl Response.Status.INTERNAL_SERVER_ERROR).entity( "Failed to retrieve authority references").type( "text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(e, response); } return authRefList; 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 cebbb47db..e44ad6ee0 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 @@ -28,8 +28,8 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; -import javax.sql.rowset.CachedRowSet; +import javax.sql.rowset.CachedRowSet; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.MultivaluedMap; @@ -46,7 +46,6 @@ import org.collectionspace.services.common.storage.JDBCTools; import org.collectionspace.services.common.storage.PreparedStatementSimpleBuilder; import org.collectionspace.services.lifecycle.TransitionDef; import org.collectionspace.services.nuxeo.util.NuxeoUtils; - import org.collectionspace.services.common.document.BadRequestException; import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.document.DocumentFilter; @@ -57,7 +56,6 @@ import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.document.DocumentWrapperImpl; import org.collectionspace.services.common.document.TransactionException; import org.collectionspace.services.config.tenant.RepositoryDomainType; - import org.nuxeo.common.utils.IdUtils; import org.nuxeo.ecm.core.api.ClientException; import org.nuxeo.ecm.core.api.DocumentModel; @@ -76,6 +74,7 @@ import org.nuxeo.runtime.transaction.TransactionRuntimeException; // import org.apache.chemistry.opencmis.commons.server.CallContext; import org.apache.chemistry.opencmis.server.impl.CallContextImpl; +import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.api.Tools; import org.collectionspace.services.common.config.ConfigUtils; @@ -85,7 +84,6 @@ import org.collectionspace.services.common.storage.PreparedStatementBuilder; import org.collectionspace.services.config.tenant.TenantBindingType; import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoCmisService; import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoRepository; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -910,7 +908,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient } if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity("Get failed, the requested Contact CSID:" + csid + ": was not found.").type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } return result.toXML(); } diff --git a/services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java b/services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java index 7d1eb9523..9c575b8f1 100644 --- a/services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java +++ b/services/query/service/src/main/java/org/collectionspace/services/query/QueryResource.java @@ -33,6 +33,8 @@ import javax.ws.rs.core.Response; //import javax.xml.bind.JAXBContext; //import javax.xml.bind.Marshaller; + +import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.query.QueryManager; //import org.collectionspace.services.common.NuxeoClientType; /*import org.collectionspace.services.common.ServiceMain; @@ -66,12 +68,12 @@ public class QueryResource { if(logger.isDebugEnabled()){ verbose("getQuery with csid=" + csid); } - if(csid == null || "".equals(csid)){ + if (csid == null || "".equals(csid)){ logger.error("getQuery: missing csid!"); Response response = Response.status(Response.Status.BAD_REQUEST).entity( "get failed on getQuery csid=" + csid).type( "text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } try { @@ -83,14 +85,14 @@ public class QueryResource { Response response = Response.status(Response.Status.NOT_FOUND).entity( "Get failed on query csid=" + csid).type( "text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(e, response); } - if(false){ + if (false) { // REM - 1/29/2014 : Huh? Why is this essentially commented out? Should probably clean up. Response response = Response.status(Response.Status.NOT_FOUND).entity( "Get failed, the requested CSID:" + csid + ": was not found.").type( "text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } // return intakeObject; diff --git a/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java b/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java index 3eccdc81c..566d4e3b9 100644 --- a/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/ReportResource.java @@ -32,6 +32,7 @@ import org.collectionspace.services.client.IQueryManager; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.ReportClient; +import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.ResourceMap; import org.collectionspace.services.common.ServiceMessages; @@ -228,7 +229,7 @@ public class ReportResource extends ResourceBase { Response response = Response.status(Response.Status.BAD_REQUEST).entity( "invoke failed on Report csid=" + csid).type( "text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } if (logger.isTraceEnabled()) { diff --git a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java index f7a4eaf69..104f33d68 100644 --- a/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java +++ b/services/report/service/src/main/java/org/collectionspace/services/report/nuxeo/ReportDocumentModelHandler.java @@ -36,7 +36,6 @@ import java.util.List; import java.util.Map; import javax.ws.rs.core.MediaType; - import javax.naming.NamingException; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; @@ -64,6 +63,7 @@ import org.collectionspace.services.report.ReportsCommon; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.ReportClient; +import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.api.JEEServerDeployment; import org.collectionspace.services.common.api.FileTools; @@ -358,7 +358,7 @@ public class ReportDocumentModelHandler extends DocHandlerBase { Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( "Invoke failed (SQL problem) on Report csid=" + reportCSID).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(sqle, response); } catch (JRException jre) { if (logger.isDebugEnabled()) { logger.debug("JR Exception: " + jre.getLocalizedMessage() + " Cause: "+jre.getCause()); @@ -366,7 +366,7 @@ public class ReportDocumentModelHandler extends DocHandlerBase { Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( "Invoke failed (Jasper problem) on Report csid=" + reportCSID).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(jre, response); } catch (FileNotFoundException fnfe) { if (logger.isDebugEnabled()) { logger.debug("FileNotFoundException: " + fnfe.getLocalizedMessage()); @@ -374,11 +374,11 @@ public class ReportDocumentModelHandler extends DocHandlerBase { Response response = Response.status( Response.Status.INTERNAL_SERVER_ERROR).entity( "Invoke failed (SQL problem) on Report csid=" + reportCSID).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(fnfe, response); } finally { - if(conn!=null) { + if (conn!=null) { try { - conn.close(); + conn.close(); } catch (SQLException sqle) { // SQLExceptions can be chained. We have at least one exception, so // set up a loop to make sure we let the user know about all of them diff --git a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java index 14cf99225..3b6d27ab5 100644 --- a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java +++ b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/ServiceGroupResource.java @@ -34,6 +34,7 @@ import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.ServiceGroupClient; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; +import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.ServiceMessages; @@ -183,7 +184,7 @@ public class ServiceGroupResource extends AbstractCollectionSpaceResourceImpl { // 404 if there are no mappings. Response response = Response.status(Response.Status.NOT_FOUND).entity( ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(groupname)).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } //Otherwise, build the response with a list ServicegroupsCommon common = new ServicegroupsCommon(); diff --git a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java index 8e74d7003..874ad0995 100644 --- a/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java +++ b/services/servicegroup/service/src/main/java/org/collectionspace/services/servicegroup/nuxeo/ServiceGroupDocumentModelHandler.java @@ -41,6 +41,7 @@ import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.client.IQueryManager; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.ServiceMain; import org.collectionspace.services.common.ServiceMessages; import org.collectionspace.services.common.StoredValuesUriTemplate; @@ -113,7 +114,7 @@ public class ServiceGroupDocumentModelHandler Response response = Response.status(Response.Status.NOT_FOUND).entity( ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(implode(serviceGroupNames, ","))).type("text/plain").build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } servicebindings = SecurityUtils.getReadableServiceBindingsForCurrentUser(servicebindings); // Build the list of docTypes for allowed serviceBindings @@ -161,7 +162,8 @@ public class ServiceGroupDocumentModelHandler logger.debug("Caught exception ", e); } throw new DocumentException(e); - } + } + return list; } diff --git a/services/workflow/service/src/main/java/org/collectionspace/services/workflow/WorkflowResource.java b/services/workflow/service/src/main/java/org/collectionspace/services/workflow/WorkflowResource.java index b0ec10880..19a8af562 100644 --- a/services/workflow/service/src/main/java/org/collectionspace/services/workflow/WorkflowResource.java +++ b/services/workflow/service/src/main/java/org/collectionspace/services/workflow/WorkflowResource.java @@ -24,6 +24,7 @@ package org.collectionspace.services.workflow; import org.collectionspace.services.client.workflow.WorkflowClient; +import org.collectionspace.services.common.CSWebApplicationException; import org.collectionspace.services.common.ResourceBase; import org.collectionspace.services.common.ResourceMap; import org.collectionspace.services.common.ServiceMessages; @@ -101,7 +102,7 @@ public class WorkflowResource extends ResourceBase { Response response = Response.status(Response.Status.BAD_REQUEST) .entity(ServiceMessages.GET_LIST_UNSUPPORTED).type("text/plain") .build(); - throw new WebApplicationException(response); + throw new CSWebApplicationException(response); } } -- 2.47.3