cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r792190 - in /cxf/branches/2.2.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/ systests/src/test/java/org/apache/cxf/systest/jaxrs/
Date Wed, 08 Jul 2009 15:36:25 GMT
Author: sergeyb
Date: Wed Jul  8 15:36:24 2009
New Revision: 792190

URL: http://svn.apache.org/viewvc?rev=792190&view=rev
Log:
Merged revisions 792183 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r792183 | sergeyb | 2009-07-08 16:19:27 +0100 (Wed, 08 Jul 2009) | 1 line
  
  JAX-RS : access for proxy and http clients to its config
........

Added:
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
      - copied unchanged from r792183, cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientMessageObserver.java
Modified:
    cxf/branches/2.2.x-fixes/   (props changed)
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java
    cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
    cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java

Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul  8 15:36:24 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792096
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792096,792183

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

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=792190&r1=792189&r2=792190&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Wed Jul  8 15:36:24 2009
@@ -29,6 +29,7 @@
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
@@ -47,7 +48,6 @@
 import javax.ws.rs.ext.MessageBodyWriter;
 
 import org.apache.cxf.Bus;
-import org.apache.cxf.BusFactory;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.endpoint.ConduitSelector;
@@ -75,7 +75,9 @@
 public class AbstractClient implements Client {
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractClient.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractClient.class);
-
+    private static final String REQUEST_CONTEXT = "RequestContext";
+    private static final String RESPONSE_CONTEXT = "ResponseContext";
+    
     protected ClientConfiguration cfg = new ClientConfiguration();
     
     private MultivaluedMap<String, String> requestHeaders = new MetadataMap<String,
String>();
@@ -495,19 +497,19 @@
         message.getExchange().put(ConduitSelector.class, cfg.getConduitSelector());
     }
     
