cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1528046 - in /cxf/branches/2.7.x-fixes: ./ api/src/main/java/org/apache/cxf/logging/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Tue, 01 Oct 2013 11:39:44 GMT
Author: sergeyb
Date: Tue Oct  1 11:39:43 2013
New Revision: 1528046

URL: http://svn.apache.org/r1528046
Log:
Merged revisions 1526284,1526286 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1526284 | sergeyb | 2013-09-25 21:12:46 +0100 (Wed, 25 Sep 2013) | 1 line
  
  [CXF-5300] Trying to map exceptions thrown from in or out interceptors to JAX-RS Response
........
  r1526286 | sergeyb | 2013-09-25 21:16:24 +0100 (Wed, 25 Sep 2013) | 1 line
  
  [CXF-5300] Adding a missing test resource
........

Added:
    cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/logging/NoOpFaultListener.java
  (with props)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
      - copied unchanged from r1526286, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSDefaultFaultOutInterceptor.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutExceptionMapperInterceptor.java
      - copied, changed from r1526286, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutExceptionMapperInterceptor.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomInFaultyInterceptor.java
      - copied unchanged from r1526286, cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomInFaultyInterceptor.java
Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutInterceptor.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1526284-1526286

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Added: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/logging/NoOpFaultListener.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/logging/NoOpFaultListener.java?rev=1528046&view=auto
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/logging/NoOpFaultListener.java
(added)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/logging/NoOpFaultListener.java
Tue Oct  1 11:39:43 2013
@@ -0,0 +1,33 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.logging;
+
+import org.apache.cxf.message.Message;
+
+/**
+ * Utility FaultListener for blocking the default PhaseInterceptorChain fault logging
+ */
+public class NoOpFaultListener implements FaultListener {
+
+    @Override
+    public boolean faultOccurred(Exception exception, String description, Message message)
{
+        return false;
+    }
+
+}

Propchange: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/logging/NoOpFaultListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/logging/NoOpFaultListener.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java?rev=1528046&r1=1528045&r2=1528046&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSInInterceptor.java
Tue Oct  1 11:39:43 2013
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxrs.interceptor;
 
 import java.io.IOException;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
@@ -37,8 +38,11 @@ import javax.ws.rs.core.Response;
 
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.interceptor.OutgoingChainInterceptor;
 import org.apache.cxf.jaxrs.JAXRSServiceImpl;
 import org.apache.cxf.jaxrs.ext.RequestHandler;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -53,7 +57,11 @@ import org.apache.cxf.jaxrs.provider.Pro
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.logging.FaultListener;
+import org.apache.cxf.logging.NoOpFaultListener;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageContentsList;
+import org.apache.cxf.message.MessageImpl;
 import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
@@ -69,28 +77,7 @@ public class JAXRSInInterceptor extends 
         super(Phase.UNMARSHAL);
     }
 
