camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1144447 - in /camel/branches/camel-2.7.x: ./ components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
Date Fri, 08 Jul 2011 19:37:59 GMT
Author: dkulp
Date: Fri Jul  8 19:37:58 2011
New Revision: 1144447

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

........
  r1092034 | ningjiang | 2011-04-14 03:48:40 -0400 (Thu, 14 Apr 2011) | 1 line
  
  CAMEL-3860 cxfrs producer supports to configure the query parameter with the Exchange.HTTP_QUERY
message header
........

Modified:
    camel/branches/camel-2.7.x/   (props changed)
    camel/branches/camel-2.7.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
    camel/branches/camel-2.7.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java

Propchange: camel/branches/camel-2.7.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jul  8 19:37:58 2011
@@ -1 +1 @@
-/camel/trunk:1083696,1083723-1083724,1084150,1085277,1085543,1085549,1085905,1085909,1086165,1086231,1087005,1087276,1087612,1087620,1087856,1088583,1088916-1088917,1089275,1089348,1090166,1090204,1090564,1090960-1090969,1091082,1091518,1091771,1091799,1092068,1092577,1092667,1093978,1094147,1094156,1095405,1095469,1095471,1095475-1095476,1096346,1097909,1097912,1097978,1098630,1099417,1100975,1102162,1102181,1104076,1124497,1127744,1127988,1131411,1134252,1134501,1135223,1135364,1136290,1138285,1139163,1140096-1140102,1141783,1143925,1144248,1144324
+/camel/trunk:1083696,1083723-1083724,1084150,1085277,1085543,1085549,1085905,1085909,1086165,1086231,1087005,1087276,1087612,1087620,1087856,1088583,1088916-1088917,1089275,1089348,1090166,1090204,1090564,1090960-1090969,1091082,1091518,1091771,1091799,1092034,1092068,1092577,1092667,1093978,1094147,1094156,1095405,1095469,1095471,1095475-1095476,1096346,1097909,1097912,1097978,1098630,1099417,1100975,1102162,1102181,1104076,1124497,1127744,1127988,1131411,1134252,1134501,1135223,1135364,1136290,1138285,1139163,1140096-1140102,1141783,1143925,1144248,1144324

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

Modified: camel/branches/camel-2.7.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java?rev=1144447&r1=1144446&r2=1144447&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
(original)
+++ camel/branches/camel-2.7.x/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/jaxrs/CxfRsProducer.java
Fri Jul  8 19:37:58 2011
@@ -16,12 +16,15 @@
  */
 package org.apache.camel.component.cxf.jaxrs;
 
+import java.io.UnsupportedEncodingException;
 import java.lang.ref.SoftReference;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
+import java.net.URLDecoder;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -33,6 +36,7 @@ import org.apache.camel.Message;
 import org.apache.camel.component.cxf.CxfConstants;
 import org.apache.camel.component.cxf.CxfOperationException;
 import org.apache.camel.component.cxf.util.CxfEndpointUtils;
+import org.apache.camel.converter.IOConverter;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.LRUCache;
 import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
@@ -104,6 +108,13 @@ public class CxfRsProducer extends Defau
         // check if there is a query map in the message header
         Map<String, String> maps = inMessage.getHeader(CxfConstants.CAMEL_CXF_RS_QUERY_MAP,
Map.class);
         if (maps == null) {
+            // Get the map from HTTP_QUERY header
+            String queryString = inMessage.getHeader(Exchange.HTTP_QUERY, String.class);
+            if (queryString != null) {
+                maps = getQueryParametersFromQueryString(queryString, IOConverter.getCharsetName(exchange));
+            }
+        }
+        if (maps == null) {
             maps = cxfRsEndpoint.getParameters();
         }
         if (maps != null) {
@@ -111,6 +122,10 @@ public class CxfRsProducer extends Defau
                 client.query(entry.getKey(), entry.getValue());
             }
         }
+        String queryString = inMessage.getHeader(Exchange.HTTP_QUERY, String.class);
+        if (queryString != null) {
+            
+        }
 
         CxfRsBinding binding = cxfRsEndpoint.getBinding();
 
@@ -200,6 +215,21 @@ public class CxfRsProducer extends Defau
             exchange.getOut().setBody(response);
         }
     }
+    
+    private Map<String, String> getQueryParametersFromQueryString(String queryString,
String charset) throws UnsupportedEncodingException {
+        Map<String, String> answer  = new LinkedHashMap<String, String>();
+        for (String param : queryString.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 Method findRightMethod(List<Class<?>> resourceClasses, String methodName,
Class[] parameterTypes) throws NoSuchMethodException {
         Method answer = null;

Modified: camel/branches/camel-2.7.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.7.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java?rev=1144447&r1=1144446&r2=1144447&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
(original)
+++ camel/branches/camel-2.7.x/components/camel-cxf/src/test/java/org/apache/camel/component/cxf/jaxrs/CxfRsRouterTest.java
Fri Jul  8 19:37:58 2011
@@ -65,6 +65,23 @@ public class CxfRsRouterTest extends Cam
         }
     }
     
+
+    @Test
+    public void testGetCustomerWithQuery() throws Exception {      
+        HttpGet get = new HttpGet("http://localhost:9000/route/customerservice/customers?id=123");
+        get.addHeader("Accept" , "application/json");
+        HttpClient httpclient = new DefaultHttpClient();
+
+        try {
+            HttpResponse response = httpclient.execute(get);
+            assertEquals(200, response.getStatusLine().getStatusCode());
+            assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}", 
+                         EntityUtils.toString(response.getEntity()));
+        } finally {
+            httpclient.getConnectionManager().shutdown();
+        }
+    }
+    
     @Test
     public void testGetCustomers() throws Exception {      
         HttpGet get = new HttpGet("http://localhost:9000/route/customerservice/customers/");



Mime
View raw message