cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r909396 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Fri, 12 Feb 2010 13:25:36 GMT
Author: sergeyb
Date: Fri Feb 12 13:25:35 2010
New Revision: 909396

URL: http://svn.apache.org/viewvc?rev=909396&view=rev
Log:
JAXRS : updates to do with preserving template name/values pairs in proxy-to-subproxy and
thread-safe clients

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientState.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultithreadedClientTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=909396&r1=909395&r2=909396&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Fri Feb 12 13:25:35 2010
@@ -57,6 +57,7 @@
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.UriBuilderImpl;
 import org.apache.cxf.jaxrs.model.ParameterType;
+import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
@@ -293,6 +294,21 @@
         state.setCurrentBuilder(new UriBuilderImpl(uri));
     }
     
+    protected MultivaluedMap<String, String> getTemplateParametersMap(URITemplate template,

+                                                                      List<Object>
values) {
+        if (values != null && values.size() != 0) { 
+            List<String> vars = template.getVariables();
+            MultivaluedMap<String, String> templatesMap =  new MetadataMap<String,
String>(vars.size());
+            for (int i = 0; i < vars.size(); i++) {
+                if (i < values.size()) {
+                    templatesMap.add(vars.get(i), values.get(i).toString());
+                }
+            }
+            return templatesMap;
+        } 
+        return null;
+    }
+    
     protected ResponseBuilder setResponseBuilder(HttpURLConnection conn, Exchange exchange)
throws Throwable {
         Message inMessage = exchange.getInMessage();
         if (conn == null) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=909396&r1=909395&r2=909396&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Fri Feb 12 13:25:35 2010
@@ -163,7 +163,8 @@
                 subHeaders.putAll(headers);    
             }
             
-            ClientState newState = getState().newState(uri, headers);
+            ClientState newState = getState().newState(uri, subHeaders, 
+                 getTemplateParametersMap(ori.getURITemplate(), pathParams));
             ClientProxyImpl proxyImpl = new ClientProxyImpl(newState, subCri, false, inheritHeaders);
             proxyImpl.setConfiguration(getConfiguration());
             return JAXRSClientFactory.create(m.getReturnType(), proxyImpl);
@@ -414,16 +415,10 @@
                           List<Object> pathParams) throws Throwable {
         Message outMessage = createMessage(ori.getHttpMethod(), headers, uri);
         outMessage.getExchange().setOneWay(ori.isOneway());
-        if (pathParams.size() != 0) { 
-            List<String> vars = ori.getURITemplate().getVariables();
-            MultivaluedMap<String, String> templatesMap =  new MetadataMap<String,
String>(vars.size());
-            for (int i = 0; i < vars.size(); i++) {
-                if (i < pathParams.size()) {
-                    templatesMap.add(vars.get(i), pathParams.get(i).toString());
-                }
-            }
-            outMessage.put(URITemplate.TEMPLATE_PARAMETERS, templatesMap);
-        }
+        
+        getState().setTemplates(getTemplateParametersMap(ori.getURITemplate(), pathParams));
+        outMessage.put(URITemplate.TEMPLATE_PARAMETERS, getState().getTemplates());
+        
         outMessage.setContent(OperationResourceInfo.class, ori);
         setPlainOperationNameProperty(outMessage, ori.getMethodToInvoke().getName());
         outMessage.getExchange().put(Method.class, ori.getMethodToInvoke());

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientState.java?rev=909396&r1=909395&r2=909396&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientState.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientState.java
Fri Feb 12 13:25:35 2010
@@ -29,8 +29,9 @@
  * Represents the client state :
  *  - baseURI
  *  - current uri builder
- *  - current requestHeaders,
- *  - current response
+ *  - current requestHeaders
+ *  - current template parameters map
+ *  - last response
  */
 public interface ClientState {
     
@@ -83,6 +84,19 @@
     MultivaluedMap<String, String> getRequestHeaders();
     
     /**
+     * Sets the map containing template name and value pairs
+     * @param templates
+     */
+    void setTemplates(MultivaluedMap<String, String> map);
+    
+    /**
+     * Gets the templates map
+     * @return templates
+     */
+    MultivaluedMap<String, String> getTemplates();
+    
+    
+    /**
      * Resets the current state to the baseURI
      *
      */
@@ -94,8 +108,11 @@
      * subresource proxies and new web clients respectively to ensure thet stay
      * thread-local if needed
      * @param baseURI baseURI
-     * @param headers request headers
+     * @param headers request headers, can be null
+     * @param templates initial templates map, can be null
      * @return client state
      */
-    ClientState newState(URI baseURI, MultivaluedMap<String, String> headers);
+    ClientState newState(URI baseURI, 
+                         MultivaluedMap<String, String> headers,
+                         MultivaluedMap<String, String> templates);
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java?rev=909396&r1=909395&r2=909396&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
Fri Feb 12 13:25:35 2010
@@ -271,7 +271,7 @@
             }
         } else {
             MultivaluedMap<String, String> headers = inheritHeaders ? client.getHeaders()
: null;
-            bean.setInitialState(clientState.newState(client.getCurrentURI(), headers));
+            bean.setInitialState(clientState.newState(client.getCurrentURI(), headers, null));
             proxy = bean.create(cls);
         }
         WebClient.copyProperties(WebClient.client(proxy), client);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java?rev=909396&r1=909395&r2=909396&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
