cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1442121 - /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Date Mon, 04 Feb 2013 14:05:56 GMT
Author: sergeyb
Date: Mon Feb  4 14:05:56 2013
New Revision: 1442121

URL: http://svn.apache.org/viewvc?rev=1442121&view=rev
Log:
Making sure 2.0 filters can be re-entered if the exception has been mapped

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1442121&r1=1442120&r2=1442121&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Mon Feb  4 14:05:56 2013
@@ -35,6 +35,7 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.InternalServerErrorException;
 import javax.ws.rs.container.AsyncResponse;
 import javax.ws.rs.core.GenericEntity;
 import javax.ws.rs.core.HttpHeaders;
@@ -132,6 +133,21 @@ public class JAXRSOutInterceptor extends
         OperationResourceInfo ori = (OperationResourceInfo)exchange.get(OperationResourceInfo.class
             .getName());
         
+        boolean retryHappened = false;
+        try {
+            response = runResponseFilters(providerFactory, message, response, ori);
+        } catch (Throwable ex) {
+            response = handleFilterException(providerFactory, message, response, ori, ex);
+            retryHappened = true;
+        }
+        
+        serializeMessage(message, response, ori, !retryHappened);        
+    }
+
+    private Response runResponseFilters(ProviderFactory providerFactory,
+                                Message message, 
+                                Response response, 
+                                OperationResourceInfo ori) {
         // Global post-match and name-bound response filters
         JAXRSUtils.runContainerResponseFilters(providerFactory, response, message, ori);
         Response updatedResponse = message.get(Response.class);
@@ -139,7 +155,6 @@ public class JAXRSOutInterceptor extends
             response = updatedResponse;
         }
         
-        
         List<ProviderInfo<ResponseHandler>> handlers = 
             ProviderFactory.getInstance(message).getResponseHandlers();
         for (ProviderInfo<ResponseHandler> rh : handlers) {
@@ -151,10 +166,9 @@ public class JAXRSOutInterceptor extends
             }
             
         }
-        
-        serializeMessage(message, response, ori, true);        
+        return response;
     }
-
+    
     private int getStatus(Message message, int defaultValue) {
         Object customStatus = message.getExchange().get(Message.RESPONSE_CODE);
         return customStatus == null ? defaultValue : (Integer)customStatus;
@@ -356,6 +370,18 @@ public class JAXRSOutInterceptor extends
         }
     }
     
+    private Response handleFilterException(ProviderFactory pf,
+                                       Message message, 
+                                       Response response, 
+                                       OperationResourceInfo ori,
+                                       Throwable ex) {
+        Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
+        if (excResponse != null) {
+            return runResponseFilters(pf, message, excResponse, ori);
+        }
+        throw new InternalServerErrorException(ex);
+    }
+    
     private void handleWriteException(Message message, 
                                          Response response, 
                                          OperationResourceInfo ori,



Mime
View raw message