[ 
https://issues.apache.org/jira/browse/CAMEL-12442?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16462063#comment-16462063
 ] 

ASF GitHub Bot commented on CAMEL-12442:
----------------------------------------

davsclaus closed pull request #2314: CAMEL-12442:rest-dsl - Rest producer 
should use RestConfiguration
URL: https://github.com/apache/camel/pull/2314
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 d0e93e2765f..39107cf4c44 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 Producer createProducer(CamelContext camelContext, 
String host,
         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 95bcb66041f..7444681a946 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 Producer createProducer(CamelContext camelContext, 
String host,
         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 28db0ab073d..bcac2518b14 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 Producer createProducer(CamelContext camelContext, 
String host,
         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 00000000000..d91d799d91e
--- /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 fe19fbae3b9..68585e79a6e 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 Producer createProducer(CamelContext camelContext, 
String host,
         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 00000000000..6d3841a89f2
--- /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 9c4bdf0b8aa..f1de36efb3a 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 Producer createProducer(CamelContext camelContext, 
String host,
         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 00000000000..f5dd887f010
--- /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");
+                            }
+                        });
+            }
+        };
+    }
+ 
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> rest-dsl - Rest producer should use RestConfiguration
> -----------------------------------------------------
>
>                 Key: CAMEL-12442
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12442
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-core
>            Reporter: Claus Ibsen
>            Priority: Major
>             Fix For: 2.22.0
>
>
> The RestConfiguration have additional configuration for component level, 
> endpoint level which you may want to allow to configure for the rest-dsl 
> producer side.
> Currently this is only supported on the consumer side.
> To introduce this, requires an API change in the RestProducerFactory method.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to