Fri Feb 12 13:25:35 2010
@@ -132,7 +132,7 @@
         }
         if (initialState != null) {
             return headers != null
-                ? initialState.newState(URI.create(getAddress()), headers) : initialState;
+                ? initialState.newState(URI.create(getAddress()), headers, null) : initialState;
         } else {
             return null;
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java?rev=909396&r1=909395&r2=909396&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/LocalClientState.java
Fri Feb 12 13:25:35 2010
@@ -33,6 +33,7 @@
 public class LocalClientState implements ClientState {
     
     private MultivaluedMap<String, String> requestHeaders = new MetadataMap<String,
String>();
+    private MultivaluedMap<String, String> templates;
     private ResponseBuilder responseBuilder;
     private URI baseURI;
     private UriBuilder currentBuilder;
@@ -48,10 +49,10 @@
     
     public LocalClientState(LocalClientState cs) {
         this.requestHeaders = new MetadataMap<String, String>(cs.requestHeaders);
+        this.templates = cs.templates == null ? null : new MetadataMap<String, String>(cs.templates);
         this.responseBuilder = cs.responseBuilder != null ? cs.responseBuilder.clone() :
null;
         this.baseURI = cs.baseURI;
         this.currentBuilder = cs.currentBuilder != null ? cs.currentBuilder.clone() : null;
-        
     }
     
     
@@ -88,17 +89,42 @@
         return requestHeaders;
     }
     
+    public MultivaluedMap<String, String> getTemplates() {
+        return templates;
+    }
+
+    public void setTemplates(MultivaluedMap<String, String> map) {
+        if (templates == null) {
+            this.templates = map;
+        } else if (map != null) {
+            templates.putAll(map);
+        } else {
+            templates = null;
+        }
+    }
+    
     public void reset() {
         requestHeaders.clear();
         responseBuilder = null;
         currentBuilder = UriBuilder.fromUri(baseURI);
+        templates = null;
     }
     
-    public ClientState newState(URI newBaseURI, MultivaluedMap<String, String> headers)
{
+    public ClientState newState(URI newBaseURI, 
+                                MultivaluedMap<String, String> headers,
+                                MultivaluedMap<String, String> templatesMap) {
         ClientState state = new LocalClientState(newBaseURI);
         if (headers != null) {
             state.setRequestHeaders(headers);
         }
+        // we need to carry the template parameters forward
+        MultivaluedMap<String, String> newTemplateParams = templates;
+        if (newTemplateParams != null && templatesMap != null) {
+            newTemplateParams.putAll(templatesMap);
+        } else {
+            newTemplateParams = templatesMap;
+        }
+        state.setTemplates(newTemplateParams);
         return state;
     }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java?rev=909396&r1=909395&r2=909396&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ThreadLocalClientState.java
Fri Feb 12 13:25:35 2010
@@ -83,15 +83,24 @@
         return getState().getRequestHeaders();
     }
     
+    public MultivaluedMap<String, String> getTemplates() {
+        return getState().getTemplates();
+    }
+
+    public void setTemplates(MultivaluedMap<String, String> map) {
+        getState().setTemplates(map);
+    }
+    
     public void reset() {
         removeThreadLocalState(Thread.currentThread());
     }
     
-    public ClientState newState(URI baseURI, MultivaluedMap<String, String> headers)
{
+    public ClientState newState(URI baseURI, 
+                                MultivaluedMap<String, String> headers,
+                                MultivaluedMap<String, String> templates) {
         LocalClientState ls = new LocalClientState(baseURI);
-        if (headers != null) {
-            ls.setRequestHeaders(headers);
-        }
+        ls.setRequestHeaders(headers);
+        ls.setTemplates(templates);
         return new ThreadLocalClientState(ls);
     }
     
@@ -148,4 +157,6 @@
             }
         }
     }
