CAMEL-7354: camel-spark component.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f994a4e3 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f994a4e3 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f994a4e3 Branch: refs/heads/master Commit: f994a4e33080a10a2da3de0624b9161f6b27d8e0 Parents: 183bbef Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Jun 27 17:44:10 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Jun 27 17:47:34 2014 +0200 ---------------------------------------------------------------------- .../camel/component/spark/SparkConsumer.java | 8 +-- .../camel/component/spark/SparkEndpoint.java | 10 ++-- .../component/spark/CamelSparkAcceptTest.java | 55 ++++++++++++++++++++ 3 files changed, 65 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/f994a4e3/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkConsumer.java ---------------------------------------------------------------------- diff --git a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkConsumer.java b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkConsumer.java index 8450636..16d350d 100644 --- a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkConsumer.java +++ b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkConsumer.java @@ -41,12 +41,14 @@ public class SparkConsumer extends DefaultConsumer { String path = getEndpoint().getPath(); String verb = getEndpoint().getVerb(); - String acceptType = getEndpoint().getAcceptType(); + String accept = getEndpoint().getAccept(); + + // TODO: reuse our spark route builder DSL instead of this code if ("get".equals(verb)) { log.info("get(/{})", verb); - if (acceptType != null) { - Spark.get(path, acceptType, route); + if (accept != null) { + Spark.get(path, accept, route); } else { Spark.get(path, route); } http://git-wip-us.apache.org/repos/asf/camel/blob/f994a4e3/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkEndpoint.java ---------------------------------------------------------------------- diff --git a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkEndpoint.java b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkEndpoint.java index 05c9082..9d291ca 100644 --- a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkEndpoint.java +++ b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkEndpoint.java @@ -36,7 +36,7 @@ public class SparkEndpoint extends DefaultEndpoint { @UriParam private String path; @UriParam - private String acceptType; + private String accept; public SparkEndpoint(String endpointUri, Component component) { super(endpointUri, component); @@ -74,12 +74,12 @@ public class SparkEndpoint extends DefaultEndpoint { this.path = path; } - public String getAcceptType() { - return acceptType; + public String getAccept() { + return accept; } - public void setAcceptType(String acceptType) { - this.acceptType = acceptType; + public void setAccept(String accept) { + this.accept = accept; } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/f994a4e3/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkAcceptTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkAcceptTest.java b/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkAcceptTest.java new file mode 100644 index 0000000..eb0df15 --- /dev/null +++ b/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkAcceptTest.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.spark; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.http.HttpOperationFailedException; +import org.junit.Test; + +public class CamelSparkAcceptTest extends BaseSparkTest { + + @Test + public void testSparkGet() throws Exception { + getMockEndpoint("mock:foo").expectedMessageCount(1); + + try { + template.requestBodyAndHeader("http://0.0.0.0:" + getPort() + "/hello", null, "Accept", "text/plain", String.class); + fail("Should fail"); + } catch (CamelExecutionException e) { + HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); + assertEquals(404, cause.getStatusCode()); + } + + String out2 = template.requestBodyAndHeader("http://0.0.0.0:" + getPort() + "/hello", null, "Accept", "application/json", String.class); + assertEquals("{ \"reply\": \"Bye World\" }", out2); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("spark:get:hello?accept=application/json") + .to("mock:foo") + .transform().constant("{ \"reply\": \"Bye World\" }"); + } + }; + } +}