-    @Override
-    public void handleFault(Message message) {
-        super.handleFault(message);
-        
-        LOG.fine("Cleanup thread local variables");
-        
-        Object rootInstance = message.getExchange().remove(JAXRSUtils.ROOT_INSTANCE);
-        Object rootProvider = message.getExchange().remove(JAXRSUtils.ROOT_PROVIDER);
-        if (rootInstance != null && rootProvider != null) {
-            try {
-                ((ResourceProvider)rootProvider).releaseInstance(message, rootInstance);
-            } catch (Throwable tex) {
-                LOG.warning("Exception occurred during releasing the service instance, "
+ tex.getMessage());
-            }
-        }
-        ProviderFactory.getInstance(message).clearThreadLocalProxies();
-        ClassResourceInfo cri = (ClassResourceInfo)message.getExchange().get(JAXRSUtils.ROOT_RESOURCE_CLASS);
-        if (cri != null) {
-            cri.clearThreadLocalProxies();
-        }
-    }
-    
+
     public void handleMessage(Message message) {
         
         if (message.getExchange().get(OperationResourceInfo.class) != null) {
@@ -297,4 +284,55 @@ public class JAXRSInInterceptor extends 
             || MessageUtils.isTrue(HttpUtils.getProtocolHeader(message, Message.ONE_WAY_REQUEST,
null));
         message.getExchange().setOneWay(oneway);
     }
+    
+    @Override
+    public void handleFault(Message message) {
+        super.handleFault(message);
+        
+        Response r = JAXRSUtils.convertFaultToResponse(message.getContent(Exception.class),

+                                                       message);
+        if (r != null) {
+            message.removeContent(Exception.class);
+            message.getInterceptorChain().setFaultObserver(null);
+            if (message.getContextualProperty(FaultListener.class.getName()) == null) {
+                message.put(FaultListener.class.getName(), new NoOpFaultListener());
+            }
+            
+            Endpoint e = message.getExchange().get(Endpoint.class);
+            Message mout = new MessageImpl();
+            mout.setContent(List.class, new MessageContentsList(r));
+            mout.setExchange(message.getExchange());
+            mout = e.getBinding().createMessage(mout);
+            mout.setInterceptorChain(OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange()));
+            message.getExchange().setOutMessage(mout);
+            
+            
+            Iterator<Interceptor<? extends Message>> iterator = message.getInterceptorChain().iterator();
+            while (iterator.hasNext()) {
+                Interceptor<? extends Message> inInterceptor = iterator.next();
+                if (inInterceptor.getClass() == OutgoingChainInterceptor.class) {
+                    ((OutgoingChainInterceptor)inInterceptor).handleMessage(message);
+                    return;
+                }
+            }
+        }
+        
+        
+        LOG.fine("Cleanup thread local variables");
+        
+        Object rootInstance = message.getExchange().remove(JAXRSUtils.ROOT_INSTANCE);
+        Object rootProvider = message.getExchange().remove(JAXRSUtils.ROOT_PROVIDER);
+        if (rootInstance != null && rootProvider != null) {
+            try {
+                ((ResourceProvider)rootProvider).releaseInstance(message, rootInstance);
+            } catch (Throwable tex) {
+                LOG.warning("Exception occurred during releasing the service instance, "
+ tex.getMessage());
+            }
+        }
+        ProviderFactory.getInstance(message).clearThreadLocalProxies();
+        ClassResourceInfo cri = (ClassResourceInfo)message.getExchange().get(JAXRSUtils.ROOT_RESOURCE_CLASS);
+        if (cri != null) {
+            cri.clearThreadLocalProxies();
+        }
+    }
 }

Copied: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutExceptionMapperInterceptor.java
(from r1526286, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutExceptionMapperInterceptor.java)
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutExceptionMapperInterceptor.java?p2=cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutExceptionMapperInterceptor.java&p1=cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutExceptionMapperInterceptor.java&r1=1526286&r2=1528046&rev=1528046&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutExceptionMapperInterceptor.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutExceptionMapperInterceptor.java
Tue Oct  1 11:39:43 2013
@@ -32,7 +32,7 @@ import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
-import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.logging.FaultListener;
 import org.apache.cxf.logging.NoOpFaultListener;
@@ -100,7 +100,7 @@ public class JAXRSOutExceptionMapperInte
                 LOG.warning("Exception occurred during releasing the service instance, "
+ tex.getMessage());
             }
         }
