CAMEL-7619: Rest DSL - adding support for xml/json binding using Camel's data formats.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c00286d8 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c00286d8 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c00286d8 Branch: refs/heads/master Commit: c00286d83aeb6627c4cf32da693d451d143f1379 Parents: d8d0301 Author: Claus Ibsen <davscl...@apache.org> Authored: Fri Jul 25 23:27:43 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Jul 25 23:27:43 2014 +0200 ---------------------------------------------------------------------- .../org/apache/camel/component/rest/RestEndpoint.java | 12 +++++++++++- .../org/apache/camel/model/rest/RestDefinition.java | 9 +++++++++ .../java/org/apache/camel/spi/RestConsumerFactory.java | 7 ++++--- .../camel/component/rest/DummyRestConsumerFactory.java | 4 ++-- .../camel/component/restlet/RestletComponent.java | 4 ++-- .../camel/component/sparkrest/SparkComponent.java | 4 ++-- .../component/rest/DummyRestConsumerFactory.java | 4 ++-- 7 files changed, 32 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/c00286d8/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java index 9f05502..1d9195d 100644 --- a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java +++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java @@ -39,6 +39,8 @@ public class RestEndpoint extends DefaultEndpoint { @UriParam private String consumes; @UriParam + private String produces; + @UriParam private String componentName; private Map<String, Object> parameters; @@ -76,6 +78,14 @@ public class RestEndpoint extends DefaultEndpoint { this.consumes = consumes; } + public String getProduces() { + return produces; + } + + public void setProduces(String produces) { + this.produces = produces; + } + public String getComponentName() { return componentName; } @@ -141,7 +151,7 @@ public class RestEndpoint extends DefaultEndpoint { } if (factory != null) { - Consumer consumer = factory.createConsumer(getCamelContext(), processor, getVerb(), getPath(), getConsumes(), getParameters()); + Consumer consumer = factory.createConsumer(getCamelContext(), processor, getVerb(), getPath(), getConsumes(), getProduces(), getParameters()); configureConsumer(consumer); return consumer; } else { http://git-wip-us.apache.org/repos/asf/camel/blob/c00286d8/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java index b7bf16d..64be3bf 100644 --- a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java @@ -309,8 +309,16 @@ public class RestDefinition { String from = "rest:" + verb.asVerb() + ":" + buildUri(verb); // append options Map<String, Object> options = new HashMap<String, Object>(); + // verb takes precedence over configuration on rest if (verb.getConsumes() != null) { options.put("consumes", verb.getConsumes()); + } else if (getConsumes() != null) { + options.put("consumes", getConsumes()); + } + if (verb.getProduces() != null) { + options.put("produces", verb.getProduces()); + } else if (getProduces() != null) { + options.put("produces", getProduces()); } if (!options.isEmpty()) { String query = URISupport.createQueryString(options); @@ -332,6 +340,7 @@ public class RestDefinition { binding.setOutType(verb.getOutType()); binding.setList(verb.getList()); binding.setOutList(verb.getOutList()); + // verb takes precedence over configuration on rest if (verb.getConsumes() != null) { binding.setConsumes(verb.getConsumes()); } else { http://git-wip-us.apache.org/repos/asf/camel/blob/c00286d8/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java b/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java index 82d2198..8af67c7 100644 --- a/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java +++ b/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java @@ -33,11 +33,12 @@ public interface RestConsumerFactory { * @param processor the processor * @param verb HTTP verb such as GET, POST * @param path HTTP context-path - * @param consumes accept-type, is <tt>null</tt> to accept anything + * @param consumes media-types for what this REST service consume as input (accept-type), is <tt>null</tt> or <tt>*/*</tt> for anything + * @param produces media-types for what this REST service produces as output, can be <tt>null</tt> * @param parameters additional parameters * @return a newly created REST consumer * @throws Exception can be thrown */ - Consumer createConsumer(CamelContext camelContext, Processor processor, - String verb, String path, String consumes, Map<String, Object> parameters) throws Exception; + Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path, + String consumes, String produces, Map<String, Object> parameters) throws Exception; } http://git-wip-us.apache.org/repos/asf/camel/blob/c00286d8/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java b/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java index 5ec21f8..837933f 100644 --- a/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java +++ b/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java @@ -28,8 +28,8 @@ import org.apache.camel.spi.RestConsumerFactory; public class DummyRestConsumerFactory implements RestConsumerFactory { @Override - public Consumer createConsumer(CamelContext camelContext, Processor processor, - String verb, String path, String consumes, Map<String, Object> parameters) throws Exception { + public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path, + String consumes, String produces, Map<String, Object> parameters) throws Exception { // just use a seda endpoint for testing purpose String id = ActiveMQUuidGenerator.generateSanitizedId(path); // remove leading dash as we add that ourselves http://git-wip-us.apache.org/repos/asf/camel/blob/c00286d8/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java index 8707160..ac90fde 100644 --- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java +++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java @@ -501,8 +501,8 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R } @Override - public Consumer createConsumer(CamelContext camelContext, Processor processor, - String verb, String path, String consumes, Map<String, Object> parameters) throws Exception { + public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path, + String consumes, String produces, Map<String, Object> parameters) throws Exception { path = FileUtil.stripLeadingSeparator(path); http://git-wip-us.apache.org/repos/asf/camel/blob/c00286d8/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java index 1562342..c3827ff 100644 --- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java +++ b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java @@ -123,8 +123,8 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer } @Override - public Consumer createConsumer(CamelContext camelContext, Processor processor, - String verb, String path, String consumes, Map<String, Object> parameters) throws Exception { + public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path, + String consumes, String produces, Map<String, Object> parameters) throws Exception { if (ObjectHelper.isNotEmpty(path)) { // spark-rest uses :name syntax instead of {name} so we need to replace those http://git-wip-us.apache.org/repos/asf/camel/blob/c00286d8/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java index 47d8059..ad5c9e9 100644 --- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java +++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java @@ -28,8 +28,8 @@ import org.apache.camel.spi.RestConsumerFactory; public class DummyRestConsumerFactory implements RestConsumerFactory { @Override - public Consumer createConsumer(CamelContext camelContext, Processor processor, - String verb, String path, String accept, Map<String, Object> parameters) throws Exception { + public Consumer createConsumer(CamelContext camelContext, Processor processor, String verb, String path, + String consumes, String produces, Map<String, Object> parameters) throws Exception { // just use a seda endpoint for testing purpose String id = ActiveMQUuidGenerator.generateSanitizedId(path); // remove leading dash as we add that ourselves