camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/3] camel git commit: CAMEL-8049 Added the support of multi-value in DefaultRestletBinding with thanks to Bojan
Date Wed, 19 Nov 2014 07:26:35 GMT
Repository: camel
Updated Branches:
  refs/heads/master add89cef0 -> e6f9f02fa


CAMEL-8049 Added the support of multi-value in DefaultRestletBinding with thanks to Bojan


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

Branch: refs/heads/master
Commit: e6f9f02fac4689d17b5e809de2f64c0f60a73b24
Parents: 34b2f72
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed Nov 19 15:25:28 2014 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed Nov 19 15:25:47 2014 +0800

----------------------------------------------------------------------
 .../restlet/DefaultRestletBinding.java          | 33 ++++++++++++++------
 1 file changed, 24 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e6f9f02f/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
index 7e62cd8..8650021 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/DefaultRestletBinding.java
@@ -24,10 +24,12 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Collection;
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+
 import javax.xml.transform.dom.DOMSource;
 
 import org.apache.camel.Exchange;
@@ -110,16 +112,23 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate
         // only deal with the form if the content type is "application/x-www-form-urlencoded"
         if (request.getEntity().getMediaType() != null && request.getEntity().getMediaType().equals(MediaType.APPLICATION_WWW_FORM))
{
             Form form = new Form(request.getEntity());
-            for (Map.Entry<String, String> entry : form.getValuesMap().entrySet())
{
-                String key = entry.getKey();
-                String value = entry.getValue();
+            for (String paramName : form.getValuesMap().keySet()) {
+                String[] values = form.getValuesArray(paramName);
+                Object value = null;
+                if (values != null && values.length > 0) {
+                    if (values.length == 1) {
+                        value = values[0];
+                    } else {
+                        value = values;
+                    }
+                }
                 if (value == null) {
-                    inMessage.setBody(key);
-                    LOG.debug("Populate exchange from Restlet request body: {}", key);
+                    inMessage.setBody(paramName);
+                    LOG.debug("Populate exchange from Restlet request body: {}", paramName);
                 } else {
-                    if (!headerFilterStrategy.applyFilterToExternalHeaders(key, value, exchange))
{
-                        inMessage.setHeader(key, value);
-                        LOG.debug("Populate exchange from Restlet request user header: {}
value: {}", key, value);
+                    if (!headerFilterStrategy.applyFilterToExternalHeaders(paramName, value,
exchange)) {
+                        inMessage.setHeader(paramName, value);
+                        LOG.debug("Populate exchange from Restlet request user header: {}
value: {}", paramName, value);
                     }
                 }
             }
@@ -166,7 +175,13 @@ public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrate
                         request.getAttributes().put(key, value);
                     } else {
                         // put the user stuff in the form
-                        form.add(key, value.toString());
+                        if (value instanceof Collection) {
+                            for (Object v: (Collection<?>) value) {
+                                form.add(key, v.toString());
+                            }
+                        } else {
+                            form.add(key, value.toString());
+                        }
                     }
                 } else {
                     // For non-form post put all the headers in attributes


Mime
View raw message