This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 505117a CAMEL-12442:rest-dsl - Rest producer should use
RestConfiguration (#2314)
505117a is described below
commit 505117adb445e2cc0c99bc1b2511d3ceb08591cc
Author: ramu11 <[email protected]>
AuthorDate: Thu May 3 13:14:34 2018 +0530
CAMEL-12442:rest-dsl - Rest producer should use RestConfiguration (#2314)
---
.../apache/camel/component/http/HttpComponent.java | 20 ++++++
.../camel/component/http4/HttpComponent.java | 19 ++++++
.../component/netty4/http/NettyHttpComponent.java | 20 ++++++
.../RestNettyProducerThrowExceptionErrorTest.java | 72 ++++++++++++++++++++++
.../camel/component/restlet/RestletComponent.java | 23 ++++++-
.../RestletProducerThrowExceptionErrorTest.java | 69 +++++++++++++++++++++
.../component/undertow/UndertowComponent.java | 20 ++++++
...estUndertowProducerThrowExceptionErrorTest.java | 71 +++++++++++++++++++++
8 files changed, 313 insertions(+), 1 deletion(-)
diff --git
a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
index d0e93e2..39107cf 100644
---
a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
+++
b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
@@ -312,6 +312,26 @@ public class HttpComponent extends HttpCommonComponent
implements RestProducerFa
if (!ObjectHelper.isEmpty(uriTemplate)) {
url += "/" + uriTemplate;
}
+
+ RestConfiguration config = configuration;
+ if (config == null) {
+ config = camelContext.getRestConfiguration("http", true);
+ }
+
+ Map<String, Object> map = new HashMap<>();
+ // build query string, and append any endpoint configuration properties
+ if (config.getComponent() == null ||
config.getComponent().equals("http")) {
+ // setup endpoint options
+ if (config.getEndpointProperties() != null &&
!config.getEndpointProperties().isEmpty()) {
+ map.putAll(config.getEndpointProperties());
+ }
+ }
+
+ // get the endpoint
+ String query = URISupport.createQueryString(map);
+ if (!query.isEmpty()) {
+ url = url + "?" + query;
+ }
HttpEndpoint endpoint = camelContext.getEndpoint(url,
HttpEndpoint.class);
if (parameters != null && !parameters.isEmpty()) {
diff --git
a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
index 95bcb66..7444681 100644
---
a/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
+++
b/components/camel-http4/src/main/java/org/apache/camel/component/http4/HttpComponent.java
@@ -433,7 +433,26 @@ public class HttpComponent extends HttpCommonComponent
implements RestProducerFa
if (!ObjectHelper.isEmpty(uriTemplate)) {
url += "/" + uriTemplate;
}
+
+ RestConfiguration config = configuration;
+ if (config == null) {
+ config = camelContext.getRestConfiguration("http4", true);
+ }
+ Map<String, Object> map = new HashMap<>();
+ // build query string, and append any endpoint configuration properties
+ if (config.getComponent() == null ||
config.getComponent().equals("http4")) {
+ // setup endpoint options
+ if (config.getEndpointProperties() != null &&
!config.getEndpointProperties().isEmpty()) {
+ map.putAll(config.getEndpointProperties());
+ }
+ }
+
+ // get the endpoint
+ String query = URISupport.createQueryString(map);
+ if (!query.isEmpty()) {
+ url = url + "?" + query;
+ }
HttpEndpoint endpoint = camelContext.getEndpoint(url,
HttpEndpoint.class);
if (parameters != null && !parameters.isEmpty()) {
setProperties(camelContext, endpoint, parameters);
diff --git
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
index 28db0ab..bcac251 100644
---
a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
+++
b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/NettyHttpComponent.java
@@ -430,6 +430,26 @@ public class NettyHttpComponent extends NettyComponent
implements HeaderFilterSt
if (!ObjectHelper.isEmpty(uriTemplate)) {
url += "/" + uriTemplate;
}
+
+ RestConfiguration config = configuration;
+ if (config == null) {
+ config = camelContext.getRestConfiguration("netty4-http", true);
+ }
+
+ Map<String, Object> map = new HashMap<>();
+ // build query string, and append any endpoint configuration properties
+ if (config.getComponent() == null ||
config.getComponent().equals("netty4-http")) {
+ // setup endpoint options
+ if (config.getEndpointProperties() != null &&
!config.getEndpointProperties().isEmpty()) {
+ map.putAll(config.getEndpointProperties());
+ }
+ }
+
+ // get the endpoint
+ String query = URISupport.createQueryString(map);
+ if (!query.isEmpty()) {
+ url = url + "?" + query;
+ }
NettyHttpEndpoint endpoint = camelContext.getEndpoint(url,
NettyHttpEndpoint.class);
if (parameters != null && !parameters.isEmpty()) {
diff --git
a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyProducerThrowExceptionErrorTest.java
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyProducerThrowExceptionErrorTest.java
new file mode 100644
index 0000000..d91d799
--- /dev/null
+++
b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyProducerThrowExceptionErrorTest.java
@@ -0,0 +1,72 @@
+/**
+ * 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.netty4.http.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.netty4.http.BaseNettyTest;
+import org.junit.Test;
+
+public class RestNettyProducerThrowExceptionErrorTest extends BaseNettyTest{
+
+ @Test
+ public void testUndertowProducerOk() throws Exception {
+ String out = fluentTemplate.withHeader("id",
"123").to("direct:start").request(String.class);
+ assertEquals("123;Donald Duck", out);
+ }
+
+ @Test
+ public void testUndertowProducerFail() throws Exception {
+ Exchange out = fluentTemplate.withHeader("id",
"777").to("direct:start").request(Exchange.class);
+ assertNotNull(out);
+ assertFalse("Should not have thrown exception", out.isFailed());
+ assertEquals(500, out.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use localhost with the given port
+
restConfiguration().component("netty4-http").host("localhost").port(getPort())
+ .endpointProperty("throwExceptionOnFailure", "false");
+
+ from("direct:start")
+ .to("rest:get:users/{id}/basic");
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .get("{id}/basic")
+ .route()
+ .to("mock:input")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ String id = exchange.getIn().getHeader("id",
String.class);
+ if ("777".equals(id)) {
+ throw new IllegalArgumentException("Bad id
number");
+ }
+ exchange.getOut().setBody(id + ";Donald Duck");
+ }
+ });
+ }
+ };
+ }
+
+
+}
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 fe19fba..68585e7 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
@@ -829,7 +829,28 @@ public class RestletComponent extends DefaultComponent
implements RestConsumerFa
if (!ObjectHelper.isEmpty(uriTemplate)) {
url += "/" + uriTemplate;
}
- url += "?restletMethod=" + restletMethod;
+
+ RestConfiguration config = configuration;
+ if (config == null) {
+ config = camelContext.getRestConfiguration("restlet", true);
+ }
+
+ Map<String, Object> map = new HashMap<>();
+ // build query string, and append any endpoint configuration properties
+ if (config.getComponent() == null ||
config.getComponent().equals("restlet")) {
+ // setup endpoint options
+ if (config.getEndpointProperties() != null &&
!config.getEndpointProperties().isEmpty()) {
+ map.putAll(config.getEndpointProperties());
+ }
+ }
+
+ // get the endpoint
+ String query = URISupport.createQueryString(map);
+ if (!query.isEmpty()) {
+ url = url + "?" + query;
+ } else {
+ url += "?restletMethod=" + restletMethod;
+ }
RestletEndpoint endpoint = camelContext.getEndpoint(url,
RestletEndpoint.class);
if (parameters != null && !parameters.isEmpty()) {
diff --git
a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerThrowExceptionErrorTest.java
b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerThrowExceptionErrorTest.java
new file mode 100644
index 0000000..6d3841a
--- /dev/null
+++
b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletProducerThrowExceptionErrorTest.java
@@ -0,0 +1,69 @@
+/**
+ * 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.restlet;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class RestletProducerThrowExceptionErrorTest extends RestletTestSupport
{
+
+ @Test
+ public void testRestletProducerOk() throws Exception {
+ String out = fluentTemplate.withHeader("id",
"123").to("direct:start").request(String.class);
+ assertEquals("123;Donald Duck", out);
+ }
+
+ @Test
+ public void testRestletProducerFail() throws Exception {
+ Exchange out = fluentTemplate.withHeader("id",
"666").to("direct:start").request(Exchange.class);
+ assertNotNull(out);
+ assertFalse("Should not have thrown exception", out.isFailed());
+ assertEquals(500, out.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use localhost with the given port
+
restConfiguration().component("restlet").host("localhost").port(portNum)
+ .endpointProperty("throwExceptionOnFailure", "false");
+
+ from("direct:start")
+ .to("rest:get:users/{id}/basic");
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .get("{id}/basic")
+ .route()
+ .to("mock:input")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ String id = exchange.getIn().getHeader("id",
String.class);
+ if ("666".equals(id)) {
+ throw new IllegalArgumentException("Bad id
number");
+ }
+ exchange.getOut().setBody(id + ";Donald Duck");
+ }
+ });
+ }
+ };
+ }
+}
diff --git
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
index 9c4bdf0..f1de36e 100644
---
a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
+++
b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
@@ -277,6 +277,26 @@ public class UndertowComponent extends DefaultComponent
implements RestConsumerF
if (!ObjectHelper.isEmpty(uriTemplate)) {
url += "/" + uriTemplate;
}
+
+ RestConfiguration config = configuration;
+ if (config == null) {
+ config = camelContext.getRestConfiguration("undertow", true);
+ }
+
+ Map<String, Object> map = new HashMap<>();
+ // build query string, and append any endpoint configuration properties
+ if (config.getComponent() == null ||
config.getComponent().equals("undertow")) {
+ // setup endpoint options
+ if (config.getEndpointProperties() != null &&
!config.getEndpointProperties().isEmpty()) {
+ map.putAll(config.getEndpointProperties());
+ }
+ }
+
+ // get the endpoint
+ String query = URISupport.createQueryString(map);
+ if (!query.isEmpty()) {
+ url = url + "?" + query;
+ }
UndertowEndpoint endpoint = camelContext.getEndpoint(url,
UndertowEndpoint.class);
if (parameters != null && !parameters.isEmpty()) {
diff --git
a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowProducerThrowExceptionErrorTest.java
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowProducerThrowExceptionErrorTest.java
new file mode 100644
index 0000000..f5dd887
--- /dev/null
+++
b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowProducerThrowExceptionErrorTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.undertow.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.junit.Test;
+
+public class RestUndertowProducerThrowExceptionErrorTest extends
BaseUndertowTest {
+
+ @Test
+ public void testUndertowProducerOk() throws Exception {
+ String out = fluentTemplate.withHeader("id",
"123").to("direct:start").request(String.class);
+ assertEquals("123;Donald Duck", out);
+ }
+
+ @Test
+ public void testUndertowProducerFail() throws Exception {
+ Exchange out = fluentTemplate.withHeader("id",
"777").to("direct:start").request(Exchange.class);
+ assertNotNull(out);
+ assertFalse("Should not have thrown exception", out.isFailed());
+ assertEquals(500, out.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use localhost with the given port
+
restConfiguration().component("undertow").host("localhost").port(getPort())
+ .endpointProperty("throwExceptionOnFailure", "false");
+
+ from("direct:start")
+ .to("rest:get:users/{id}/basic");
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .get("{id}/basic")
+ .route()
+ .to("mock:input")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws
Exception {
+ String id = exchange.getIn().getHeader("id",
String.class);
+ if ("777".equals(id)) {
+ throw new IllegalArgumentException("Bad id
number");
+ }
+ exchange.getOut().setBody(id + ";Donald Duck");
+ }
+ });
+ }
+ };
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
[email protected].