Repository: camel Updated Branches: refs/heads/master dcdbf4811 -> ea37bdb01
CAMEL-9833: Add mapHttpMessage option to allow to turn off mapping by default Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/19ba87c4 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/19ba87c4 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/19ba87c4 Branch: refs/heads/master Commit: 19ba87c4be2eb0c1e865f6a35e921e35353e7640 Parents: dcdbf48 Author: Andrea Cosentino <anco...@gmail.com> Authored: Fri Apr 8 09:11:29 2016 +0200 Committer: Andrea Cosentino <anco...@gmail.com> Committed: Fri Apr 8 09:11:55 2016 +0200 ---------------------------------------------------------------------- ...ndingPreservePostFormUrlEncodedBodyTest.java | 2 +- .../jetty/HttpBridgeBigFormPostRouteTest.java | 128 ------------------- .../JettyHttpMapHttpMessageHeadersTest.java | 117 +++++++++++++++++ 3 files changed, 118 insertions(+), 129 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/19ba87c4/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBindingPreservePostFormUrlEncodedBodyTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBindingPreservePostFormUrlEncodedBodyTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBindingPreservePostFormUrlEncodedBodyTest.java index 6fa6df0..ca46b62 100644 --- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBindingPreservePostFormUrlEncodedBodyTest.java +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBindingPreservePostFormUrlEncodedBodyTest.java @@ -44,7 +44,7 @@ public class HttpBindingPreservePostFormUrlEncodedBodyTest extends BaseJettyTest protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { - from("jetty:http://localhost:{{port}}/myapp/myservice").process(new Processor() { + from("jetty:http://localhost:{{port}}/myapp/myservice?map").process(new Processor() { public void process(Exchange exchange) throws Exception { String body = exchange.getIn().getBody(String.class); http://git-wip-us.apache.org/repos/asf/camel/blob/19ba87c4/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeBigFormPostRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeBigFormPostRouteTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeBigFormPostRouteTest.java deleted file mode 100644 index acf3952..0000000 --- a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/HttpBridgeBigFormPostRouteTest.java +++ /dev/null @@ -1,128 +0,0 @@ -/** - * 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; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.http.Consts; -import org.apache.http.HttpEntity; -import org.apache.http.NameValuePair; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.message.BasicNameValuePair; -import org.junit.Test; - -public class HttpBridgeBigFormPostRouteTest extends BaseJettyTest { - - private static final String LARGE_HEADER_VALUE = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " - + "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley " - + "of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap " - + "into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of " - + "Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus " - + "PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting " - + "industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer " - + "took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, " - + "but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s " - + "with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing " - + "software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing " - + "and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an " - + "unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five " - + "centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the " - + "1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing " - + "software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and " - + "typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown " - + "printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, " - + "but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the " - + "release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus " - + "PageMaker including versions of Lorem Ipsum." + "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " - + "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley " - + "of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap " - + "into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of " - + "Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus " - + "PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and typesetting " - + "industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer " - + "took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, " - + "but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s " - + "with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing " - + "software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing " - + "and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an " - + "unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five " - + "centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the " - + "1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing " - + "software like Aldus PageMaker including versions of Lorem Ipsum. Lorem Ipsum is simply dummy text of the printing and " - + "typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown " - + "printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, " - + "but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the " - + "release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus " - + "PageMaker including versions of Lorem Ipsum."; - - private int port1; - private int port2; - - @Test - public void testHttpClient() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:input"); - mock.expectedMessageCount(1); - - List<NameValuePair> nvps = new ArrayList<NameValuePair>(); - nvps.add(new BasicNameValuePair("param1", LARGE_HEADER_VALUE)); - nvps.add(new BasicNameValuePair("param2", LARGE_HEADER_VALUE)); - nvps.add(new BasicNameValuePair("param3", LARGE_HEADER_VALUE)); - - HttpEntity entity = new UrlEncodedFormEntity(nvps, Consts.UTF_8); - HttpPost httpPost = new HttpPost("http://localhost:" + port2 + "/test/hello"); - httpPost.setEntity(entity); - - CloseableHttpClient httpClient = HttpClients.createDefault(); - try { - CloseableHttpResponse response = httpClient.execute(httpPost); - assertEquals(response.getStatusLine().getStatusCode(), 200); - response.close(); - } finally { - httpClient.close(); - } - - mock.assertIsSatisfied(); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - port1 = getPort(); - port2 = getNextPort(); - - errorHandler(noErrorHandler()); - - from("jetty:http://localhost:" + port2 + "/test/hello?matchOnUriPrefix=true&mapHttpMessageHeaders=false&mapHttpMessageBody=false") - .log("I was here") - .to("jetty:http://localhost:" + port1 + "?bridgeEndpoint=true"); - - from("jetty://http://localhost:" + port1 + "?matchOnUriPrefix=true") - .log("Me too") - .to("mock:input"); - - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/19ba87c4/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/JettyHttpMapHttpMessageHeadersTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/JettyHttpMapHttpMessageHeadersTest.java b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/JettyHttpMapHttpMessageHeadersTest.java new file mode 100644 index 0000000..5b3fad5 --- /dev/null +++ b/components/camel-jetty9/src/test/java/org/apache/camel/component/jetty/JettyHttpMapHttpMessageHeadersTest.java @@ -0,0 +1,117 @@ +/** + * 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; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; + +public class JettyHttpMapHttpMessageHeadersTest extends BaseJettyTest { + + private String serverUriFiltered = "http://localhost:" + getPort() + "/myservice"; + private String serverUriNotFiltered = "http://localhost:" + getPort() + "/myservice1"; + + @Test + public void testHttpGetWithParamsViaURIFiltered() throws Exception { + + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + mock.expectedHeaderReceived("one", null); + mock.expectedHeaderReceived("two", null); + mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "GET"); + + template.requestBody(serverUriFiltered + "?one=einz&two=twei", null, Object.class); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testHttpGetWithParamsViaURINotFiltered() throws Exception { + + MockEndpoint mock = getMockEndpoint("mock:result1"); + mock.expectedMessageCount(1); + mock.expectedHeaderReceived("one", "einz"); + mock.expectedHeaderReceived("two", "twei"); + mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "GET"); + + template.requestBody(serverUriNotFiltered + "?one=einz&two=twei", null, Object.class); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testHttpGetWithParamsViaHeaderFiltered() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + mock.expectedHeaderReceived("one", null); + mock.expectedHeaderReceived("two", null); + mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "GET"); + + template.requestBodyAndHeader(serverUriFiltered, null, Exchange.HTTP_QUERY, "one=uno&two=dos"); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testHttpGetWithParamsViaHeaderNotFiltered() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result1"); + mock.expectedMessageCount(1); + mock.expectedHeaderReceived("one", "uno"); + mock.expectedHeaderReceived("two", "dos"); + mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "GET"); + + template.requestBodyAndHeader(serverUriNotFiltered, null, Exchange.HTTP_QUERY, "one=uno&two=dos"); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testHttpPostNotFiltered() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result1"); + mock.expectedMessageCount(1); + mock.expectedBodiesReceived("Hello World"); + mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "POST"); + mock.expectedHeaderReceived("header1", "pippo"); + + template.requestBodyAndHeader(serverUriNotFiltered, "Hello World", "header1", "pippo"); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testHttpPostFiltered() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedMessageCount(1); + mock.expectedBodiesReceived("Hello World"); + mock.expectedHeaderReceived(Exchange.HTTP_METHOD, "POST"); + mock.expectedHeaderReceived("header1", null); + + template.requestBodyAndHeader(serverUriFiltered, "Hello World", "header1", "pippo"); + + assertMockEndpointsSatisfied(); + } + + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() throws Exception { + from("jetty:" + serverUriFiltered + "?mapHttpMessageHeaders=false").to("mock:result"); + from("jetty:" + serverUriNotFiltered).to("mock:result1"); + } + }; + } +}