cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1479604 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: interceptor/JAXRSInInterceptor.java utils/JAXRSUtils.java
Date Mon, 06 May 2013 15:25:01 GMT
Author: sergeyb
Date: Mon May  6 15:25:01 2013
New Revision: 1479604

URL: http://svn.apache.org/r1479604
Log:
[CXF-4988] The exceptions thrown from readers should be mapped too

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=1479604&r1=1479603&r2=1479604&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Mon May  6 15:25:01 2013
@@ -37,6 +37,7 @@ import javax.ws.rs.core.Response;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
@@ -94,15 +95,10 @@ public class JAXRSInInterceptor extends 
         
         try {
             processRequest(message);
+        } catch (Fault ex) {
+            convertExceptionToResponseIfPossible(ex.getCause(), message);
         } catch (RuntimeException ex) {
-            Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
-            if (excResponse == null) {
-                ServerProviderFactory.getInstance(message).clearThreadLocalProxies();
-                message.getExchange().put(Message.PROPOGATE_EXCEPTION, 
-                                          JAXRSUtils.propogateException(message));
-                throw ex;
-            }
-            message.getExchange().put(Response.class, excResponse);
+            convertExceptionToResponseIfPossible(ex, message);
         }
         
         
@@ -207,16 +203,22 @@ public class JAXRSInInterceptor extends 
             List<Object> params = JAXRSUtils.processParameters(ori, matchedValues,
message);
             message.setContent(List.class, params);
         } catch (IOException ex) {
-            Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
-            if (excResponse == null) {
-                throw new InternalServerErrorException(ex);
-            } else {
-                message.getExchange().put(Response.class, excResponse);
-            }
+            convertExceptionToResponseIfPossible(ex, message);
         }
         
     }
     
+    private void convertExceptionToResponseIfPossible(Throwable ex, Message message) {
+        Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
+        if (excResponse == null) {
+            ServerProviderFactory.getInstance(message).clearThreadLocalProxies();
+            message.getExchange().put(Message.PROPOGATE_EXCEPTION, 
+                                      JAXRSUtils.propogateException(message));
+            throw ex instanceof RuntimeException ? (RuntimeException)ex : new InternalServerErrorException(ex);
+        }
+        message.getExchange().put(Response.class, excResponse);
+    }
+    
     private void setExchangeProperties(Message message, OperationResourceInfo ori, 
                                       MultivaluedMap<String, String> values,
                                       int numberOfResources) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1479604&r1=1479603&r2=1479604&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Mon
May  6 15:25:01 2013
@@ -103,6 +103,7 @@ import org.apache.cxf.common.util.Packag
 import org.apache.cxf.common.util.ReflectionUtil;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.XMLUtils;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.ext.ContextProvider;
 import org.apache.cxf.jaxrs.ext.MessageContext;
@@ -1290,7 +1291,7 @@ public final class JAXRSUtils {
                 } catch (WebApplicationException ex) {
                     throw ex;
                 } catch (Exception ex) {
-                    throw new WebApplicationException(ex);
+                    throw new Fault(ex);
                 }
             } else {
                 String errorMessage = new org.apache.cxf.common.i18n.Message("NO_MSG_READER",



Mime
View raw message