cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From owu...@apache.org
Subject svn commit: r1564029 - /cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RestServiceExceptionMapper.java
Date Mon, 03 Feb 2014 19:51:25 GMT
Author: owulff
Date: Mon Feb  3 19:51:24 2014
New Revision: 1564029

URL: http://svn.apache.org/r1564029
Log:
Support HTTP Header X-Application-Error-Code and X-Application-Error-Info

Modified:
    cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RestServiceExceptionMapper.java

Modified: cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RestServiceExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RestServiceExceptionMapper.java?rev=1564029&r1=1564028&r2=1564029&view=diff
==============================================================================
--- cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RestServiceExceptionMapper.java
(original)
+++ cxf/fediz/trunk/services/idp/src/main/java/org/apache/cxf/fediz/service/idp/rest/RestServiceExceptionMapper.java
Mon Feb  3 19:51:24 2014
@@ -20,6 +20,8 @@ package org.apache.cxf.fediz.service.idp
 
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+import javax.ws.rs.core.Response.Status;
 import javax.ws.rs.ext.ExceptionMapper;
 import javax.ws.rs.ext.Provider;
 import org.slf4j.Logger;
@@ -32,6 +34,10 @@ import org.springframework.security.acce
 @Provider
 public class RestServiceExceptionMapper implements ExceptionMapper<Exception> {
 
+    public static final String APPLICATION_ERROR_CODE = "X-Application-Error-Code";
+    
+    public static final String APPLICATION_ERROR_INFO = "X-Application-Error-Info";
+    
     private static final String BASIC_REALM_UNAUTHORIZED = "Basic realm=\"Apache Fediz authentication\"";
 
     private static final Logger LOG = LoggerFactory.getLogger(RestServiceExceptionMapper.class);
@@ -45,24 +51,27 @@ public class RestServiceExceptionMapper 
                     header(HttpHeaders.WWW_AUTHENTICATE, BASIC_REALM_UNAUTHORIZED).
                     build();
         }
-        // EmptyResultDataAccessException
-        // DataIntegrityViolationException
-        // DataRetrievalFailureException / JpaObjectRetrievalFailureException
-        
         if (ex instanceof DataIntegrityViolationException) {
-            return Response.status(Response.Status.CONFLICT).build();
+            return buildResponse(Response.Status.CONFLICT, ex);
         }
         
         if (ex instanceof EmptyResultDataAccessException) {
-            return Response.status(Response.Status.NOT_FOUND).build();
+            return buildResponse(Response.Status.NOT_FOUND, ex);
         }
         
         if (ex instanceof DataRetrievalFailureException) {
-            return Response.status(Response.Status.NOT_FOUND).build();
+            return buildResponse(Response.Status.NOT_FOUND, ex);
         }
 
         // Rest is interpreted as InternalServerError
-        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
+        return buildResponse(Response.Status.INTERNAL_SERVER_ERROR, ex);
+    }
+
+    Response buildResponse(final Status status, final Exception ex) {
+        ResponseBuilder responseBuilder = Response.status(status);
+        return responseBuilder.header(APPLICATION_ERROR_CODE, ex.getClass().getName())
+                              .header(APPLICATION_ERROR_INFO, ex.getMessage())
+                              .status(status).build();
     }
 
 }



Mime
View raw message