Repository: camel
Updated Branches:
  refs/heads/master 4496eea4f -> b1bceaf9a


CAMEL-9613: Added unit test based on user forum issue


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

Branch: refs/heads/master
Commit: b1bceaf9ac3447c47279cadd6bebdb94e1fa95d9
Parents: 4496eea
Author: Claus Ibsen <davscl...@apache.org>
Authored: Fri Feb 19 17:05:31 2016 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Fri Feb 19 17:05:31 2016 +0100

----------------------------------------------------------------------
 .../sparkrest/DefaultSparkBinding.java          |  6 +++
 .../sparkrest/RestCamelSparkJsonTest.java       | 55 ++++++++++++++++++++
 2 files changed, 61 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b1bceaf9/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/DefaultSparkBinding.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/DefaultSparkBinding.java
 
b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/DefaultSparkBinding.java
index 27c74c7..3efa003 100644
--- 
a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/DefaultSparkBinding.java
+++ 
b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/DefaultSparkBinding.java
@@ -127,6 +127,12 @@ public class DefaultSparkBinding implements SparkBinding {
         for (Map.Entry<String, Object> entry : 
message.getHeaders().entrySet()) {
             String key = entry.getKey();
             Object value = entry.getValue();
+
+            if (Exchange.CONTENT_TYPE.equalsIgnoreCase(key)) {
+               // we set content-type later
+                continue;
+            }
+
             // use an iterator as there can be multiple values. (must not use 
a delimiter)
             final Iterator<?> it = ObjectHelper.createIterator(value, null);
             while (it.hasNext()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/b1bceaf9/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkJsonTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkJsonTest.java
 
b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkJsonTest.java
new file mode 100644
index 0000000..60d2a27
--- /dev/null
+++ 
b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkJsonTest.java
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.sparkrest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class RestCamelSparkJsonTest extends BaseSparkTest {
+
+    @Test
+    public void testSparkHello() throws Exception {
+        Exchange out = template.request("http://localhost:"; + getPort() + 
"/spark/hello", new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(Exchange.CONTENT_TYPE, 
"application/json");
+            }
+        });
+        assertNotNull(out);
+
+        assertEquals("application/json", 
out.getOut().getHeader(Exchange.CONTENT_TYPE));
+        assertEquals("{'reply': 'Hello World'}", 
out.getOut().getBody(String.class));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // will automatic find the spark component to use, as we setup 
that component in the BaseSparkTest
+                
rest("/spark").consumes("application/json").produces("application/json")
+                    .get("/hello").to("direct:hello");
+
+                from("direct:hello")
+                        .transform().constant("{'reply': 'Hello World'}");
+
+            }
+        };
+    }
+}

Reply via email to