You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/06/27 18:29:21 UTC
[4/8] git commit: CAMEL-7354: camel-spark component.
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/321ab932
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/321ab932
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/321ab932
Branch: refs/heads/master
Commit: 321ab9324c0ea9e9db4e15e39c5146d4bde0df3f
Parents: 4529963
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jun 27 16:13:16 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Jun 27 16:13:16 2014 +0200
----------------------------------------------------------------------
.../camel/component/spark/CamelSparkRoute.java | 10 +-
.../component/spark/DefaultSparkBinding.java | 123 +++++++++++++++++++
.../camel/component/spark/SparkBinding.java | 40 ++++++
.../camel/component/spark/SparkComponent.java | 31 ++++-
.../component/spark/SparkConfiguration.java | 55 +++++++++
.../camel/component/spark/SparkConsumer.java | 7 +-
.../camel/component/spark/SparkEndpoint.java | 30 +++++
.../spark/SparkHeaderFilterStrategy.java | 53 ++++++++
.../camel/component/spark/SparkHelper.java | 56 +++++++++
.../camel/component/spark/SparkMessage.java | 51 ++++++++
.../component/spark/CamelSparkParamTest.java | 46 +++++++
11 files changed, 495 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/321ab932/components/camel-spark/src/main/java/org/apache/camel/component/spark/CamelSparkRoute.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/main/java/org/apache/camel/component/spark/CamelSparkRoute.java b/components/camel-spark/src/main/java/org/apache/camel/component/spark/CamelSparkRoute.java
index 2550668..c418f88 100644
--- a/components/camel-spark/src/main/java/org/apache/camel/component/spark/CamelSparkRoute.java
+++ b/components/camel-spark/src/main/java/org/apache/camel/component/spark/CamelSparkRoute.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.spark;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
+import org.apache.camel.Message;
import org.apache.camel.Processor;
import spark.Request;
import spark.Response;
@@ -35,16 +36,21 @@ public class CamelSparkRoute implements Route {
@Override
public Object handle(Request request, Response response) {
-
Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
- exchange.getIn().setBody(request);
try {
+ Message in = endpoint.getSparkBinding().toCamelMessage(request, exchange, endpoint.getSparkConfiguration());
+ exchange.setIn(in);
+
processor.process(exchange);
} catch (Exception e) {
exchange.setException(e);
}
+ if (exchange.getException() != null) {
+ // TODO: how to handle exchange failures
+ }
+
if (exchange.hasOut()) {
return exchange.getOut().getBody();
} else {
http://git-wip-us.apache.org/repos/asf/camel/blob/321ab932/components/camel-spark/src/main/java/org/apache/camel/component/spark/DefaultSparkBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/main/java/org/apache/camel/component/spark/DefaultSparkBinding.java b/components/camel-spark/src/main/java/org/apache/camel/component/spark/DefaultSparkBinding.java
new file mode 100644
index 0000000..4f1251a
--- /dev/null
+++ b/components/camel-spark/src/main/java/org/apache/camel/component/spark/DefaultSparkBinding.java
@@ -0,0 +1,123 @@
+/**
+ * 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 java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import org.apache.camel.spi.HeaderFilterStrategy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import spark.Request;
+
+public class DefaultSparkBinding implements SparkBinding {
+
+ private static final Logger LOG = LoggerFactory.getLogger(DefaultSparkBinding.class);
+ private HeaderFilterStrategy headerFilterStrategy = new SparkHeaderFilterStrategy();
+
+ @Override
+ public Message toCamelMessage(Request request, Exchange exchange, SparkConfiguration configuration) throws Exception {
+ LOG.trace("toCamelMessage: {}", request);
+
+ SparkMessage answer = new SparkMessage(request, null);
+ answer.setExchange(exchange);
+ if (configuration.isMapHeaders()) {
+ populateCamelHeaders(request, answer.getHeaders(), exchange, configuration);
+ }
+
+ if (configuration.isDisableStreamCache()) {
+ // keep the body as a input stream
+ answer.setBody(request.raw().getInputStream());
+ } else {
+ answer.setBody(request.body());
+ }
+ return answer;
+ }
+
+ @Override
+ public void populateCamelHeaders(Request request, Map<String, Object> headers, Exchange exchange, SparkConfiguration configuration) throws Exception {
+ // store the method and query and other info in headers as String types
+ headers.put(Exchange.HTTP_METHOD, request.raw().getMethod());
+ headers.put(Exchange.HTTP_QUERY, request.raw().getQueryString());
+ headers.put(Exchange.HTTP_URL, request.raw().getRequestURL().toString());
+ headers.put(Exchange.HTTP_URI, request.raw().getRequestURI());
+ headers.put(Exchange.HTTP_PATH, request.raw().getPathInfo());
+ headers.put(Exchange.CONTENT_TYPE, request.raw().getContentType());
+
+ for (String key : request.attributes()) {
+ Object value = request.attribute(key);
+ Object decoded = shouldUrlDecodeHeader(configuration, key, value, "UTF-8");
+ if (headerFilterStrategy != null
+ && !headerFilterStrategy.applyFilterToExternalHeaders(key, decoded, exchange)) {
+ SparkHelper.appendHeader(headers, key, decoded);
+ }
+ }
+
+ for (String key : request.headers()) {
+ Object value = request.headers(key);
+ Object decoded = shouldUrlDecodeHeader(configuration, key, value, "UTF-8");
+ if (headerFilterStrategy != null
+ && !headerFilterStrategy.applyFilterToExternalHeaders(key, decoded, exchange)) {
+ SparkHelper.appendHeader(headers, key, decoded);
+ }
+ }
+
+ for (Map.Entry<String, String> entry : request.params().entrySet()) {
+ String key = mapKey(entry.getKey());
+ String value = entry.getValue();
+ Object decoded = shouldUrlDecodeHeader(configuration, key, value, "UTF-8");
+ if (headerFilterStrategy != null
+ && !headerFilterStrategy.applyFilterToExternalHeaders(key, decoded, exchange)) {
+ SparkHelper.appendHeader(headers, key, decoded);
+ }
+ }
+ }
+
+ /**
+ * Decodes the header if needed to, or returns the header value as is.
+ *
+ * @param configuration the configuration
+ * @param headerName the header name
+ * @param value the current header value
+ * @param charset the charset to use for decoding
+ * @return the decoded value (if decoded was needed) or a <tt>toString</tt> representation of the value.
+ * @throws java.io.UnsupportedEncodingException is thrown if error decoding.
+ */
+ protected String shouldUrlDecodeHeader(SparkConfiguration configuration, String headerName, Object value, String charset) throws
+ UnsupportedEncodingException {
+ // do not decode Content-Type
+ if (Exchange.CONTENT_TYPE.equals(headerName)) {
+ return value.toString();
+ } else if (configuration.isUrlDecodeHeaders()) {
+ return URLDecoder.decode(value.toString(), charset);
+ } else {
+ return value.toString();
+ }
+ }
+
+ protected String mapKey(String key) {
+ if (key.startsWith(":")) {
+ return key.substring(1);
+ } else {
+ return key;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/321ab932/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkBinding.java b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkBinding.java
new file mode 100644
index 0000000..61d8798
--- /dev/null
+++ b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkBinding.java
@@ -0,0 +1,40 @@
+/**
+ * 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 java.util.Map;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Message;
+import spark.Request;
+
+public interface SparkBinding {
+
+ /**
+ * Binds from Spark {@link Request} to Camel {@link org.apache.camel.Message}.
+ *
+ * @param request the netty http request
+ * @param exchange the exchange that should contain the returned message.
+ * @param configuration configuration
+ * @return the message to store on the given exchange
+ * @throws Exception is thrown if error during binding
+ */
+ Message toCamelMessage(Request request, Exchange exchange, SparkConfiguration configuration) throws Exception;
+
+ void populateCamelHeaders(Request request, Map<String, Object> headers, Exchange exchange, SparkConfiguration configuration) throws Exception;
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/321ab932/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkComponent.java b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkComponent.java
index db3b6b1..c2ff687 100644
--- a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkComponent.java
+++ b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkComponent.java
@@ -20,12 +20,15 @@ import java.util.Map;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.util.ObjectHelper;
import spark.Spark;
import spark.SparkBase;
public class SparkComponent extends UriEndpointComponent {
private int port = SparkBase.SPARK_DEFAULT_PORT;
+ private SparkConfiguration sparkConfiguration = new SparkConfiguration();
+ private SparkBinding sparkBinding = new DefaultSparkBinding();
public SparkComponent() {
super(SparkEndpoint.class);
@@ -39,18 +42,38 @@ public class SparkComponent extends UriEndpointComponent {
this.port = port;
}
+ public SparkConfiguration getSparkConfiguration() {
+ return sparkConfiguration;
+ }
+
+ public void setSparkConfiguration(SparkConfiguration sparkConfiguration) {
+ this.sparkConfiguration = sparkConfiguration;
+ }
+
+ public SparkBinding getSparkBinding() {
+ return sparkBinding;
+ }
+
+ public void setSparkBinding(SparkBinding sparkBinding) {
+ this.sparkBinding = sparkBinding;
+ }
+
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
SparkEndpoint answer = new SparkEndpoint(uri, this);
+ answer.setSparkConfiguration(getSparkConfiguration());
+ answer.setSparkBinding(getSparkBinding());
setProperties(answer, parameters);
- String[] parts = remaining.split(":");
- if (parts.length != 2) {
+ if (!remaining.contains(":")) {
throw new IllegalArgumentException("Invalid syntax. Must be spark:verb:path");
}
- answer.setVerb(parts[0]);
- answer.setPath(parts[1]);
+ String verb = ObjectHelper.before(remaining, ":");
+ String path = ObjectHelper.after(remaining, ":");
+
+ answer.setVerb(verb);
+ answer.setPath(path);
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/321ab932/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkConfiguration.java b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkConfiguration.java
new file mode 100644
index 0000000..0c6d2b7
--- /dev/null
+++ b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkConfiguration.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.spi.UriParam;
+import org.apache.camel.spi.UriParams;
+
+@UriParams
+public class SparkConfiguration {
+
+ @UriParam
+ private boolean mapHeaders = true;
+ @UriParam
+ private boolean disableStreamCache;
+ @UriParam
+ private boolean urlDecodeHeaders;
+
+ public boolean isMapHeaders() {
+ return mapHeaders;
+ }
+
+ public void setMapHeaders(boolean mapHeaders) {
+ this.mapHeaders = mapHeaders;
+ }
+
+ public boolean isDisableStreamCache() {
+ return disableStreamCache;
+ }
+
+ public void setDisableStreamCache(boolean disableStreamCache) {
+ this.disableStreamCache = disableStreamCache;
+ }
+
+ public boolean isUrlDecodeHeaders() {
+ return urlDecodeHeaders;
+ }
+
+ public void setUrlDecodeHeaders(boolean urlDecodeHeaders) {
+ this.urlDecodeHeaders = urlDecodeHeaders;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/321ab932/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 5db1b40..8450636 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,10 +41,15 @@ public class SparkConsumer extends DefaultConsumer {
String path = getEndpoint().getPath();
String verb = getEndpoint().getVerb();
+ String acceptType = getEndpoint().getAcceptType();
if ("get".equals(verb)) {
log.info("get(/{})", verb);
- Spark.get(path, route);
+ if (acceptType != null) {
+ Spark.get(path, acceptType, route);
+ } else {
+ Spark.get(path, route);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/321ab932/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 b46e647..05c9082 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
@@ -28,14 +28,36 @@ import org.apache.camel.spi.UriParam;
public class SparkEndpoint extends DefaultEndpoint {
@UriParam
+ SparkConfiguration sparkConfiguration;
+ @UriParam
+ private SparkBinding sparkBinding;
+ @UriParam
private String verb;
@UriParam
private String path;
+ @UriParam
+ private String acceptType;
public SparkEndpoint(String endpointUri, Component component) {
super(endpointUri, component);
}
+ public SparkConfiguration getSparkConfiguration() {
+ return sparkConfiguration;
+ }
+
+ public void setSparkConfiguration(SparkConfiguration sparkConfiguration) {
+ this.sparkConfiguration = sparkConfiguration;
+ }
+
+ public SparkBinding getSparkBinding() {
+ return sparkBinding;
+ }
+
+ public void setSparkBinding(SparkBinding sparkBinding) {
+ this.sparkBinding = sparkBinding;
+ }
+
public String getVerb() {
return verb;
}
@@ -52,6 +74,14 @@ public class SparkEndpoint extends DefaultEndpoint {
this.path = path;
}
+ public String getAcceptType() {
+ return acceptType;
+ }
+
+ public void setAcceptType(String acceptType) {
+ this.acceptType = acceptType;
+ }
+
@Override
public Producer createProducer() throws Exception {
throw new UnsupportedOperationException("Producer not supported");
http://git-wip-us.apache.org/repos/asf/camel/blob/321ab932/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkHeaderFilterStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkHeaderFilterStrategy.java b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkHeaderFilterStrategy.java
new file mode 100644
index 0000000..33e0eb0
--- /dev/null
+++ b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkHeaderFilterStrategy.java
@@ -0,0 +1,53 @@
+/**
+ * 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.impl.DefaultHeaderFilterStrategy;
+
+/**
+ * Default Spark {@link org.apache.camel.spi.HeaderFilterStrategy} used when binding with {@link org.apache.camel.component.spark.SparkBinding}.
+ */
+public class SparkHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
+
+ public SparkHeaderFilterStrategy() {
+ initialize();
+ }
+
+ protected void initialize() {
+ getOutFilter().add("content-length");
+ getOutFilter().add("content-type");
+ getOutFilter().add("host");
+ // Add the filter for the Generic Message header
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
+ getOutFilter().add("cache-control");
+ getOutFilter().add("connection");
+ getOutFilter().add("date");
+ getOutFilter().add("pragma");
+ getOutFilter().add("trailer");
+ getOutFilter().add("transfer-encoding");
+ getOutFilter().add("upgrade");
+ getOutFilter().add("via");
+ getOutFilter().add("warning");
+
+ setLowerCase(true);
+
+ // filter headers begin with "Camel" or "org.apache.camel"
+ // must ignore case for Http based transports
+ setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/321ab932/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkHelper.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkHelper.java b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkHelper.java
new file mode 100644
index 0000000..eda26b6
--- /dev/null
+++ b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkHelper.java
@@ -0,0 +1,56 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public final class SparkHelper {
+
+ private SparkHelper() {
+ }
+
+ /**
+ * Appends the key/value to the headers.
+ * <p/>
+ * This implementation supports keys with multiple values. In such situations the value
+ * will be a {@link java.util.List} that contains the multiple values.
+ *
+ * @param headers headers
+ * @param key the key
+ * @param value the value
+ */
+ @SuppressWarnings("unchecked")
+ public static void appendHeader(Map<String, Object> headers, String key, Object value) {
+ if (headers.containsKey(key)) {
+ Object existing = headers.get(key);
+ List<Object> list;
+ if (existing instanceof List) {
+ list = (List<Object>) existing;
+ } else {
+ list = new ArrayList<Object>();
+ list.add(existing);
+ }
+ list.add(value);
+ value = list;
+ }
+
+ headers.put(key, value);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/321ab932/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkMessage.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkMessage.java b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkMessage.java
new file mode 100644
index 0000000..0d02da3
--- /dev/null
+++ b/components/camel-spark/src/main/java/org/apache/camel/component/spark/SparkMessage.java
@@ -0,0 +1,51 @@
+/**
+ * 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.impl.DefaultMessage;
+import spark.Request;
+import spark.Response;
+
+/**
+ * Spark based {@link org.apache.camel.Message}.
+ * <p/>
+ * This implementation allows direct access to the Spark {@link Request} using
+ * the {@link #getRequest()} method.
+ */
+public class SparkMessage extends DefaultMessage {
+
+ private final transient Request request;
+ private final transient Response response;
+
+ public SparkMessage(Request request, Response response) {
+ this.request = request;
+ this.response = response;
+ }
+
+ public Request getRequest() {
+ return request;
+ }
+
+ public Response getResponse() {
+ return response;
+ }
+
+ @Override
+ public DefaultMessage newInstance() {
+ return new SparkMessage(request, response);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/321ab932/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkParamTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkParamTest.java b/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkParamTest.java
new file mode 100644
index 0000000..ad40fb4
--- /dev/null
+++ b/components/camel-spark/src/test/java/org/apache/camel/component/spark/CamelSparkParamTest.java
@@ -0,0 +1,46 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.junit.Test;
+
+public class CamelSparkParamTest extends BaseSparkTest {
+
+ @Test
+ public void testSparkGet() throws Exception {
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+ getMockEndpoint("mock:foo").expectedHeaderReceived("name", "world");
+
+ String out = template.requestBody("http://0.0.0.0:" + getPort() + "/hello/world", null, String.class);
+ assertEquals("Bye world", out);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("spark:get:/hello/:name")
+ .to("mock:foo")
+ .transform().simple("Bye ${header.name}");
+ }
+ };
+ }
+}