-    protected PhaseInterceptorChain setupOutInterceptorChain(Endpoint endpoint) { 
+    protected static PhaseInterceptorChain setupOutInterceptorChain(ClientConfiguration cfg)
{ 
         PhaseManager pm = cfg.getBus().getExtension(PhaseManager.class);
         List<Interceptor> i1 = cfg.getBus().getOutInterceptors();
         List<Interceptor> i2 = cfg.getOutInterceptors();
-        List<Interceptor> i3 = endpoint.getOutInterceptors();
+        List<Interceptor> i3 = cfg.getConduitSelector().getEndpoint().getOutInterceptors();
         return new PhaseChainCache().get(pm.getOutPhases(), i1, i2, i3);
     }
     
-    protected PhaseInterceptorChain setupInInterceptorChain(Endpoint endpoint) { 
+    protected static PhaseInterceptorChain setupInInterceptorChain(ClientConfiguration cfg)
{ 
         PhaseManager pm = cfg.getBus().getExtension(PhaseManager.class);
         List<Interceptor> i1 = cfg.getBus().getInInterceptors();
         List<Interceptor> i2 = cfg.getInInterceptors();
-        List<Interceptor> i3 = endpoint.getInInterceptors();
+        List<Interceptor> i3 = cfg.getConduitSelector().getEndpoint().getInInterceptors();
         return new PhaseChainCache().get(pm.getInPhases(), i1, i2, i3);
     }
     
@@ -536,44 +538,28 @@
         exchange.setSynchronous(true);
         exchange.setOutMessage(m);
         exchange.put(Bus.class, cfg.getBus());
-        exchange.put(MessageObserver.class, new ClientMessageObserver());
+        exchange.put(MessageObserver.class, new ClientMessageObserver(cfg));
         exchange.put(Endpoint.class, cfg.getConduitSelector().getEndpoint());
         exchange.setOneWay(false);
         m.setExchange(exchange);
         
-        PhaseInterceptorChain chain = setupOutInterceptorChain(cfg.getConduitSelector().getEndpoint());
+        PhaseInterceptorChain chain = setupOutInterceptorChain(cfg);
         m.setInterceptorChain(chain);
         
+        // context
+        if (cfg.getRequestContext().size() > 0 || cfg.getResponseContext().size() >
0) {
+            Map<String, Object> context = new HashMap<String, Object>();
+            context.put(REQUEST_CONTEXT, cfg.getRequestContext());
+            context.put(RESPONSE_CONTEXT, cfg.getResponseContext());
+            m.put(Message.INVOCATION_CONTEXT, context);
+            m.putAll(cfg.getRequestContext());
+            exchange.putAll(cfg.getRequestContext());
+        }
+        
         //setup conduit selector
         prepareConduitSelector(m);
         
         return m;
     }
 
-    private class ClientMessageObserver implements MessageObserver {
-
-        public void onMessage(Message m) {
-            
-            Message message = cfg.getConduitSelector().getEndpoint().getBinding().createMessage(m);
-            message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
-            message.put(Message.INBOUND_MESSAGE, Boolean.TRUE);
-            PhaseInterceptorChain chain = setupInInterceptorChain(cfg.getConduitSelector().getEndpoint());
-            message.setInterceptorChain(chain);
-            message.getExchange().setInMessage(message);
-            Bus origBus = BusFactory.getThreadDefaultBus(false);
-            BusFactory.setThreadDefaultBus(cfg.getBus());
-
-            // execute chain
-            try {
-                chain.doIntercept(message);
-            } finally {
-                BusFactory.setThreadDefaultBus(origBus);
-            }
-        }
-        
-    }
-
-    
-
-
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java?rev=792190&r1=792189&r2=792190&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientConfiguration.java
Wed Jul  8 15:36:24 2009
@@ -18,13 +18,21 @@
  */
 package org.apache.cxf.jaxrs.client;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.common.util.ModCountCopyOnWriteArrayList;
 import org.apache.cxf.endpoint.ConduitSelector;
 import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.interceptor.InterceptorProvider;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.MessageObserver;
 
 public class ClientConfiguration implements InterceptorProvider {
 
@@ -34,7 +42,10 @@
     private List<Interceptor> inFault  = new ModCountCopyOnWriteArrayList<Interceptor>();
     private ConduitSelector conduitSelector;
     private Bus bus;
-
+    private Map<String, Object> requestContext = new HashMap<String, Object>();
+    private Map<String, Object> responseContext = new HashMap<String, Object>();
+    
+    
     public void setConduitSelector(ConduitSelector cs) {
         this.conduitSelector = cs;
     }
@@ -82,4 +93,21 @@
     public void setOutFaultInterceptors(List<Interceptor> interceptors) {
         outFault = interceptors;
     }
+    
+    public Conduit getConduit() {
+        Message message = new MessageImpl();
+        Exchange exchange = new ExchangeImpl();
+        message.setExchange(exchange);
+        exchange.put(MessageObserver.class, new ClientMessageObserver(this));
+        exchange.put(Bus.class, bus);
+        return getConduitSelector().selectConduit(message);
+    }
+    
+    public Map<String, Object> getResponseContext() {
+        return responseContext;
+    }
+    
+    public Map<String, Object> getRequestContext() {
+        return requestContext;
+    }
 }

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=792190&r1=792189&r2=792190&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Wed Jul  8 15:36:24 2009
@@ -176,6 +176,23 @@
     }
     
     /**
+     * Retieves ClientConfiguration
+     * @param client proxy or http-centric Client
+     * @return underlying ClientConfiguration instance 
+     */
+    public static ClientConfiguration getConfig(Object client) {
+        if (client instanceof Client) {
+            if (client instanceof WebClient) { 
+                return ((AbstractClient)client).getConfiguration();
+            } else if (client instanceof InvocationHandlerAware) {
+                Object handler = ((InvocationHandlerAware)client).getInvocationHandler();
+                return ((AbstractClient)handler).getConfiguration();
+            }
+        }
+        throw new IllegalArgumentException("Not a valid Client");
+    }
+    
+    /**
      * Does HTTP invocation
      * @param httpMethod HTTP method
      * @param body request body, can be null

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java?rev=792190&r1=792189&r2=792190&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBeanTest.java
Wed Jul  8 15:36:24 2009
@@ -31,6 +31,8 @@
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
+import org.apache.cxf.transport.Conduit;
+import org.apache.cxf.transport.http.HTTPConduit;
 
 import org.junit.Assert;
 import org.junit.Test;
@@ -46,6 +48,16 @@
     }
     
     @Test
+    public void testGetConduit() throws Exception {
+        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setAddress("http://bar");
+        bean.setResourceClass(BookStore.class);
+        BookStore store = bean.create(BookStore.class);
+        Conduit conduit = WebClient.getConfig(store).getConduit();
+        assertTrue(conduit instanceof HTTPConduit);
+    }
+    
+    @Test
     public void testTemplateInRootPathInherit() throws Exception {
         JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
         bean.setAddress("http://bar");

Modified: cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java?rev=792190&r1=792189&r2=792190&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
(original)
+++ cxf/branches/2.2.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/client/WebClientTest.java
Wed Jul  8 15:36:24 2009
@@ -21,6 +21,9 @@
 
 import java.net.URI;
 
+import org.apache.cxf.jaxrs.resources.BookInterface;
+import org.apache.cxf.jaxrs.resources.BookStore;
+
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -143,4 +146,21 @@
         assertEquals(URI.create("http://foo"), wc.getBaseURI());
         assertEquals(URI.create("http://foo/1/2"), wc.getCurrentURI());
     }
+    
+    @Test
+    public void testWebClientConfiguration() {
+        WebClient wc = WebClient.create(URI.create("http://foo"));
+        assertNotNull(WebClient.getConfig(wc) != null);
+    }
+    
+    @Test
+    public void testProxyConfiguration() {
+        // interface
+        BookInterface proxy = JAXRSClientFactory.create("http://foo", BookInterface.class);
+        assertNotNull(WebClient.getConfig(proxy) != null);
+        // cglib
+        BookStore proxy2 = JAXRSClientFactory.create("http://foo", BookStore.class);
+        assertNotNull(WebClient.getConfig(proxy2) != null);
+    }
+    
 }

Modified: cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=792190&r1=792189&r2=792190&view=diff
==============================================================================
--- cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
(original)
+++ cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
Wed Jul  8 15:36:24 2009
@@ -58,6 +58,7 @@
 import org.apache.cxf.phase.AbstractPhaseInterceptor;
 import org.apache.cxf.phase.Phase;
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.transport.http.HTTPConduit;
 
 import org.junit.BeforeClass;
 import org.junit.Ignore;
@@ -104,9 +105,14 @@
         String baseAddress = "http://localhost:9092/test/services/rest";
         BookStoreJaxrsJaxws proxy = JAXRSClientFactory.create(baseAddress,
                                                                   BookStoreJaxrsJaxws.class);
+        HTTPConduit conduit = (HTTPConduit)WebClient.getConfig(proxy).getConduit();
+        
         Book b = proxy.getBook(new Long("123"));
         assertEquals(123, b.getId());
         assertEquals("CXF in Action", b.getName());
+        
+        HTTPConduit conduit2 = (HTTPConduit)WebClient.getConfig(proxy).getConduit();
+        assertSame(conduit, conduit2);
     }
     
     @Test



Mime
View raw message