CAMEL-10164: swagger component for making rest calls with swagger schema validation and facade to actual HTTP client in use
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/19b1f5c5 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/19b1f5c5 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/19b1f5c5 Branch: refs/heads/master Commit: 19b1f5c52e81b11af4ecb9053af11a2115309e30 Parents: 9408d9f Author: Claus Ibsen <[email protected]> Authored: Thu Aug 25 14:15:06 2016 +0200 Committer: Claus Ibsen <[email protected]> Committed: Fri Aug 26 16:53:31 2016 +0200 ---------------------------------------------------------------------- .../camel/component/rest/RestComponent.java | 7 ++++- .../model/rest/RestConfigurationDefinition.java | 29 ++++++++++++++++++-- .../org/apache/camel/spi/RestConfiguration.java | 19 +++++++++++++ ...ttyRestProducerGetRestConfigurationTest.java | 2 +- .../rest/producer/JettyRestProducerGetTest.java | 2 +- .../swagger/component/RestSwaggerGetTest.java | 2 +- .../component/RestSwaggerGetUriParamTest.java | 2 +- 7 files changed, 56 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/19b1f5c5/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java index 3553a5b..67aaaba 100644 --- a/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java +++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java @@ -89,7 +89,12 @@ public class RestComponent extends UriEndpointComponent { // if no explicit component name was given, then fallback and use default configured component name if (answer.getComponentName() == null && getCamelContext().getRestConfiguration() != null) { - answer.setComponentName(getCamelContext().getRestConfiguration().getComponent()); + String name = getCamelContext().getRestConfiguration().getProducerComponent(); + if (name == null) { + // fallback and use the consumer name + name = getCamelContext().getRestConfiguration().getComponent(); + } + answer.setComponentName(name); } return answer; http://git-wip-us.apache.org/repos/asf/camel/blob/19b1f5c5/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java index 89ad625..dec2901 100644 --- a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java @@ -46,6 +46,9 @@ public class RestConfigurationDefinition { private String apiComponent; @XmlAttribute + private String producerComponent; + + @XmlAttribute private String scheme; @XmlAttribute @@ -110,7 +113,7 @@ public class RestConfigurationDefinition { } /** - * The Camel Rest component to use for the REST transport, such as restlet, spark-rest. + * The Camel Rest component to use for the REST transport (consumer), such as restlet, spark-rest. * If no component has been explicit configured, then Camel will lookup if there is a Camel component * that integrates with the Rest DSL, or if a org.apache.camel.spi.RestConsumerFactory is registered in the registry. * If either one is found, then that is being used. @@ -130,6 +133,17 @@ public class RestConfigurationDefinition { this.apiComponent = apiComponent; } + public String getProducerComponent() { + return producerComponent; + } + + /** + * Sets the name of the Camel component to use as the REST producer + */ + public void setProducerComponent(String producerComponent) { + this.producerComponent = producerComponent; + } + public String getScheme() { return scheme; } @@ -402,7 +416,7 @@ public class RestConfigurationDefinition { //------------------------------------------------------------------------- /** - * To use a specific Camel rest component + * To use a specific Camel rest component (consumer) */ public RestConfigurationDefinition component(String componentId) { setComponent(componentId); @@ -418,6 +432,14 @@ public class RestConfigurationDefinition { } /** + * To use a specific Camel rest component (producer) + */ + public RestConfigurationDefinition producerComponent(String componentId) { + setProducerComponent(componentId); + return this; + } + + /** * To use a specific scheme such as http/https */ public RestConfigurationDefinition scheme(String scheme) { @@ -647,6 +669,9 @@ public class RestConfigurationDefinition { if (apiComponent != null) { answer.setApiComponent(CamelContextHelper.parseText(context, apiComponent)); } + if (producerComponent != null) { + answer.setProducerComponent(CamelContextHelper.parseText(context, producerComponent)); + } if (scheme != null) { answer.setScheme(CamelContextHelper.parseText(context, scheme)); } http://git-wip-us.apache.org/repos/asf/camel/blob/19b1f5c5/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java b/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java index e5f0f93..0a71ba6 100644 --- a/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java +++ b/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java @@ -39,6 +39,7 @@ public class RestConfiguration { private String component; private String apiComponent; + private String producerComponent; private String scheme; private String host; private int port; @@ -97,6 +98,24 @@ public class RestConfiguration { } /** + * Gets the name of the Camel component to use as the REST producer + * + * @return the component name, or <tt>null</tt> to let Camel search the {@link Registry} to find suitable implementation + */ + public String getProducerComponent() { + return producerComponent; + } + + /** + * Sets the name of the Camel component to use as the REST producer + * + * @param componentName the name of the component (such as restlet, jetty, etc.) + */ + public void setProducerComponent(String componentName) { + this.producerComponent = componentName; + } + + /** * Gets the hostname to use by the REST consumer * * @return the hostname, or <tt>null</tt> to use default hostname http://git-wip-us.apache.org/repos/asf/camel/blob/19b1f5c5/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerGetRestConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerGetRestConfigurationTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerGetRestConfigurationTest.java index b701c81..e254b1a 100644 --- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerGetRestConfigurationTest.java +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerGetRestConfigurationTest.java @@ -39,7 +39,7 @@ public class JettyRestProducerGetRestConfigurationTest extends BaseJettyTest { public void configure() throws Exception { String host = "localhost:" + getPort(); - restConfiguration().host(host).component("jetty"); + restConfiguration().producerComponent("jetty").host(host); from("direct:start") .to("rest:get:api:hello/hi/{name}") http://git-wip-us.apache.org/repos/asf/camel/blob/19b1f5c5/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerGetTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerGetTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerGetTest.java index 1798084..9ce781b 100644 --- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerGetTest.java +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerGetTest.java @@ -39,7 +39,7 @@ public class JettyRestProducerGetTest extends BaseJettyTest { public void configure() throws Exception { String host = "http://localhost:" + getPort(); - restConfiguration().component("jetty").host(host); + restConfiguration().producerComponent("jetty").host(host); from("direct:start") .to("rest:get:api:hello/hi/{name}") http://git-wip-us.apache.org/repos/asf/camel/blob/19b1f5c5/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/component/RestSwaggerGetTest.java ---------------------------------------------------------------------- diff --git a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/component/RestSwaggerGetTest.java b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/component/RestSwaggerGetTest.java index 766936d..05fca79 100644 --- a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/component/RestSwaggerGetTest.java +++ b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/component/RestSwaggerGetTest.java @@ -46,7 +46,7 @@ public class RestSwaggerGetTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - restConfiguration().setComponent("dummy"); + restConfiguration().producerComponent("dummy"); from("direct:start") .to("rest:get:hello/hi/{name}?apiDoc=hello-api.json") http://git-wip-us.apache.org/repos/asf/camel/blob/19b1f5c5/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/component/RestSwaggerGetUriParamTest.java ---------------------------------------------------------------------- diff --git a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/component/RestSwaggerGetUriParamTest.java b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/component/RestSwaggerGetUriParamTest.java index a1db6e9..a5783bb 100644 --- a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/component/RestSwaggerGetUriParamTest.java +++ b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/component/RestSwaggerGetUriParamTest.java @@ -45,7 +45,7 @@ public class RestSwaggerGetUriParamTest extends CamelTestSupport { return new RouteBuilder() { @Override public void configure() throws Exception { - restConfiguration().setComponent("dummy"); + restConfiguration().producerComponent("dummy"); from("direct:start") .to("rest:get:bye?name={name}&apiDoc=hello-api.json")
