Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcComponentClientConfigTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcComponentClientConfigTest.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcComponentClientConfigTest.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcComponentClientConfigTest.java Fri Jun 3 12:46:49 2011 @@ -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.ahc; + +import com.ning.http.client.AsyncHttpClientConfig; +import org.apache.camel.CamelContext; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class AhcComponentClientConfigTest extends CamelTestSupport { + + @Override + protected CamelContext createCamelContext() throws Exception { + AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder(); + AsyncHttpClientConfig config = builder.setFollowRedirects(true).setMaxRequestRetry(3).build(); + + CamelContext context = super.createCamelContext(); + AhcComponent component = context.getComponent("ahc", AhcComponent.class); + component.setClientConfig(config); + return context; + } + + @Test + public void testAhcComponentClientConfig() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + + template.sendBody("direct:start", null); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("ahc:http://localhost:9080/foo") + .to("mock:result"); + + from("jetty:http://localhost:9080/foo") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + // redirect to test the client config worked as we told it to follow redirects + exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, "301"); + exchange.getOut().setHeader("Location", "http://localhost:9080/bar"); + } + }); + + from("jetty:http://localhost:9080/bar") + .transform(constant("Bye World")); + } + }; + } +}
Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcComponentClientConfigTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcComponentClientConfigTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcGoogleTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcGoogleTest.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcGoogleTest.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcGoogleTest.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,53 @@ +/** + * 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.ahc; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Ignore; +import org.junit.Test; + +/** + * Requires online internet connection for testing. + */ +@Ignore("Run this test manual as it requires online internet") +public class AhcGoogleTest extends CamelTestSupport { + + @Test + public void testAhcGoogle() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(1); + + template.sendBody("direct:start", null); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("ahc:http://www.google.se") + .to("log:result?showAll=true") + .convertBodyTo(String.class) + .log("Google responded with body:\n${body}") + .to("mock:result"); + } + }; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcGoogleTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcGoogleTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduce500Test.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduce500Test.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduce500Test.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduce500Test.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,68 @@ +/** + * 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.ahc; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class AhcProduce500Test extends CamelTestSupport { + + @Test + public void testAhcProduce() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); + + try { + template.sendBody("direct:start", null); + fail("Should have thrown exception"); + } catch (CamelExecutionException e) { + AhcOperationFailedException cause = assertIsInstanceOf(AhcOperationFailedException.class, e.getCause()); + assertNotNull(cause); + assertEquals(500, cause.getStatusCode()); + assertEquals("Server Error", cause.getStatusText()); + assertEquals("Does not work", cause.getResponseBody()); + assertEquals(false, cause.isRedirectError()); + assertNotNull(cause.getResponseHeaders()); + } + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("ahc:http://localhost:9080/foo") + .to("mock:result"); + + from("jetty:http://localhost:9080/foo") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 500); + exchange.getOut().setBody("Does not work"); + } + }); + + } + }; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduce500Test.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduce500Test.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceClientConfigTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceClientConfigTest.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceClientConfigTest.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceClientConfigTest.java Fri Jun 3 12:46:49 2011 @@ -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.ahc; + +import com.ning.http.client.AsyncHttpClientConfig; +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.impl.JndiRegistry; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class AhcProduceClientConfigTest extends CamelTestSupport { + + @Override + protected JndiRegistry createRegistry() throws Exception { + AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder(); + AsyncHttpClientConfig config = builder.setFollowRedirects(true).setMaxRequestRetry(3).build(); + + JndiRegistry jndi = super.createRegistry(); + jndi.bind("myConfig", config); + return jndi; + } + + @Test + public void testAhcProduceClientConfig() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + + template.sendBody("direct:start", null); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("ahc:http://localhost:9080/foo?clientConfig=#myConfig") + .to("mock:result"); + + from("jetty:http://localhost:9080/foo") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + // redirect to test the client config worked as we told it to follow redirects + exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, "301"); + exchange.getOut().setHeader("Location", "http://localhost:9080/bar"); + } + }); + + from("jetty:http://localhost:9080/bar") + .transform(constant("Bye World")); + } + }; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceClientConfigTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceClientConfigTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetHeadersTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetHeadersTest.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetHeadersTest.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetHeadersTest.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,60 @@ +/** + * 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.ahc; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class AhcProduceGetHeadersTest extends CamelTestSupport { + + @Test + public void testAhcProduce() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + getMockEndpoint("mock:result").expectedHeaderReceived("foo", 123); + getMockEndpoint("mock:result").expectedHeaderReceived("bar", "cool"); + getMockEndpoint("mock:result").expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 200); + getMockEndpoint("mock:result").expectedHeaderReceived(Exchange.CONTENT_LENGTH, 9); + + Map<String, Object> headers = new HashMap<String, Object>(); + headers.put("foo", 123); + headers.put("bar", "cool"); + + template.sendBodyAndHeaders("direct:start", null, headers); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("ahc:http://localhost:9080/foo") + .to("mock:result"); + + from("jetty:http://localhost:9080/foo") + .transform(constant("Bye World")); + } + }; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetHeadersTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetHeadersTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetNoSlashInUriTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetNoSlashInUriTest.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetNoSlashInUriTest.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetNoSlashInUriTest.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,49 @@ +/** + * 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.ahc; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class AhcProduceGetNoSlashInUriTest extends CamelTestSupport { + + @Test + public void testAhcProduce() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + + template.sendBody("direct:start", null); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + // no // slash in uri should still work + .to("ahc:http:localhost:9080/foo") + .to("mock:result"); + + from("jetty:http://localhost:9080/foo") + .transform(constant("Bye World")); + } + }; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetNoSlashInUriTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetNoSlashInUriTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetTest.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetTest.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetTest.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,58 @@ +/** + * 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.ahc; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class AhcProduceGetTest extends CamelTestSupport { + + @Test + public void testAhcProduce() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + + template.sendBody("direct:start", null); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testAhcProduceGetHeader() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + + template.sendBodyAndHeader("direct:start", null, Exchange.HTTP_METHOD, "GET"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("ahc:http://localhost:9080/foo") + .to("mock:result"); + + from("jetty:http://localhost:9080/foo") + .transform(constant("Bye World")); + } + }; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceGetTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceNoThrowExceptionOnFailureTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceNoThrowExceptionOnFailureTest.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceNoThrowExceptionOnFailureTest.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceNoThrowExceptionOnFailureTest.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,57 @@ +/** + * 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.ahc; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class AhcProduceNoThrowExceptionOnFailureTest extends CamelTestSupport { + + @Test + public void testAhcProduce() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Does not work"); + getMockEndpoint("mock:result").expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 500); + + template.sendBody("direct:start", null); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("ahc:http://localhost:9080/foo?throwExceptionOnFailure=false") + .to("mock:result"); + + from("jetty:http://localhost:9080/foo") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 500); + exchange.getOut().setBody("Does not work"); + } + }); + + } + }; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceNoThrowExceptionOnFailureTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceNoThrowExceptionOnFailureTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostHeadersTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostHeadersTest.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostHeadersTest.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostHeadersTest.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,60 @@ +/** + * 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.ahc; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class AhcProducePostHeadersTest extends CamelTestSupport { + + @Test + public void testAhcProduce() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + getMockEndpoint("mock:result").expectedHeaderReceived("foo", 123); + getMockEndpoint("mock:result").expectedHeaderReceived("bar", "cool"); + getMockEndpoint("mock:result").expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 200); + getMockEndpoint("mock:result").expectedHeaderReceived(Exchange.CONTENT_LENGTH, 9); + + Map<String, Object> headers = new HashMap<String, Object>(); + headers.put("foo", 123); + headers.put("bar", "cool"); + + template.sendBodyAndHeaders("direct:start", "World", headers); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("ahc:http://localhost:9080/foo") + .to("mock:result"); + + from("jetty:http://localhost:9080/foo") + .transform(simple("Bye ${body}")); + } + }; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostHeadersTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostHeadersTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostTest.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostTest.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostTest.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,58 @@ +/** + * 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.ahc; + +import org.apache.camel.Exchange; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class AhcProducePostTest extends CamelTestSupport { + + @Test + public void testAhcProduce() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + + template.sendBody("direct:start", "World"); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testAhcProducePostHeader() throws Exception { + getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); + + template.sendBodyAndHeader("direct:start", "World", Exchange.HTTP_METHOD, "POST"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("ahc:http://localhost:9080/foo") + .to("mock:result"); + + from("jetty:http://localhost:9080/foo") + .transform(simple("Bye ${body}")); + } + }; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProducePostTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceTransferExceptionTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceTransferExceptionTest.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceTransferExceptionTest.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceTransferExceptionTest.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,56 @@ +/** + * 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.ahc; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +public class AhcProduceTransferExceptionTest extends CamelTestSupport { + + @Test + public void testAhcProduce() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(0); + + try { + template.sendBody("direct:start", null); + fail("Should have thrown exception"); + } catch (CamelExecutionException e) { + MyOrderException cause = assertIsInstanceOf(MyOrderException.class, e.getCause()); + assertNotNull(cause); + assertEquals("123", cause.getOrderId()); + } + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:start") + .to("ahc:http://localhost:9080/foo?transferException=true") + .to("mock:result"); + + from("jetty:http://localhost:9080/foo?transferException=true") + .throwException(new MyOrderException("123")); + } + }; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceTransferExceptionTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/AhcProduceTransferExceptionTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/MyOrderException.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/MyOrderException.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/MyOrderException.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/MyOrderException.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,36 @@ +/** + * 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.ahc; + +import java.io.Serializable; + +/** + * + */ +public class MyOrderException extends Exception implements Serializable { + + private final String orderId; + + public MyOrderException(String orderId) { + super("Unknown orderId: " + orderId); + this.orderId = orderId; + } + + public String getOrderId() { + return orderId; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/MyOrderException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/MyOrderException.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/AhcProduceJavaBodyTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/AhcProduceJavaBodyTest.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/AhcProduceJavaBodyTest.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/AhcProduceJavaBodyTest.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,126 @@ +/** + * 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.ahc.javabody; + +import org.apache.camel.Exchange; +import org.apache.camel.Processor; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.ahc.AhcConstants; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + +/** + * + */ +public class AhcProduceJavaBodyTest extends CamelTestSupport { + + @Override + public boolean isUseRouteBuilder() { + return false; + } + + @Test + public void testHttpSendJavaBodyAndReceiveString() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("jetty:http://localhost:9080/myapp/myservice") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + MyCoolBean cool = exchange.getIn().getBody(MyCoolBean.class); + assertNotNull(cool); + + assertEquals(123, cool.getId()); + assertEquals("Camel", cool.getName()); + + // we send back plain test + exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/plain"); + exchange.getOut().setBody("OK"); + } + }); + } + }); + context.start(); + + MyCoolBean cool = new MyCoolBean(123, "Camel"); + + String reply = template.requestBodyAndHeader("ahc:http:localhost:9080/myapp/myservice", cool, + Exchange.CONTENT_TYPE, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, String.class); + + assertEquals("OK", reply); + } + + @Test + public void testHttpSendJavaBodyAndReceiveJavaBody() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("jetty:http://localhost:9080/myapp/myservice") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + MyCoolBean cool = exchange.getIn().getBody(MyCoolBean.class); + assertNotNull(cool); + + assertEquals(123, cool.getId()); + assertEquals("Camel", cool.getName()); + + MyCoolBean reply = new MyCoolBean(456, "Camel rocks"); + exchange.getOut().setBody(reply); + exchange.getOut().setHeader(Exchange.CONTENT_TYPE, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT); + } + }); + } + }); + context.start(); + + MyCoolBean cool = new MyCoolBean(123, "Camel"); + + MyCoolBean reply = template.requestBodyAndHeader("ahc:http://localhost:9080/myapp/myservice", cool, + Exchange.CONTENT_TYPE, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT, MyCoolBean.class); + + assertEquals(456, reply.getId()); + assertEquals("Camel rocks", reply.getName()); + } + + @Test + public void testHttpSendStringAndReceiveJavaBody() throws Exception { + context.addRoutes(new RouteBuilder() { + @Override + public void configure() throws Exception { + from("jetty:http://localhost:9080/myapp/myservice") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + String body = exchange.getIn().getBody(String.class); + assertNotNull(body); + assertEquals("Hello World", body); + + MyCoolBean reply = new MyCoolBean(456, "Camel rocks"); + exchange.getOut().setBody(reply); + exchange.getOut().setHeader(Exchange.CONTENT_TYPE, AhcConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT); + } + }); + } + }); + context.start(); + + MyCoolBean reply = template.requestBody("ahc:http://localhost:9080/myapp/myservice", "Hello World", MyCoolBean.class); + + assertEquals(456, reply.getId()); + assertEquals("Camel rocks", reply.getName()); + } + +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/AhcProduceJavaBodyTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/AhcProduceJavaBodyTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/MyCoolBean.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/MyCoolBean.java?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/MyCoolBean.java (added) +++ camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/MyCoolBean.java Fri Jun 3 12:46:49 2011 @@ -0,0 +1,41 @@ +/** + * 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.ahc.javabody; + +import java.io.Serializable; + +/** + * + */ +public class MyCoolBean implements Serializable { + + private final int id; + private final String name; + + public MyCoolBean(int id, String name) { + this.id = id; + this.name = name; + } + + public int getId() { + return id; + } + + public String getName() { + return name; + } +} Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/MyCoolBean.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/java/org/apache/camel/component/ahc/javabody/MyCoolBean.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-ahc/src/test/resources/log4j.properties URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ahc/src/test/resources/log4j.properties?rev=1131016&view=auto ============================================================================== --- camel/trunk/components/camel-ahc/src/test/resources/log4j.properties (added) +++ camel/trunk/components/camel-ahc/src/test/resources/log4j.properties Fri Jun 3 12:46:49 2011 @@ -0,0 +1,36 @@ +## ------------------------------------------------------------------------ +## 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. +## ------------------------------------------------------------------------ + +# +# The logging properties used for testing. +# +log4j.rootLogger=INFO, file + +# uncomment the following to enable camel debugging +#log4j.logger.org.apache.camel.component.ahc=TRACE + +# CONSOLE appender not used by default +log4j.appender.out=org.apache.log4j.ConsoleAppender +log4j.appender.out.layout=org.apache.log4j.PatternLayout +log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n +#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n + +# File appender +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d %-5p %c{1} - %m %n +log4j.appender.file.file=target/camel-ahc-test.log \ No newline at end of file Propchange: camel/trunk/components/camel-ahc/src/test/resources/log4j.properties ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-ahc/src/test/resources/log4j.properties ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/components/camel-ahc/src/test/resources/log4j.properties ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java?rev=1131016&r1=1131015&r2=1131016&view=diff ============================================================================== --- camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java (original) +++ camel/trunk/components/camel-http/src/main/java/org/apache/camel/component/http/helper/HttpHelper.java Fri Jun 3 12:46:49 2011 @@ -191,7 +191,6 @@ public final class HttpHelper { } catch (Throwable t) { throw new RuntimeExchangeException("Cannot analyze the Exchange.HTTP_PATH header, due to: " + t.getMessage(), exchange, t); } - } if (path.length() > 0) { // make sure that there is exactly one "/" between HTTP_URI and Modified: camel/trunk/components/pom.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/pom.xml?rev=1131016&r1=1131015&r2=1131016&view=diff ============================================================================== --- camel/trunk/components/pom.xml (original) +++ camel/trunk/components/pom.xml Fri Jun 3 12:46:49 2011 @@ -51,6 +51,7 @@ <module>camel-jms</module> <!-- regular modules in alphabetic order --> + <module>camel-ahc</module> <module>camel-amqp</module> <module>camel-atom</module> <module>camel-aws</module> Modified: camel/trunk/parent/pom.xml URL: http://svn.apache.org/viewvc/camel/trunk/parent/pom.xml?rev=1131016&r1=1131015&r2=1131016&view=diff ============================================================================== --- camel/trunk/parent/pom.xml (original) +++ camel/trunk/parent/pom.xml Fri Jun 3 12:46:49 2011 @@ -36,6 +36,7 @@ <compiler.fork>false</compiler.fork> <!-- Note that activemq dependency is only used for testing! --> <activemq-version>5.5.0</activemq-version> + <ahc-version>1.6.3</ahc-version> <apacheds-version>1.5.7</apacheds-version> <aries-blueprint-version>0.3</aries-blueprint-version> <atomikos-trascations-version>3.7.0</atomikos-trascations-version> @@ -218,6 +219,11 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-ahc</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-amqp</artifactId> <version>${project.version}</version> </dependency>