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

commit 7d1e28cec8658a8cee4de23415fcaa759e95a30a
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Wed May 2 15:56:07 2018 +0200

    CAMEL-12442: rest-dsl producer should use rest configuration so you can 
configure producer based endpoint properties.
---
 .../camel/component/jetty/JettyHttpComponent.java  | 20 ++++++
 ...JettyRestProducerThrowExceptionOnErrorTest.java | 71 ++++++++++++++++++++++
 2 files changed, 91 insertions(+)

diff --git 
a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
 
b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index 563ba8d..d20b1332 100644
--- 
a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ 
b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -1254,6 +1254,26 @@ public abstract class JettyHttpComponent extends 
HttpCommonComponent implements
             url += "/" + uriTemplate;
         }
 
+        RestConfiguration config = configuration;
+        if (config == null) {
+            config = camelContext.getRestConfiguration("jetty", true);
+        }
+
+        Map<String, Object> map = new HashMap<>();
+        // build query string, and append any endpoint configuration properties
+        if (config.getComponent() == null || 
config.getComponent().equals("jetty")) {
+            // 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;
+        }
+
         JettyHttpEndpoint endpoint = camelContext.getEndpoint(url, 
JettyHttpEndpoint.class);
         if (parameters != null && !parameters.isEmpty()) {
             setProperties(camelContext, endpoint, parameters);
diff --git 
a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerThrowExceptionOnErrorTest.java
 
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerThrowExceptionOnErrorTest.java
new file mode 100644
index 0000000..4eed6ca
--- /dev/null
+++ 
b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/producer/JettyRestProducerThrowExceptionOnErrorTest.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.jetty.rest.producer;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jetty.BaseJettyTest;
+import org.junit.Test;
+
+public class JettyRestProducerThrowExceptionOnErrorTest extends BaseJettyTest {
+
+    @Test
+    public void testJettyProducerOk() throws Exception {
+        String out = fluentTemplate.withHeader("id", 
"123").to("direct:start").request(String.class);
+        assertEquals("123;Donald Duck", out);
+    }
+
+    @Test
+    public void testJettyProducerFail() 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("jetty").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 ("666".equals(id)) {
+                                    throw new IllegalArgumentException("Bad id 
number");
+                                }
+                                exchange.getOut().setBody(id + ";Donald Duck");
+                            }
+                        });
+            }
+        };
+    }
+
+}

-- 
To stop receiving notification emails like this one, please contact
davscl...@apache.org.

Reply via email to