+
+    
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=909396&r1=909395&r2=909396&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Fri
Feb 12 13:25:35 2010
@@ -24,6 +24,7 @@
 import java.lang.reflect.Type;
 import java.net.HttpURLConnection;
 import java.net.URI;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
@@ -48,7 +49,6 @@
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.ext.form.Form;
-import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
@@ -65,8 +65,6 @@
  */
 public class WebClient extends AbstractClient {
     
-    private MultivaluedMap<String, String> templates;
-    
     protected WebClient(String baseAddress) {
         this(URI.create(baseAddress));
     }
@@ -197,7 +195,7 @@
             }
         } else {
             MultivaluedMap<String, String> headers = inheritHeaders ? client.getHeaders()
: null;
-            webClient = new WebClient(clientState.newState(client.getCurrentURI(), headers));
+            webClient = new WebClient(clientState.newState(client.getCurrentURI(), headers,
null));
         }
         copyProperties(webClient, client);
         return webClient;
@@ -411,17 +409,8 @@
      * @return updated WebClient
      */
     public WebClient path(String path, Object... values) {
-        URITemplate t = new URITemplate(path);
-        List<String> vars = t.getVariables();
-        if (vars.size() > 0 && vars.size() == values.length) {
-            if (templates == null) {
-                templates = new MetadataMap<String, String>();
-            }
-            for (int i = 0; i < values.length; i++) {
-                templates.add(vars.get(i), values[i].toString());
-            }
-        }
         URI u = UriBuilder.fromUri(URI.create("http://tempuri")).path(path).buildFromEncoded(values);
+        getState().setTemplates(getTemplateParametersMap(new URITemplate(path), Arrays.asList(values)));
         return path(u.getRawPath());
     }
     
@@ -464,7 +453,7 @@
      * @return updated WebClient
      */
     public WebClient to(String newAddress, boolean forward) {
-        clearTemplates();
+        getState().setTemplates(null);
         if (forward) {
             if (!newAddress.startsWith(getBaseURI().toString())) {
                 throw new IllegalArgumentException("Base address can not be preserved");
@@ -482,7 +471,7 @@
      * @return updated WebClient
      */
     public WebClient back(boolean fast) {
-        clearTemplates();
+        getState().setTemplates(null);
         if (fast) {
             getCurrentBuilder().replacePath(getBaseURI().getPath());
         } else {
@@ -567,7 +556,7 @@
     
     @Override
     public WebClient reset() {
-        clearTemplates();
+        //clearTemplates();
         return (WebClient)super.reset();
     }
     
@@ -585,12 +574,7 @@
             headers.putSingle(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_TYPE.toString());
         }
         resetResponse();
-        try {
-            return doChainedInvocation(httpMethod, headers, body, responseClass, genericType);
-        } finally {
-            clearTemplates();
-        }
-        
+        return doChainedInvocation(httpMethod, headers, body, responseClass, genericType);
     }
 
     protected Response doChainedInvocation(String httpMethod, 
@@ -598,7 +582,7 @@
         
         URI uri = getCurrentURI();
         Message m = createMessage(httpMethod, headers, uri);
-        m.put(URITemplate.TEMPLATE_PARAMETERS, templates);
+        m.put(URITemplate.TEMPLATE_PARAMETERS, getState().getTemplates());
         if (body != null) {
             MessageContentsList contents = new MessageContentsList(body);
             m.setContent(List.class, contents);
@@ -639,13 +623,6 @@
         return createHttpConnection(getCurrentBuilder().clone().buildFromEncoded(), methodName);
     }
     
-    private void clearTemplates() {
-        if (templates != null) {
-            templates.clear();
-            templates = null;
-        }
-    }
-    
     private class BodyWriter extends AbstractOutDatabindingInterceptor {
 
         public BodyWriter() {

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultithreadedClientTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultithreadedClientTest.java?rev=909396&r1=909395&r2=909396&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultithreadedClientTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultithreadedClientTest.java
Fri Feb 12 13:25:35 2010
@@ -45,7 +45,7 @@
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly",
-                   launchServer(BookServer.class));
+                   launchServer(BookServer.class, true));
     }
     
     @Test

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=909396&r1=909395&r2=909396&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
Fri Feb 12 13:25:35 2010
@@ -73,7 +73,7 @@
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
-                   launchServer(BookServerRestSoap.class));
+                   launchServer(BookServerRestSoap.class, true));
     }
     
     @Test



Mime
View raw message