-        ServerProviderFactory.getInstance(message).clearThreadLocalProxies();
+        ProviderFactory.getInstance(message).clearThreadLocalProxies();
         ClassResourceInfo cri = (ClassResourceInfo)message.getExchange().get(JAXRSUtils.ROOT_RESOURCE_CLASS);
         if (cri != null) {
             cri.clearThreadLocalProxies();

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1528046&r1=1528045&r2=1528046&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Tue Oct  1 11:39:43 2013
@@ -79,11 +79,13 @@ public class JAXRSOutInterceptor extends
     public JAXRSOutInterceptor() {
         super(Phase.MARSHAL);
     }
-
+    
     public void handleMessage(Message message) {
         ProviderFactory providerFactory = ProviderFactory.getInstance(message);
         try {
             processResponse(providerFactory, message);
+        } catch (Exception ex) {
+            message.put("jaxrs.out.fault", Boolean.TRUE);    
         } finally {
             Object rootInstance = message.getExchange().remove(JAXRSUtils.ROOT_INSTANCE);
             Object rootProvider = message.getExchange().remove(JAXRSUtils.ROOT_PROVIDER);
@@ -489,4 +491,8 @@ public class JAXRSOutInterceptor extends
     private boolean isResponseHeadersCopied(Message message) {
         return MessageUtils.isTrue(message.get(AbstractHTTPDestination.RESPONSE_HEADERS_COPIED));
     }
+    
+    public void handleFault(Message message) {
+        message.put("jaxrs.out.fault", Boolean.TRUE);
+    }
 }

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=1528046&r1=1528045&r2=1528046&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
Tue Oct  1 11:39:43 2013
@@ -37,6 +37,7 @@ import org.apache.cxf.jaxrs.ext.search.Q
 import org.apache.cxf.jaxrs.ext.search.SearchBean;
 import org.apache.cxf.jaxrs.ext.search.SearchContextProvider;
 import org.apache.cxf.jaxrs.ext.search.sql.SQLPrinterVisitor;
+import org.apache.cxf.jaxrs.interceptor.JAXRSOutExceptionMapperInterceptor;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.provider.BinaryDataProvider;
 import org.apache.cxf.jaxrs.provider.JAXBElementProvider;
@@ -78,8 +79,12 @@ public class BookServer extends Abstract
         providers.add(new SearchContextProvider());
         providers.add(new QueryContextProvider());
         sf.setProviders(providers);
+        List<Interceptor<? extends Message>> inInts = new ArrayList<Interceptor<?
extends Message>>();
+        inInts.add(new CustomInFaultyInterceptor());
+        sf.setInInterceptors(inInts);
         List<Interceptor<? extends Message>> outInts = new ArrayList<Interceptor<?
extends Message>>();
         outInts.add(new CustomOutInterceptor());
+        outInts.add(new JAXRSOutExceptionMapperInterceptor());
         sf.setOutInterceptors(outInts);
         List<Interceptor<? extends Message>> outFaultInts = new ArrayList<Interceptor<?
extends Message>>();
         outFaultInts.add(new CustomOutFaultInterceptor());

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1528046&r1=1528045&r2=1528046&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Tue Oct  1 11:39:43 2013
@@ -495,6 +495,18 @@ public class BookStore {
         return Response.status(401).entity("This is 401").build();
     }
     
+    @GET
+    @Path("infault")
+    public Response infault() throws Exception {
+        throw new RuntimeException();
+    }
+    
+    @GET
+    @Path("outfault")
+    public Response outfault() throws Exception {
+        return Response.ok().build();
+    }
+    
     @POST
     @Path("/collections")
     @Produces({"application/xml", "application/json" })

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutInterceptor.java?rev=1528046&r1=1528045&r2=1528046&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutInterceptor.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/CustomOutInterceptor.java
Tue Oct  1 11:39:43 2013
@@ -23,6 +23,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MultivaluedMap;
 
@@ -42,6 +43,11 @@ public class CustomOutInterceptor extend
     @SuppressWarnings("unchecked")
     public void handleMessage(Message message) throws Fault {
         
+        String requestUri = (String)message.getExchange().getInMessage().get(Message.REQUEST_URI);
+        if (requestUri.endsWith("/outfault")) {
+            throw new WebApplicationException(403);
+        }
+        
         HttpHeaders requestHeaders = new HttpHeadersImpl(message.getExchange().getInMessage());
         if (!requestHeaders.getRequestHeader("PLAIN-MAP").isEmpty()) {
             Map<String, List<String>> headers = (Map<String, List<String>>)

Modified: cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1528046&r1=1528045&r2=1528046&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Oct  1 11:39:43 2013
@@ -426,6 +426,27 @@ public class JAXRSClientServerBookTest e
         assertEquals(401, r.getStatus());
         assertEquals("This is 401", getStringFromInputStream((InputStream)r.getEntity()));
     }
+    
+    @Test
+    public void testCapturedServerInFault() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/bookstore/infault"; 
+        WebClient wc = WebClient.create(endpointAddress);
+        Response r = wc.get();
+        assertEquals(401, r.getStatus());
+    }
+    
+    @Test
+    public void testCapturedServerOutFault() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:" + PORT + "/bookstore/outfault"; 
+        WebClient wc = WebClient.create(endpointAddress);
+        WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(1000000L);
+        Response r = wc.get();
+        assertEquals(403, r.getStatus());
+    }
 
     @Test
     public void testGetCollectionOfBooks() throws Exception {



Mime
View raw message