]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-3281: Was returning a 500 status code for duplicate role create requests,...
authorRichard Millet <richard.millet@berkeley.edu>
Wed, 19 Jan 2011 23:37:40 +0000 (23:37 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Wed, 19 Jan 2011 23:37:40 +0000 (23:37 +0000)
services/authorization-mgt/client/src/test/java/org/collectionspace/services/authorization/client/test/RoleServiceTest.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java

index d29ce75a98ebc25f53728febbdb3901b63a9116c..443a4aaccd347a1c5cdde20e9bdbbfeebf8e4a42 100644 (file)
@@ -181,7 +181,7 @@ public class RoleServiceTest extends AbstractServiceTestImpl {
         }
         Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
                 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
-        Assert.assertEquals(statusCode, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
+        Assert.assertEquals(statusCode, Response.Status.BAD_REQUEST.getStatusCode());
     }
 
     /**
index 9e33df598ca466d46e00a64da62fe0787144971f..34b04dfa420081971edf84df6a86f90d0075fa8e 100644 (file)
@@ -47,6 +47,7 @@ import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.context.ServiceContextFactory;
 import org.collectionspace.services.common.context.RemoteServiceContextFactory;
 import org.collectionspace.services.common.document.BadRequestException;
+import org.collectionspace.services.common.document.DocumentException;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentHandler;
@@ -140,34 +141,42 @@ public class RoleResource
      */
     @POST
     public Response createRole(Role input) {
-        try {
+       Response response = null;
+
+       try {
             ServiceContext ctx = createServiceContext(input, Role.class);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getStorageClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(RoleResource.class);
             path.path("" + csid);
-            Response response = Response.created(path.build()).build();
-            return response;
+            response = Response.created(path.build()).build();
         } catch (BadRequestException bre) {
-            Response response = Response.status(
+            response = Response.status(
+                    Response.Status.BAD_REQUEST).entity(ServiceMessages.POST_FAILED
+                    + bre.getErrorReason()).type("text/plain").build();
+            throw new WebApplicationException(response);
+        } catch (DocumentException bre) {
+            response = Response.status(
                     Response.Status.BAD_REQUEST).entity(ServiceMessages.POST_FAILED
                     + bre.getErrorReason()).type("text/plain").build();
             throw new WebApplicationException(response);
         } catch (UnauthorizedException ue) {
-            Response response = Response.status(
+            response = Response.status(
                     Response.Status.UNAUTHORIZED).entity(ServiceMessages.POST_FAILED
                     + ue.getErrorReason()).type("text/plain").build();
             throw new WebApplicationException(response);
         } catch (Exception e) {
             if (logger.isDebugEnabled()) {
-                logger.debug("Caught exception in createRole", e);
+                logger.debug("Caught a general exception in RoleResource:createRole post: ", e);
             }
             logger.error(ServiceMessages.UNKNOWN_ERROR_MSG, e);
-            Response response = Response.status(
+            response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity(ServiceMessages.POST_FAILED
                     + e.getMessage()).type("text/plain").build();
             throw new WebApplicationException(e, response);
         }
+        
+        return response;        
     }
 
     /**