cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1528024 - in /cxf/trunk: rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Tue, 01 Oct 2013 09:54:32 GMT
Author: sergeyb
Date: Tue Oct  1 09:54:31 2013
New Revision: 1528024

URL: http://svn.apache.org/r1528024
Log:
[CXF-5314] Initial/basic support for inFaultInterceptors in JAX-RS client runtime

Modified:
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1528024&r1=1528023&r2=1528024&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java (original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java Tue
Oct  1 09:54:31 2013
@@ -62,6 +62,7 @@ import org.apache.cxf.endpoint.Retryable
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.InFaultChainInitiatorObserver;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.StaxInEndingInterceptor;
 import org.apache.cxf.jaxrs.client.spec.ClientRequestFilterInterceptor;
@@ -828,6 +829,18 @@ public abstract class AbstractClient imp
         return chain;
     }
     
+    protected static MessageObserver setupInFaultObserver(final ClientConfiguration cfg)
{ 
+        if (!cfg.getInFaultInterceptors().isEmpty()) {
+            return new InFaultChainInitiatorObserver(cfg.getBus()) {
+                protected void initializeInterceptors(Exchange ex, PhaseInterceptorChain
chain) {
+                    chain.add(cfg.getInFaultInterceptors());
+                }
+            };
+        } else {
+            return null;
+        }
+    }
+    
     protected Message createMessage(Object body,
                                     String httpMethod, 
                                     MultivaluedMap<String, String> headers,
@@ -864,6 +877,7 @@ public abstract class AbstractClient imp
         m.put(URITemplate.TEMPLATE_PARAMETERS, getState().getTemplates());
         
         PhaseInterceptorChain chain = setupOutInterceptorChain(cfg);
+        chain.setFaultObserver(setupInFaultObserver(cfg));
         m.setInterceptorChain(chain);
         
         exchange = createExchange(m, exchange);

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java?rev=1528024&r1=1528023&r2=1528024&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
Tue Oct  1 09:54:31 2013
@@ -354,6 +354,7 @@ public class JAXRSClientFactoryBean exte
         client.getConfiguration().getOutInterceptors().addAll(ep.getOutInterceptors());
         client.getConfiguration().getInInterceptors().addAll(getInInterceptors());
         client.getConfiguration().getInInterceptors().addAll(ep.getInInterceptors());
+        client.getConfiguration().getInFaultInterceptors().addAll(getInFaultInterceptors());
 
         applyFeatures(client);
         

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1528024&r1=1528023&r2=1528024&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue
Oct  1 09:54:31 2013
@@ -498,13 +498,13 @@ public class BookStore {
     
     @GET
     @Path("infault")
-    public Response infault() throws Exception {
+    public Response infault() {
         throw new RuntimeException();
     }
     
     @GET
     @Path("outfault")
-    public Response outfault() throws Exception {
+    public Response outfault() {
         return Response.ok().build();
     }
     

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java?rev=1528024&r1=1528023&r2=1528024&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
Tue Oct  1 09:54:31 2013
@@ -19,19 +19,28 @@
 
 package org.apache.cxf.systest.jaxrs;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import javax.ws.rs.core.Response;
 
 import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.interceptor.Fault;
+import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
 import org.apache.cxf.jaxrs.client.WebClient;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.phase.AbstractPhaseInterceptor;
+import org.apache.cxf.phase.Phase;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.apache.cxf.transport.local.LocalConduit;
 import org.apache.cxf.transport.local.LocalTransportFactory;
 
 import org.junit.After;
 import org.junit.Before;
+import org.junit.Ignore;
 import org.junit.Test;
 
 public class JAXRSLocalTransportTest extends AbstractBusClientServerTestBase {
@@ -46,6 +55,10 @@ public class JAXRSLocalTransportTest ext
                                new SingletonResourceProvider(new BookStore(), true));
         sf.setResourceProvider(BookStoreSpring.class,
                                new SingletonResourceProvider(new BookStoreSpring(), true));
+        List<Interceptor<? extends Message>> outInts = new ArrayList<Interceptor<?
extends Message>>();
+        outInts.add(new CustomOutInterceptor());
+        sf.setOutInterceptors(outInts);
+        
         sf.setTransportId(LocalTransportFactory.TRANSPORT_ID);
         sf.setAddress("local://books");
         localServer = sf.create();
@@ -67,6 +80,54 @@ public class JAXRSLocalTransportTest ext
     }
     
     @Test
+    @Ignore
+    public void testProxyServerInFault() throws Exception {
+        BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class);
+        Response r = localProxy.infault();
+        assertEquals(500, r.getStatus());
+    }
+    
+    @Test
+    public void testProxyServerInFaultDirectDispatch() throws Exception {
+        BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class);
+        WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
"true");
+        WebClient.getConfig(localProxy).getInFaultInterceptors().add(new TestFaultInInterceptor());
+        Response r = localProxy.infault();
+        assertEquals(500, r.getStatus());
+    }
+    
+    @Test
+    @Ignore
+    public void testProxyEmtpyResponse() throws Exception {
+        BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class);
+        assertNull(localProxy.getEmptyBook());
+        assertEquals(204, WebClient.client(localProxy).getResponse().getStatus());
+    }
+    
+    @Test
+    public void testProxyEmptyResponseDirectDispatch() throws Exception {
+        BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class);
+        WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
"true");
+        assertNull(localProxy.getEmptyBook());
+        assertEquals(204, WebClient.client(localProxy).getResponse().getStatus());
+    }
+    
+    @Test
+    public void testProxyServerOutFault() throws Exception {
+        BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class);
+        Response r = localProxy.outfault();
+        assertEquals(500, r.getStatus());
+    }
+    
+    @Test
+    public void testProxyServerOutFaultDirectDispacth() throws Exception {
+        BookStore localProxy = JAXRSClientFactory.create("local://books", BookStore.class);
+        WebClient.getConfig(localProxy).getRequestContext().put(LocalConduit.DIRECT_DISPATCH,
"true");
+        Response r = localProxy.outfault();
+        assertEquals(500, r.getStatus());
+    }
+    
+    @Test
     public void testSubresourceProxyDirectDispatchGet() throws Exception {
         BookStore localProxy = 
             JAXRSClientFactory.create("local://books", BookStore.class);
@@ -138,4 +199,20 @@ public class JAXRSLocalTransportTest ext
         Book book = localProxy.getBookByURLQuery(new String[] {"1", "2", "3"});
         assertEquals(123L, book.getId());
     }
+    
+    private static class TestFaultInInterceptor extends AbstractPhaseInterceptor<Message>
{
+        public TestFaultInInterceptor() {
+            this(Phase.PRE_STREAM);
+        }
+
+        public TestFaultInInterceptor(String s) {
+            super(Phase.PRE_STREAM);
+            
+        } 
+
+        public void handleMessage(Message message) throws Fault {
+            message.getExchange().put(Message.RESPONSE_CODE, 500);
+        }
+
+    }
 }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1528024&r1=1528023&r2=1528024&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Tue Oct  1 09:54:31 2013
@@ -94,7 +94,7 @@ public class JAXRSSoapBookTest extends A
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
-                   launchServer(BookServerRestSoap.class));
+                   launchServer(BookServerRestSoap.class, true));
     }
     
     @Test
@@ -897,7 +897,7 @@ public class JAXRSSoapBookTest extends A
             assertTrue("Wrong exception caught", 
                        "fault from bad interceptor".equals(e.getCause().getMessage()));
             assertTrue("Client In Fault In Interceptor was invoked", 
-                    !testFeature.faultInInterceptorCalled());
+                    testFeature.faultInInterceptorCalled());
         }
     }
     



Mime
View raw message