Repository: camel Updated Branches: refs/heads/camel-2.18.x 692b0f7d1 -> 7c3f9e402
[CAMEL-11688]ensure transport endpoint configuration will be take into account when create JettyRestHttpBinding from REST DSL (cherry picked from commit 441bf37dde25a5c5ab08307afaa9eb290c86554e) (cherry picked from commit 6b2b0414c226ec4b605c4e4014f493b86c2dd05f) Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7c3f9e40 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7c3f9e40 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7c3f9e40 Branch: refs/heads/camel-2.18.x Commit: 7c3f9e402f18d1c01a48e899ec78a09dd8c04ea6 Parents: 692b0f7 Author: Freeman Fang <freeman.f...@gmail.com> Authored: Tue Aug 22 14:40:44 2017 +0800 Committer: Freeman Fang <freeman.f...@gmail.com> Committed: Tue Aug 22 14:51:03 2017 +0800 ---------------------------------------------------------------------- .../component/jetty/JettyRestHttpBinding.java | 5 ++ ...stJettyPostNotMapHttpMessageHeadersTest.java | 62 ++++++++++++++++++++ 2 files changed, 67 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/7c3f9e40/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestHttpBinding.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestHttpBinding.java b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestHttpBinding.java index 401b834..b89a7a5 100644 --- a/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestHttpBinding.java +++ b/components/camel-jetty-common/src/main/java/org/apache/camel/component/jetty/JettyRestHttpBinding.java @@ -28,6 +28,11 @@ public class JettyRestHttpBinding extends DefaultHttpBinding { } public JettyRestHttpBinding(HttpCommonEndpoint ep) { super(ep); + setHeaderFilterStrategy(ep.getHeaderFilterStrategy()); + setTransferException(ep.isTransferException()); + setEagerCheckContentAvailable(ep.isEagerCheckContentAvailable()); + setMapHttpMessageBody(ep.isMapHttpMessageBody()); + setMapHttpMessageHeaders(ep.isMapHttpMessageHeaders()); } @Override http://git-wip-us.apache.org/repos/asf/camel/blob/7c3f9e40/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostNotMapHttpMessageHeadersTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostNotMapHttpMessageHeadersTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostNotMapHttpMessageHeadersTest.java new file mode 100644 index 0000000..61ee548 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPostNotMapHttpMessageHeadersTest.java @@ -0,0 +1,62 @@ +/** + * 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; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jetty.BaseJettyTest; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.model.rest.RestBindingMode; +import org.junit.Test; + +public class RestJettyPostNotMapHttpMessageHeadersTest extends BaseJettyTest { + + @Test + public void testPostNotMapHttpMessageHeadersTest() throws Exception { + Map<String, Object> headers = new HashMap<String, Object>(); + headers.put(Exchange.HTTP_METHOD, "POST"); + headers.put(Exchange.CONTENT_TYPE, "application/x-www-form-urlencoded"); + String out = template.requestBodyAndHeaders("http://localhost:" + getPort() + "/rest/test", "{\"msg\": \"TEST\"}", headers, String.class); + assertEquals("\"OK\"", out); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + // configure to use jetty on localhost with the given port + //ensure we don't extract key=value pairs from form bodies + //(application/x-www-form-urlencoded) + restConfiguration().component("jetty").host("localhost").port(getPort()).bindingMode(RestBindingMode.json) + .endpointProperty("mapHttpMessageBody", "false") + .endpointProperty("mapHttpMessageHeaders", "false"); + + // use the rest DSL to define the rest services + rest("/rest") + .post("/test").produces("application/json") + .to("direct:test"); + from("direct:test").log("*** ${body}").removeHeaders("Content-Type*") + .setBody().simple("OK"); + } + }; + } + +}