cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1528061 - in /cxf/branches/2.7.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Tue, 01 Oct 2013 12:06:29 GMT
Author: sergeyb
Date: Tue Oct  1 12:06:29 2013
New Revision: 1528061

URL: http://svn.apache.org/r1528061
Log:
Merged revisions 1528024 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1528024 | sergeyb | 2013-10-01 10:54:31 +0100 (Tue, 01 Oct 2013) | 1 line
  
  [CXF-5314] Initial/basic support for inFaultInterceptors in JAX-RS client runtime
........

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/client/AbstractClient.java
    cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.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/JAXRSLocalTransportTest.java
    cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java

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

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

Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1528061&r1=1528060&r2=1528061&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Tue Oct  1 12:06:29 2013
@@ -66,6 +66,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;
@@ -888,6 +889,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,
@@ -924,6 +937,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/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java?rev=1528061&r1=1528060&r2=1528061&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
(original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
Tue Oct  1 12:06:29 2013
@@ -356,7 +356,8 @@ 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);
         
         if (headers != null && addHeaders) {

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=1528061&r1=1528060&r2=1528061&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 12:06:29 2013
@@ -497,13 +497,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/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java?rev=1528061&r1=1528060&r2=1528061&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSLocalTransportTest.java
Tue Oct  1 12:06:29 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/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=1528061&r1=1528060&r2=1528061&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/branches/2.7.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Tue Oct  1 12:06:29 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