camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [2/4] camel git commit: CAMEL-8092 Fixed the cxf:producer Matrix Params missing issue with thanks to kumarann
Date Wed, 03 Dec 2014 14:10:20 GMT
CAMEL-8092 Fixed the cxf:producer Matrix Params missing issue with thanks to kumarann


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ef142f9e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ef142f9e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ef142f9e

Branch: refs/heads/camel-2.14.x
Commit: ef142f9e9cb2d96800c1950731661dbe9a90f9ce
Parents: 01e7af3
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed Dec 3 21:45:15 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed Dec 3 22:09:30 2014 +0800

----------------------------------------------------------------------
 .../component/cxf/jaxrs/CxfRsProducer.java      | 42 ++++++++++++++++++++
 1 file changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ef142f9e/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
index c220487..7b6e6ea 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
@@ -43,6 +43,7 @@ import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
 import org.apache.cxf.jaxrs.client.Client;
 import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
 import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.message.MessageImpl;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -121,6 +122,30 @@ public class CxfRsProducer extends DefaultProducer {
         
     }
     
+    protected void setupClientMatrix(WebClient client, Exchange exchange) throws Exception
{
+        
+        org.apache.cxf.message.Message cxfMessage = (org.apache.cxf.message.Message) exchange.getIn().getHeader("CamelCxfMessage");
+        if (cxfMessage != null) {
+            String requestURL = (String)cxfMessage.get("org.apache.cxf.request.uri"); 
+            String matrixParam = null;
+            int matrixStart = requestURL.indexOf(";");
+            int matrixEnd = requestURL.indexOf("?") > -1 ? requestURL.indexOf("?") : requestURL.length();
+            Map<String, String> maps = null;
+            if (requestURL != null && matrixStart > 0) {
+                matrixParam = requestURL.substring(matrixStart + 1, matrixEnd);
+                if (matrixParam != null) {
+                    maps = getMatrixParametersFromMatrixString(matrixParam, IOHelper.getCharsetName(exchange));
+                }
+            }
+            if (maps != null) {
+                for (Map.Entry<String, String> entry : maps.entrySet()) {
+                    client.matrix(entry.getKey(), entry.getValue());
+                    LOG.debug("Matrix param " + entry.getKey() + " :: " + entry.getValue());
+                }
+            }
+        }
+    }
+    
     protected void setupClientHeaders(Client client, Exchange exchange) throws Exception
{
         Message inMessage = exchange.getIn();
         CxfRsEndpoint cxfRsEndpoint = (CxfRsEndpoint) getEndpoint();
@@ -172,6 +197,8 @@ public class CxfRsProducer extends DefaultProducer {
                 }
             }
         }
+        
+        setupClientMatrix(client, exchange); 
 
         setupClientQueryAndHeaders(client, exchange);
         
@@ -342,6 +369,21 @@ public class CxfRsProducer extends DefaultProducer {
         return answer;
     }
 
+    private Map<String, String> getMatrixParametersFromMatrixString(String matrixString,
String charset) throws UnsupportedEncodingException {
+        Map<String, String> answer  = new LinkedHashMap<String, String>();
+        for (String param : matrixString.split(";")) {
+            String[] pair = param.split("=", 2);
+            if (pair.length == 2) {
+                String name = URLDecoder.decode(pair[0], charset);
+                String value = URLDecoder.decode(pair[1], charset);
+                answer.put(name, value);
+            } else {
+                throw new IllegalArgumentException("Invalid parameter, expected to be a pair
but was " + param);
+            }
+        }
+        return answer;
+    }
+    
     private String arrayToString(Object[] array) {
         StringBuilder buffer = new StringBuilder("[");
         for (Object obj : array) {


Mime
View raw message