cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6368] Updating the default fault out interceptor not to interfere with the JAX-RS flow in case of the second-time unmapped exceptions
Date Fri, 24 Apr 2015 10:04:17 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes 372c207ca -> a27081146


[CXF-6368] Updating the default fault out interceptor not to interfere with the JAX-RS flow
in case of the second-time unmapped exceptions


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/a2708114
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/a2708114
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/a2708114

Branch: refs/heads/3.0.x-fixes
Commit: a270811466ef702756ba04cc8d06a9886ef8d1ff
Parents: 372c207
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Fri Apr 24 11:02:55 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Fri Apr 24 11:04:01 2015 +0100

----------------------------------------------------------------------
 .../JAXRSDefaultFaultOutInterceptor.java        |  4 ++
 .../jaxrs/interceptor/JAXRSOutInterceptor.java  |  2 +
 .../org/apache/cxf/jaxrs/utils/JAXRSUtils.java  |  1 +
 .../apache/cxf/systest/jaxrs/BookServer.java    | 45 ++++++++++++++++++++
 .../jaxrs/JAXRSClientServerBookTest.java        |  7 +++
 5 files changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a2708114/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
index c2b5309..b53ac0e 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
@@ -28,6 +28,7 @@ import javax.xml.stream.XMLStreamWriter;
 import org.w3c.dom.Node;
 
 import org.apache.cxf.common.i18n.BundleUtils;
+import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.helpers.NSStack;
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
@@ -52,6 +53,9 @@ public class JAXRSDefaultFaultOutInterceptor extends AbstractOutDatabindingInter
     }
 
     public void handleMessage(Message message) throws Fault {
+        if (PropertyUtils.isTrue(message.getExchange().get(JAXRSUtils.SECOND_JAXRS_EXCEPTION)))
{
+            return;
+        }
         final Fault f = (Fault) message.getContent(Exception.class);
         
         Response r = JAXRSUtils.convertFaultToResponse(f.getCause(), message);

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2708114/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
index f800c08..505f84a 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
@@ -363,6 +363,8 @@ public class JAXRSOutInterceptor extends AbstractOutDatabindingInterceptor
{
         Response excResponse = null;
         if (firstTry) {
             excResponse = JAXRSUtils.convertFaultToResponse(ex, message);
+        } else {
+            message.getExchange().put(JAXRSUtils.SECOND_JAXRS_EXCEPTION, Boolean.TRUE);
         }
         if (excResponse == null) {
             setResponseStatus(message, 500);

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2708114/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
index 3aac1a0..a25ff9c 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
@@ -149,6 +149,7 @@ public final class JAXRSUtils {
     public static final String ROOT_INSTANCE = "service.root.instance";
     public static final String ROOT_PROVIDER = "service.root.provider";
     public static final String EXCEPTION_FROM_MAPPER = "exception.from.mapper";
+    public static final String SECOND_JAXRS_EXCEPTION = "second.jaxrs.exception";
     public static final String PARTIAL_HIERARCHICAL_MEDIA_SUBTYPE_CHECK = 
         "media.subtype.partial.check"; 
     public static final String DOC_LOCATION = "wadl.location";

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2708114/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
index be25b8f..c721141 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
@@ -19,17 +19,24 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.container.PreMatching;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.ExceptionMapper;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.LoggingInInterceptor;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
@@ -90,6 +97,9 @@ public class BookServer extends AbstractBusTestServerBase {
         providers.add(new FaultyRequestHandler());
         providers.add(new SearchContextProvider());
         providers.add(new QueryContextProvider());
+        providers.add(new BlockingRequestFilter());
+        providers.add(new FaultyResponseFilter());
+        providers.add(new BlockedExceptionMapper());
         sf.setProviders(providers);
         List<Interceptor<? extends Message>> inInts = new ArrayList<Interceptor<?
extends Message>>();
         inInts.add(new CustomInFaultyInterceptor());
@@ -142,4 +152,39 @@ public class BookServer extends AbstractBusTestServerBase {
         }
         
     }
+    @PreMatching
+    private static class BlockingRequestFilter implements ContainerRequestFilter {
+
+        @Override
+        public void filter(ContainerRequestContext requestContext) throws IOException {
+            if (requestContext.getUriInfo().getPath().endsWith("/blockAndThrowException"))
{
+                requestContext.setProperty("blocked", Boolean.TRUE);
+                requestContext.abortWith(Response.ok().build());
+            }
+        }
+        
+    }
+    private static class FaultyResponseFilter implements ContainerResponseFilter {
+        @Override
+        public void filter(ContainerRequestContext requestContext, ContainerResponseContext
responseContext)
+            throws IOException {
+            if (PropertyUtils.isTrue(requestContext.getProperty("blocked"))) {
+                throw new BlockedException();
+            }
+        }
+        
+    }
+    private static class BlockedExceptionMapper implements ExceptionMapper<BlockedException>
{
+
+        @Override
+        public Response toResponse(BlockedException exception) {
+            return Response.ok().build();
+        }
+        
+        
+    }
+    @SuppressWarnings("serial")
+    public static class BlockedException extends RuntimeException {
+        
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/a2708114/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index d3ecb51..3cc7e35 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -100,6 +100,13 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
     }
     
     @Test
+    public void testBlockAndTrowException() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/blockAndThrowException";
+        WebClient wc = WebClient.create(address);
+        Response r = wc.get();
+        assertEquals(500, r.getStatus());
+    }
+    @Test
     public void testGetBookRoot() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/;JSESSIONID=xxx";
         WebClient wc = WebClient.create(address);


Mime
View raw message