http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitHttpsSslContextParametersRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitHttpsSslContextParametersRouteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitHttpsSslContextParametersRouteTest.java deleted file mode 100644 index 79cf75c..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitHttpsSslContextParametersRouteTest.java +++ /dev/null @@ -1,85 +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.HashMap; -import java.util.Map; - -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.util.jsse.KeyManagersParameters; -import org.apache.camel.util.jsse.KeyStoreParameters; -import org.apache.camel.util.jsse.SSLContextParameters; -import org.eclipse.jetty.server.Connector; -import org.junit.Ignore; - -@Ignore -public class ExplicitHttpsSslContextParametersRouteTest extends HttpsRouteTest { - - // START SNIPPET: e2 - private Connector createSslSocketConnector(CamelContext context, int port) throws Exception { - KeyStoreParameters ksp = new KeyStoreParameters(); - ksp.setResource(this.getClass().getClassLoader().getResource("jsse/localhost.ks").toString()); - ksp.setPassword(pwd); - - KeyManagersParameters kmp = new KeyManagersParameters(); - kmp.setKeyPassword(pwd); - kmp.setKeyStore(ksp); - - SSLContextParameters sslContextParameters = new SSLContextParameters(); - sslContextParameters.setKeyManagers(kmp); - - // From Camel 2.5.0 Camel-Jetty is using SslSelectChannelConnector instead of SslSocketConnector - //SslSelectChannelConnector sslSocketConnector = new SslSelectChannelConnector(); - //sslSocketConnector.getSslContextFactory().setSslContext(sslContextParameters.createSSLContext()); - //sslSocketConnector.setPort(port); - - //return sslSocketConnector; - return null; - } - // END SNIPPET: e2 - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - // START SNIPPET: e1 - // create SSL select channel connectors for port 9080 and 9090 - Map<Integer, Connector> connectors = new HashMap<Integer, Connector>(); - connectors.put(port1, createSslSocketConnector(getContext(), port1)); - connectors.put(port2, createSslSocketConnector(getContext(), port2)); - - JettyHttpComponent jetty = getContext().getComponent("jetty", JettyHttpComponent.class); - jetty.setSslSocketConnectors(connectors); - // END SNIPPET: e1 - - from("jetty:https://localhost:" + port1 + "/test").to("mock:a"); - - Processor proc = new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setBody("<b>Hello World</b>"); - } - }; - from("jetty:https://localhost:" + port1 + "/hello").process(proc); - - from("jetty:https://localhost:" + port2 + "/test").to("mock:b"); - } - }; - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitJettyRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitJettyRouteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitJettyRouteTest.java deleted file mode 100644 index 194c42f..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/ExplicitJettyRouteTest.java +++ /dev/null @@ -1,65 +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 javax.servlet.http.HttpServletRequest; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -/** - * Unit test for wiki demonstration. - */ -public class ExplicitJettyRouteTest extends BaseJettyTest { - - @Test - public void testSendToJetty() throws Exception { - Object response = template.requestBody("http://localhost:{{port}}/myapp/myservice", "bookid=123"); - // convert the response to a String - String body = context.getTypeConverter().convertTo(String.class, response); - assertEquals("<html><body>Book 123 is Camel in Action</body></html>", body); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - from("jetty:http://localhost:{{port}}/myapp/myservice").process(new MyBookService()); - } - }; - } - - public class MyBookService implements Processor { - public void process(Exchange exchange) throws Exception { - // just get the body as a string - String body = exchange.getIn().getBody(String.class); - - // we have access to the HttpServletRequest here and we can grab it if we need it - HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class); - assertNotNull(req); - - // for unit testing - assertEquals("bookid=123", body); - - // send a html response - exchange.getOut().setBody("<html><body>Book 123 is Camel in Action</body></html>"); - } - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HandlerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HandlerTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HandlerTest.java deleted file mode 100644 index 7ff661f..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HandlerTest.java +++ /dev/null @@ -1,106 +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.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; - -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.util.IOHelper; - -import org.eclipse.jetty.server.handler.StatisticsHandler; - -import org.junit.Test; - -public class HandlerTest extends BaseJettyTest { - private StatisticsHandler statisticsHandler1 = new StatisticsHandler(); - private StatisticsHandler statisticsHandler2 = new StatisticsHandler(); - private StatisticsHandler statisticsHandler3 = new StatisticsHandler(); - - private String htmlResponse = "<html><body>Book 123 is Camel in Action</body></html>"; - private int port1; - private int port2; - - @Test - public void testWithOneHandler() throws Exception { - // First test the situation where one should invoke the handler once - assertEquals(0, statisticsHandler1.getRequests()); - assertEquals(0, statisticsHandler2.getRequests()); - assertEquals(0, statisticsHandler3.getRequests()); - - InputStream html = (InputStream) template.requestBody("http://localhost:" + port1, ""); - BufferedReader br = IOHelper.buffered(new InputStreamReader(html)); - - assertEquals(htmlResponse, br.readLine()); - assertEquals(1, statisticsHandler1.getRequests()); - assertEquals(0, statisticsHandler2.getRequests()); - assertEquals(0, statisticsHandler3.getRequests()); - } - - @Test - public void testWithTwoHandlers() throws Exception { - // First test the situation where one should invoke the handler once - assertEquals(0, statisticsHandler1.getRequests()); - assertEquals(0, statisticsHandler2.getRequests()); - assertEquals(0, statisticsHandler3.getRequests()); - - InputStream html = (InputStream) template.requestBody("http://localhost:" + port2, ""); - BufferedReader br = IOHelper.buffered(new InputStreamReader(html)); - - assertEquals(htmlResponse, br.readLine()); - assertEquals(0, statisticsHandler1.getRequests()); - assertEquals(1, statisticsHandler2.getRequests()); - assertEquals(1, statisticsHandler3.getRequests()); - } - - @Override - protected JndiRegistry createRegistry() throws Exception { - JndiRegistry jndi = super.createRegistry(); - jndi.bind("statisticsHandler1", statisticsHandler1); - jndi.bind("statisticsHandler2", statisticsHandler2); - jndi.bind("statisticsHandler3", statisticsHandler3); - return jndi; - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - port1 = getPort(); - port2 = getNextPort(); - - from("jetty:http://localhost:" + port1 + "/?handlers=#statisticsHandler1") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setBody(htmlResponse); - } - }); - - from("jetty:http://localhost:" + port2 + "/?handlers=#statisticsHandler2,#statisticsHandler3") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setBody(htmlResponse); - } - }); - }; - }; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java deleted file mode 100644 index ec1a616..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java +++ /dev/null @@ -1,125 +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.io.IOException; -import java.security.Principal; -import java.util.Arrays; -import javax.servlet.http.HttpServletRequest; - -import org.apache.camel.Exchange; -import org.apache.camel.FailedToCreateProducerException; -import org.apache.camel.Processor; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.http.HttpOperationFailedException; -import org.apache.camel.impl.JndiRegistry; -import org.eclipse.jetty.security.ConstraintMapping; -import org.eclipse.jetty.security.ConstraintSecurityHandler; -import org.eclipse.jetty.security.HashLoginService; -import org.eclipse.jetty.security.SecurityHandler; -import org.eclipse.jetty.security.authentication.BasicAuthenticator; -import org.eclipse.jetty.util.security.Constraint; -import org.junit.Test; - -/** - * @version - */ -public class HttpAuthMethodPriorityTest extends BaseJettyTest { - - @Override - protected JndiRegistry createRegistry() throws Exception { - JndiRegistry jndi = super.createRegistry(); - jndi.bind("myAuthHandler", getSecurityHandler()); - return jndi; - } - private SecurityHandler getSecurityHandler() throws IOException { - Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user"); - constraint.setAuthenticate(true); - - ConstraintMapping cm = new ConstraintMapping(); - cm.setPathSpec("/*"); - cm.setConstraint(constraint); - - ConstraintSecurityHandler sh = new ConstraintSecurityHandler(); - sh.setAuthenticator(new BasicAuthenticator()); - sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] {cm})); - - HashLoginService loginService = new HashLoginService("MyRealm", "src/test/resources/myRealm.properties"); - sh.setLoginService(loginService); - sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[]{cm})); - - return sh; - } - - @Test - public void testAuthMethodPriorityBasicDigest() throws Exception { - String out = template.requestBody("http://localhost:{{port}}/test?authMethod=Basic&authMethodPriority=Basic,Digest&authUsername=donald&authPassword=duck", "Hello World", String.class); - assertEquals("Bye World", out); - } - - @Test - public void testAuthMethodPriorityNTLMBasic() throws Exception { - String out = template.requestBody("http://localhost:{{port}}/test?authMethod=Basic&authMethodPriority=NTLM,Basic&authUsername=donald&authPassword=duck", "Hello World", String.class); - assertEquals("Bye World", out); - } - - @Test - public void testAuthMethodPriorityInvalid() throws Exception { - try { - template.requestBody("http://localhost:{{port}}/test?authMethod=Basic&authMethodPriority=Basic,foo&authUsername=donald&authPassword=duck", "Hello World", String.class); - fail("Should have thrown an exception"); - } catch (FailedToCreateProducerException e) { - IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause().getCause()); - //JAXB 2.2 uses a slightly different message - boolean b = cause.getMessage().contains("No enum const") - && cause.getMessage().contains("org.apache.camel.component.http.AuthMethod.foo"); - assertTrue("Bad fault message: " + cause.getMessage(), b); - } - } - - @Test - public void testAuthMethodPriorityNTLM() throws Exception { - try { - template.requestBody("http://localhost:{{port}}/test?authMethod=Basic&authMethodPriority=NTLM&authUsername=donald&authPassword=duck", "Hello World", String.class); - fail("Should have thrown exception"); - } catch (RuntimeCamelException e) { - HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); - assertEquals(401, cause.getStatusCode()); - } - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test?handlers=myAuthHandler") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class); - assertNotNull(req); - Principal user = req.getUserPrincipal(); - assertNotNull(user); - assertEquals("donald", user.getName()); - } - }) - .transform(constant("Bye World")); - } - }; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthComponentConfiguredTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthComponentConfiguredTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthComponentConfiguredTest.java deleted file mode 100644 index 18fccfc..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthComponentConfiguredTest.java +++ /dev/null @@ -1,109 +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.io.IOException; -import java.security.Principal; -import java.util.Arrays; -import javax.servlet.http.HttpServletRequest; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.http.AuthMethod; -import org.apache.camel.component.http.HttpComponent; -import org.apache.camel.component.http.HttpConfiguration; -import org.apache.camel.impl.JndiRegistry; -import org.eclipse.jetty.security.ConstraintMapping; -import org.eclipse.jetty.security.ConstraintSecurityHandler; -import org.eclipse.jetty.security.HashLoginService; -import org.eclipse.jetty.security.SecurityHandler; -import org.eclipse.jetty.security.authentication.BasicAuthenticator; -import org.eclipse.jetty.util.security.Constraint; -import org.junit.Test; - -/** - * @version - */ -public class HttpBasicAuthComponentConfiguredTest extends BaseJettyTest { - - @Override - protected JndiRegistry createRegistry() throws Exception { - JndiRegistry jndi = super.createRegistry(); - jndi.bind("myAuthHandler", getSecurityHandler()); - return jndi; - } - - private SecurityHandler getSecurityHandler() throws IOException { - Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user"); - constraint.setAuthenticate(true); - - ConstraintMapping cm = new ConstraintMapping(); - cm.setPathSpec("/*"); - cm.setConstraint(constraint); - - ConstraintSecurityHandler sh = new ConstraintSecurityHandler(); - sh.setAuthenticator(new BasicAuthenticator()); - sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] {cm})); - - HashLoginService loginService = new HashLoginService("MyRealm", "src/test/resources/myRealm.properties"); - sh.setLoginService(loginService); - sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[]{cm})); - - return sh; - } - - @Test - public void testHttpBasicAuth() throws Exception { - String out = template.requestBody("http://localhost:{{port}}/test", "Hello World", String.class); - assertEquals("Bye World", out); - - out = template.requestBody("http://localhost:{{port}}/anotherTest", "Hello World", String.class); - assertEquals("See you later", out); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - HttpConfiguration config = new HttpConfiguration(); - config.setAuthMethod(AuthMethod.Basic); - config.setAuthUsername("donald"); - config.setAuthPassword("duck"); - - HttpComponent http = context.getComponent("http", HttpComponent.class); - http.setHttpConfiguration(config); - - from("jetty://http://localhost:{{port}}/test?handlers=myAuthHandler") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class); - assertNotNull(req); - Principal user = req.getUserPrincipal(); - assertNotNull(user); - assertEquals("donald", user.getName()); - } - }) - .transform(constant("Bye World")); - - from("jetty://http://localhost:{{port}}/anotherTest?handlers=myAuthHandler") - .transform(constant("See you later")); - } - }; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java deleted file mode 100644 index 2aebd95..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java +++ /dev/null @@ -1,106 +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.io.IOException; -import java.security.Principal; -import java.util.Arrays; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.http.HttpOperationFailedException; -import org.apache.camel.impl.JndiRegistry; -import org.eclipse.jetty.security.ConstraintMapping; -import org.eclipse.jetty.security.ConstraintSecurityHandler; -import org.eclipse.jetty.security.HashLoginService; -import org.eclipse.jetty.security.SecurityHandler; -import org.eclipse.jetty.security.authentication.BasicAuthenticator; -import org.eclipse.jetty.util.security.Constraint; -import org.junit.Test; - -/** - * @version - */ -public class HttpBasicAuthTest extends BaseJettyTest { - - @Override - protected JndiRegistry createRegistry() throws Exception { - JndiRegistry jndi = super.createRegistry(); - jndi.bind("myAuthHandler", getSecurityHandler()); - return jndi; - } - - private SecurityHandler getSecurityHandler() throws IOException { - Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user"); - constraint.setAuthenticate(true); - - ConstraintMapping cm = new ConstraintMapping(); - cm.setPathSpec("/*"); - cm.setConstraint(constraint); - - ConstraintSecurityHandler sh = new ConstraintSecurityHandler(); - sh.setAuthenticator(new BasicAuthenticator()); - sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] {cm})); - - HashLoginService loginService = new HashLoginService("MyRealm", "src/test/resources/myRealm.properties"); - sh.setLoginService(loginService); - sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[]{cm})); - - return sh; - } - - @Test - public void testHttpBaiscAuth() throws Exception { - String out = template.requestBody("http://localhost:{{port}}/test?authMethod=Basic&authUsername=donald&authPassword=duck", "Hello World", String.class); - assertEquals("Bye World", out); - } - - @Test - public void testHttpBasicAuthInvalidPassword() throws Exception { - try { - template.requestBody("http://localhost:{{port}}/test?authMethod=Basic&authUsername=donald&authPassword=sorry", "Hello World", String.class); - fail("Should have thrown exception"); - } catch (RuntimeCamelException e) { - HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); - assertEquals(401, cause.getStatusCode()); - } - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test?handlers=myAuthHandler") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class); - assertNotNull(req); - Principal user = req.getUserPrincipal(); - assertNotNull(user); - assertEquals("donald", user.getName()); - } - }) - .transform(constant("Bye World")); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingPreservePostFormUrlEncodedBodyTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingPreservePostFormUrlEncodedBodyTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingPreservePostFormUrlEncodedBodyTest.java deleted file mode 100644 index 6fa6df0..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingPreservePostFormUrlEncodedBodyTest.java +++ /dev/null @@ -1,66 +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 org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.http.HttpMethods; -import org.junit.Test; - -public class HttpBindingPreservePostFormUrlEncodedBodyTest extends BaseJettyTest { - - @Test - public void testSendToJetty() throws Exception { - Exchange exchange = template.request("http://localhost:{{port}}/myapp/myservice?query1=a&query2=b", new Processor() { - - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody("b1=x&b2=y"); - exchange.getIn().setHeader("content-type", "application/x-www-form-urlencoded"); - exchange.getIn().setHeader(Exchange.HTTP_METHOD, HttpMethods.POST); - } - - }); - // convert the response to a String - String body = exchange.getOut().getBody(String.class); - assertEquals("Request message is OK", body); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - from("jetty:http://localhost:{{port}}/myapp/myservice").process(new Processor() { - public void process(Exchange exchange) throws Exception { - String body = exchange.getIn().getBody(String.class); - - // for unit testing make sure we got right message - assertEquals("The body message is wrong", "b1=x&b2=y", body); - assertEquals("Get a wrong query parameter from the message header", "a", exchange.getIn().getHeader("query1")); - assertEquals("Get a wrong query parameter from the message header", "b", exchange.getIn().getHeader("query2")); - assertEquals("Get a wrong form parameter from the message header", "x", exchange.getIn().getHeader("b1")); - assertEquals("Get a wrong form parameter from the message header", "y", exchange.getIn().getHeader("b2")); - - // send a response - exchange.getOut().setBody("Request message is OK"); - } - }); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingRefTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingRefTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingRefTest.java deleted file mode 100644 index 22aa8ea..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingRefTest.java +++ /dev/null @@ -1,93 +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.io.IOException; -import javax.servlet.http.HttpServletResponse; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.http.DefaultHttpBinding; -import org.apache.camel.component.http.HttpEndpoint; -import org.apache.camel.impl.JndiRegistry; -import org.junit.Test; - -/** - * Unit test for http binding ref option. - */ -public class HttpBindingRefTest extends BaseJettyTest { - - @Test - public void testDefaultHttpBinding() throws Exception { - Object out = template.requestBody("http://localhost:{{port}}/myapp/myservice", "Hello World"); - assertEquals("Bye World", context.getTypeConverter().convertTo(String.class, out)); - } - - @Test - public void testCustomHttpBinding() throws Exception { - Object out = template.requestBody("http://localhost:{{port}}/myapp/myotherservice", "Hello World"); - assertEquals("Something went wrong but we dont care", context.getTypeConverter().convertTo(String.class, out)); - } - - @Override - protected JndiRegistry createRegistry() throws Exception { - JndiRegistry jndi = super.createRegistry(); - HttpEndpoint ep = new HttpEndpoint(); - jndi.bind("default", new DefaultHttpBinding(ep)); - jndi.bind("myownbinder", new MyHttpBinding(ep)); - return jndi; - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - errorHandler(noErrorHandler()); - - from("jetty:http://localhost:{{port}}/myapp/myservice?httpBindingRef=default").transform().constant("Bye World"); - - from("jetty:http://localhost:{{port}}/myapp/myotherservice?httpBindingRef=myownbinder").process(new Processor() { - public void process(Exchange exchange) throws Exception { - throw new IllegalStateException("Not implemented"); - } - }); - } - }; - } - - // START SNIPPET: e1 - public class MyHttpBinding extends DefaultHttpBinding { - public MyHttpBinding(HttpEndpoint ep) { - super(ep); - } - @Override - public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException { - // we override the doWriteExceptionResponse as we only want to alter the binding how exceptions is - // written back to the client. - - // we just return HTTP 200 so the client thinks its okay - response.setStatus(200); - // and we return this fixed text - response.getWriter().write("Something went wrong but we dont care"); - } - } - // END SNIPPET: e1 - -} - http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeEncodedPathTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeEncodedPathTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeEncodedPathTest.java deleted file mode 100644 index d1e3410..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeEncodedPathTest.java +++ /dev/null @@ -1,65 +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.io.ByteArrayInputStream; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -public class HttpBridgeEncodedPathTest extends BaseJettyTest { - - private int port1; - private int port2; - - @Test - public void testHttpClient() throws Exception { - String response = template.requestBodyAndHeader("http://localhost:" + port2 + "/test/hello?param1=%2B447777111222", - new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "text/plain", String.class); - assertEquals("Get a wrong response", "param1=+447777111222", response); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - port1 = getPort(); - port2 = getNextPort(); - - errorHandler(noErrorHandler()); - - Processor serviceProc = new Processor() { - public void process(Exchange exchange) throws Exception { - // %2B becomes decoded to a space - assertEquals(" 447777111222", exchange.getIn().getHeader("param1")); - // and in the http query %20 becomes a + sign - assertEquals("param1=+447777111222", exchange.getIn().getHeader(Exchange.HTTP_QUERY)); - - // send back the query - exchange.getOut().setBody(exchange.getIn().getHeader(Exchange.HTTP_QUERY)); - } - }; - from("jetty:http://localhost:" + port2 + "/test/hello") - .to("http://localhost:" + port1 + "?throwExceptionOnFailure=false&bridgeEndpoint=true"); - - from("jetty://http://localhost:" + port1 + "?matchOnUriPrefix=true").process(serviceProc); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java deleted file mode 100644 index d5a289d..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeMultipartRouteTest.java +++ /dev/null @@ -1,99 +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.io.File; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.http.HttpEndpoint; -import org.apache.camel.impl.DefaultHeaderFilterStrategy; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.multipart.FilePart; -import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity; -import org.apache.commons.httpclient.methods.multipart.Part; -import org.apache.commons.httpclient.methods.multipart.StringPart; -import org.junit.Test; - -public class HttpBridgeMultipartRouteTest extends BaseJettyTest { - - private int port1; - private int port2; - - private static class MultipartHeaderFilterStrategy extends DefaultHeaderFilterStrategy { - public MultipartHeaderFilterStrategy() { - initialize(); - } - - protected void initialize() { - setLowerCase(true); - setOutFilterPattern("(?i)(Camel|org\\.apache\\.camel)[\\.|a-z|A-z|0-9]*"); - } - } - - @Test - public void testHttpClient() throws Exception { - File jpg = new File("src/test/resources/java.jpg"); - String body = "TEST"; - Part[] parts = new Part[] {new StringPart("body", body), new FilePart(jpg.getName(), jpg)}; - - PostMethod method = new PostMethod("http://localhost:" + port2 + "/test/hello"); - MultipartRequestEntity requestEntity = new MultipartRequestEntity(parts, method.getParams()); - method.setRequestEntity(requestEntity); - - HttpClient client = new HttpClient(); - client.executeMethod(method); - - String responseBody = method.getResponseBodyAsString(); - assertEquals(body, responseBody); - - String numAttachments = method.getResponseHeader("numAttachments").getValue(); - assertEquals(numAttachments, "1"); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - port1 = getPort(); - port2 = getNextPort(); - - errorHandler(noErrorHandler()); - - Processor serviceProc = new Processor() { - public void process(Exchange exchange) throws Exception { - Message in = exchange.getIn(); - // put the number of attachments in a response header - exchange.getOut().setHeader("numAttachments", in.getAttachments().size()); - exchange.getOut().setBody(in.getHeader("body")); - } - }; - - HttpEndpoint epOut = getContext().getEndpoint("http://localhost:" + port1 + "?bridgeEndpoint=true&throwExceptionOnFailure=false", HttpEndpoint.class); - epOut.setHeaderFilterStrategy(new MultipartHeaderFilterStrategy()); - - from("jetty:http://localhost:" + port2 + "/test/hello?enableMultipartFilter=false") - .to(epOut); - - from("jetty://http://localhost:" + port1 + "?matchOnUriPrefix=true").process(serviceProc); - } - }; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeRouteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeRouteTest.java deleted file mode 100644 index 5303e6a..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBridgeRouteTest.java +++ /dev/null @@ -1,72 +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.io.ByteArrayInputStream; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -public class HttpBridgeRouteTest extends BaseJettyTest { - - private int port1; - private int port2; - - @Test - public void testHttpClient() throws Exception { - String response = template.requestBodyAndHeader("http://localhost:" + port2 + "/test/hello", - new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "application/xml", String.class); - assertEquals("Get a wrong response", "/", response); - - response = template.requestBody("http://localhost:" + port1 + "/hello/world", "hello", String.class); - assertEquals("Get a wrong response", "/hello/world", response); - - try { - template.requestBody("http://localhost:" + port2 + "/hello/world", "hello", String.class); - fail("Expect exception here!"); - } catch (Exception ex) { - assertTrue("We should get a RuntimeCamelException", ex instanceof RuntimeCamelException); - } - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - port1 = getPort(); - port2 = getNextPort(); - - errorHandler(noErrorHandler()); - - Processor serviceProc = new Processor() { - public void process(Exchange exchange) throws Exception { - // get the request URL and copy it to the request body - String uri = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class); - exchange.getOut().setBody(uri); - } - }; - from("jetty:http://localhost:" + port2 + "/test/hello") - .to("http://localhost:" + port1 + "?throwExceptionOnFailure=false&bridgeEndpoint=true"); - - from("jetty://http://localhost:" + port1 + "?matchOnUriPrefix=true").process(serviceProc); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpCharacterEncodingTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpCharacterEncodingTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpCharacterEncodingTest.java deleted file mode 100644 index f27d4ec..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpCharacterEncodingTest.java +++ /dev/null @@ -1,64 +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 org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -public class HttpCharacterEncodingTest extends BaseJettyTest { - - @Test - public void testSendToJetty() throws Exception { - Exchange exchange = template.send("http://localhost:{{port}}/myapp/myservice", new Processor() { - - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody("Hello World Thai Elephant \u0E08"); - exchange.getIn().setHeader("Content-Type", "text/html; charset=utf-8"); - } - - }); - // convert the response to a String - String body = exchange.getOut().getBody(String.class); - assertEquals("Response message is Thai Elephant \u0E08", body); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - from("jetty:http://localhost:{{port}}/myapp/myservice").process(new MyBookService()); - } - }; - } - - public class MyBookService implements Processor { - public void process(Exchange exchange) throws Exception { - // just get the body as a string - String body = exchange.getIn().getBody(String.class); - - // for unit testing make sure we got right message - assertEquals("Hello World Thai Elephant \u0E08", body); - - // send a html response - exchange.getOut().setHeader("Content-Type", "text/html; charset=utf-8"); - exchange.getOut().setBody("Response message is Thai Elephant \u0E08"); - } - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteEnableChunkedTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteEnableChunkedTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteEnableChunkedTest.java deleted file mode 100644 index 7d8ba72..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteEnableChunkedTest.java +++ /dev/null @@ -1,84 +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.io.ByteArrayInputStream; -import java.util.List; -import java.util.Map; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.Test; - -public class HttpClientRouteEnableChunkedTest extends BaseJettyTest { - - @Test - public void testHttpRouteWithOption() throws Exception { - testHttpClient("direct:start2"); - } - - private void testHttpClient(String uri) throws Exception { - System.getProperties().put("HTTPClient.dontChunkRequests", "yes"); - - MockEndpoint mockEndpoint = getMockEndpoint("mock:a"); - mockEndpoint.expectedBodiesReceived("<b>Hello World</b>"); - - template.requestBodyAndHeader(uri, new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "application/xml"); - - mockEndpoint.assertIsSatisfied(); - List<Exchange> list = mockEndpoint.getReceivedExchanges(); - Exchange exchange = list.get(0); - assertNotNull("exchange", exchange); - - Message in = exchange.getIn(); - assertNotNull("in", in); - - Map<String, Object> headers = in.getHeaders(); - - log.info("Headers: " + headers); - - assertTrue("Should be more than one header but was: " + headers, headers.size() > 0); - - // should get the Content-Length - assertEquals("Should get the transfer-encoding as chunked", "chunked", headers.get("Transfer-Encoding")); - // remove the system property - System.getProperties().remove("HTTPClient.dontChunkRequests"); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - errorHandler(noErrorHandler()); - - from("direct:start2").to("http://localhost:{{port}}/hello").to("mock:a"); - - Processor proc = new Processor() { - public void process(Exchange exchange) throws Exception { - ByteArrayInputStream bis = new ByteArrayInputStream("<b>Hello World</b>".getBytes()); - exchange.getOut().setBody(bis); - } - }; - - from("jetty:http://localhost:{{port}}/hello").process(proc); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java deleted file mode 100644 index 848cc70..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpClientRouteTest.java +++ /dev/null @@ -1,147 +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.io.ByteArrayInputStream; -import java.io.InputStream; -import java.util.List; -import java.util.Map; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.Test; - -public class HttpClientRouteTest extends BaseJettyTest { - - private int port1; - private int port2; - - @Test - public void testHttpRouteWithMessageHeader() throws Exception { - testHttpClient("direct:start"); - } - - @Test - public void testHttpRouteWithOption() throws Exception { - testHttpClient("direct:start2"); - } - - private void testHttpClient(String uri) throws Exception { - System.getProperties().put("HTTPClient.dontChunkRequests", "yes"); - - MockEndpoint mockEndpoint = getMockEndpoint("mock:a"); - mockEndpoint.expectedBodiesReceived("<b>Hello World</b>"); - - template.requestBodyAndHeader(uri, new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "application/xml"); - - mockEndpoint.assertIsSatisfied(); - List<Exchange> list = mockEndpoint.getReceivedExchanges(); - Exchange exchange = list.get(0); - assertNotNull("exchange", exchange); - - Message in = exchange.getIn(); - assertNotNull("in", in); - - Map<String, Object> headers = in.getHeaders(); - - log.info("Headers: " + headers); - - assertTrue("Should be more than one header but was: " + headers, headers.size() > 0); - } - - @Test - public void testHttpRouteWithQuery() throws Exception { - MockEndpoint mockEndpoint = getMockEndpoint("mock:a"); - mockEndpoint.expectedBodiesReceived("@ query"); - - template.sendBody("direct:start3", null); - mockEndpoint.assertIsSatisfied(); - } - - @Test - public void testHttpRouteWithQueryByHeader() throws Exception { - MockEndpoint mockEndpoint = getMockEndpoint("mock:a"); - mockEndpoint.expectedBodiesReceived("test"); - - template.sendBody("direct:start4", "test"); - mockEndpoint.assertIsSatisfied(); - } - - @Test - public void testHttpRouteWithHttpURI() throws Exception { - Exchange exchange = template.send("http://localhost:" + port2 + "/querystring", new Processor() { - @Override - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody(""); - exchange.getIn().setHeader(Exchange.HTTP_URI, "http://localhost:" + port2 + "/querystring?id=test"); - } - }); - assertEquals("Get a wrong response.", "test", exchange.getOut().getBody(String.class)); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - port1 = getPort(); - port2 = getNextPort(); - - errorHandler(noErrorHandler()); - - Processor clientProc = new Processor() { - public void process(Exchange exchange) throws Exception { - assertIsInstanceOf(InputStream.class, exchange.getIn().getBody()); - } - }; - - from("direct:start").to("http://localhost:" + port1 + "/hello").process(clientProc).convertBodyTo(String.class).to("mock:a"); - from("direct:start2").to("http://localhost:" + port2 + "/hello").to("mock:a"); - from("direct:start3").to("http://localhost:" + port2 + "/Query%20/test?myQuery=%40%20query").to("mock:a"); - from("direct:start4").setHeader(Exchange.HTTP_QUERY, simple("id=${body}")).to("http://localhost:" + port2 + "/querystring").to("mock:a"); - - Processor proc = new Processor() { - public void process(Exchange exchange) throws Exception { - ByteArrayInputStream bis = new ByteArrayInputStream("<b>Hello World</b>".getBytes()); - exchange.getOut().setBody(bis); - } - }; - from("jetty:http://localhost:" + port1 + "/hello").process(proc).setHeader(Exchange.HTTP_CHUNKED).constant(false); - - from("jetty:http://localhost:" + port2 + "/hello?chunked=false").process(proc); - - from("jetty:http://localhost:" + port2 + "/Query%20/test").process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setBody(exchange.getIn().getHeader("myQuery", String.class)); - } - }); - - from("jetty:http://localhost:" + port2 + "/querystring").process(new Processor() { - public void process(Exchange exchange) throws Exception { - String result = exchange.getIn().getHeader("id", String.class); - if (result == null) { - result = "No id header"; - } - exchange.getOut().setBody(result); - } - }); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpConverterTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpConverterTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpConverterTest.java deleted file mode 100644 index eef0641..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpConverterTest.java +++ /dev/null @@ -1,131 +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.io.InputStream; -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.http.HttpConverter; -import org.apache.camel.component.http.HttpMessage; -import org.junit.Test; - -/** - * @version - */ -public class HttpConverterTest extends BaseJettyTest { - - @Override - public boolean isUseRouteBuilder() { - return false; - } - - @Test - public void testToServletRequestAndResponse() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test") - // add this node to make sure the convert can work within DefaultMessageImpl - .convertBodyTo(String.class) - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - HttpServletRequest request = exchange.getIn(HttpServletRequest.class); - assertNotNull("We should get request object here", request); - HttpServletResponse response = exchange.getIn(HttpServletResponse.class); - assertNotNull("We should get response object here", response); - String s = exchange.getIn().getBody(String.class); - assertEquals("Hello World", s); - } - }).transform(constant("Bye World")); - } - }); - context.start(); - - String out = template.requestBody("http://localhost:{{port}}/test", "Hello World", String.class); - assertEquals("Bye World", out); - } - - @Test - public void testToServletInputStream() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test"). - process(new Processor() { - public void process(Exchange exchange) throws Exception { - HttpMessage msg = exchange.getIn(HttpMessage.class); - - ServletInputStream sis = HttpConverter.toServletInputStream(msg); - assertNotNull(sis); - // The ServletInputStream should be cached and you can't read message here - assertTrue(sis.available() == 0); - String s = msg.getBody(String.class); - - assertEquals("Hello World", s); - } - }).transform(constant("Bye World")); - } - }); - context.start(); - - String out = template.requestBody("http://localhost:{{port}}/test", "Hello World", String.class); - assertEquals("Bye World", out); - } - - @Test - public void testToInputStream() throws Exception { - context.addRoutes(new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test"). - process(new Processor() { - public void process(Exchange exchange) throws Exception { - HttpMessage msg = exchange.getIn(HttpMessage.class); - - InputStream sis = msg.getBody(InputStream.class); - assertNotNull(sis); - String s = exchange.getContext().getTypeConverter().convertTo(String.class, sis); - - assertEquals("Hello World", s); - } - }).transform(constant("Bye World")); - } - }); - context.start(); - - String out = template.requestBody("http://localhost:{{port}}/test", "Hello World", String.class); - assertEquals("Bye World", out); - } - - @Test - public void testNulls() throws Exception { - HttpMessage msg = null; - assertNull(HttpConverter.toInputStream(msg, null)); - assertNull(HttpConverter.toServletInputStream(msg)); - assertNull(HttpConverter.toServletRequest(msg)); - assertNull(HttpConverter.toServletResponse(msg)); - - HttpServletRequest req = null; - assertNull(HttpConverter.toInputStream(req, null)); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpEndpointURLTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpEndpointURLTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpEndpointURLTest.java deleted file mode 100644 index 5bbde5c..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpEndpointURLTest.java +++ /dev/null @@ -1,30 +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 org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; - -public class HttpEndpointURLTest extends CamelTestSupport { - - @Test - public void testHttpEndpointURLWithIPv6() { - JettyHttpEndpoint endpoint = (JettyHttpEndpoint)context.getEndpoint("jetty://http://[2a00:8a00:6000:40::1413]:30300/test?test=true"); - assertEquals("http://[2a00:8a00:6000:40::1413]:30300/test?test=true", endpoint.getHttpUri().toString()); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpEndpointUriEncodingIssueTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpEndpointUriEncodingIssueTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpEndpointUriEncodingIssueTest.java deleted file mode 100644 index f15e080..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpEndpointUriEncodingIssueTest.java +++ /dev/null @@ -1,68 +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 org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -/** - * - */ -public class HttpEndpointUriEncodingIssueTest extends BaseJettyTest { - - @Test - public void testEndpointUriEncodingIssue() throws Exception { - String uri = "http://localhost:{{port}}/myapp/mytest?columns=totalsens,upsens&username=apiuser"; - String out = template.requestBody(uri, null, String.class); - - assertEquals("We got totalsens,upsens columns", out); - } - - @Test - public void testEndpointUriWithDanishCharEncodingIssue() throws Exception { - String uri = "http://localhost:{{port}}/myapp/mytest?columns=claus,s\u00F8ren&username=apiuser"; - String out = template.requestBody(uri, null, String.class); - - assertEquals("We got claus,s\u00F8ren columns", out); - } - - @Test - public void testEndpointHeaderUriEncodingIssue() throws Exception { - String uri = "http://localhost:{{port}}/myapp/mytest?columns=totalsens,upsens&username=apiuser"; - String out = template.requestBodyAndHeader("http://localhost/dummy", null, Exchange.HTTP_URI, uri, String.class); - - assertEquals("We got totalsens,upsens columns", out); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty:http://localhost:{{port}}/myapp/mytest").process(new Processor() { - public void process(Exchange exchange) throws Exception { - String columns = exchange.getIn().getHeader("columns", String.class); - exchange.getOut().setBody("We got " + columns + " columns"); - } - }); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpFilterCamelHeadersTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpFilterCamelHeadersTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpFilterCamelHeadersTest.java deleted file mode 100644 index 4527062..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpFilterCamelHeadersTest.java +++ /dev/null @@ -1,79 +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.Map; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.impl.JndiRegistry; -import org.junit.Test; - -/** - * @version - */ -public class HttpFilterCamelHeadersTest extends BaseJettyTest { - - @Test - public void testFilterCamelHeaders() throws Exception { - Exchange out = template.send("http://localhost:{{port}}/test/filter", new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody("Claus"); - exchange.getIn().setHeader("bar", 123); - } - }); - - assertNotNull(out); - assertEquals("Hi Claus", out.getOut().getBody(String.class)); - - // there should be no internal Camel headers - // except for the response code - Map<String, Object> headers = out.getOut().getHeaders(); - for (String key : headers.keySet()) { - if (!key.equalsIgnoreCase(Exchange.HTTP_RESPONSE_CODE)) { - assertTrue("Should not contain any Camel internal headers", !key.toLowerCase().startsWith("camel")); - } else { - assertEquals(200, headers.get(Exchange.HTTP_RESPONSE_CODE)); - } - } - } - - @Override - protected JndiRegistry createRegistry() throws Exception { - JndiRegistry jndi = super.createRegistry(); - jndi.bind("foo", new MyFooBean()); - return jndi; - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty:http://localhost:{{port}}/test/filter").beanRef("foo"); - } - }; - } - - public static class MyFooBean { - - public String hello(String name) { - return "Hi " + name; - } - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGZipEncodingTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGZipEncodingTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGZipEncodingTest.java deleted file mode 100644 index 28efbfc..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGZipEncodingTest.java +++ /dev/null @@ -1,100 +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.io.ByteArrayInputStream; -import javax.servlet.http.HttpServletRequest; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.ExpressionBuilder; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -public class HttpGZipEncodingTest extends BaseJettyTest { - - private int port1; - private int port2; - - @Test - public void testHttpProducerWithGzip() throws Exception { - String response = template.requestBodyAndHeader("http://localhost:" + port1 + "/gzip", - new ByteArrayInputStream("<Hello>World</Hello>".getBytes()), Exchange.CONTENT_ENCODING, "gzip", String.class); - assertEquals("The response is wrong", "<b>Hello World</b>", response); - } - - @Test - public void testGzipProxy() throws Exception { - String response = - template.requestBodyAndHeader("http://localhost:" + port2 + "/route", - new ByteArrayInputStream("<Hello>World</Hello>".getBytes()), Exchange.CONTENT_ENCODING, "gzip", String.class); - assertEquals("The response is wrong", "<b>Hello World</b>", response); - } - - @Test - public void testGzipProducerWithGzipData() throws Exception { - String response = template.requestBodyAndHeader("direct:gzip", - new ByteArrayInputStream("<Hello>World</Hello>".getBytes()), Exchange.CONTENT_ENCODING, "gzip", String.class); - assertEquals("The response is wrong", "<b>Hello World</b>", response); - } - - @Test - public void testGzipGet() throws Exception { - String response = template.requestBodyAndHeader("http://localhost:" + port1 + "/gzip", - null, "Accept-Encoding", "gzip", String.class); - assertEquals("The response is wrong", "<b>Hello World for gzip</b>", response); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - port1 = getPort(); - port2 = getNextPort(); - - errorHandler(noErrorHandler()); - - from("direct:gzip") - .marshal().gzip() - .setProperty(Exchange.SKIP_GZIP_ENCODING, ExpressionBuilder.constantExpression(Boolean.TRUE)) - .to("http://localhost:" + port1 + "/gzip").unmarshal().gzip(); - - from("jetty:http://localhost:" + port1 + "/gzip").process(new Processor() { - public void process(Exchange exchange) throws Exception { - // check the request method - HttpServletRequest request = exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST, HttpServletRequest.class); - if ("POST".equals(request.getMethod())) { - String requestBody = exchange.getIn().getBody(String.class); - assertEquals("Get a wrong request string", "<Hello>World</Hello>", requestBody); - } - exchange.getOut().setHeader(Exchange.CONTENT_ENCODING, "gzip"); - // check the Accept Encoding header - String header = exchange.getIn().getHeader("Accept-Encoding", String.class); - if (header != null && header.indexOf("gzip") > -1) { - exchange.getOut().setBody("<b>Hello World for gzip</b>"); - } else { - exchange.getOut().setBody("<b>Hello World</b>"); - } - } - }); - - from("jetty:http://localhost:" + port2 + "/route?bridgeEndpoint=true") - .to("http://localhost:" + port1 + "/gzip?bridgeEndpoint=true"); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderCaseTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderCaseTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderCaseTest.java deleted file mode 100644 index 03e8829..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderCaseTest.java +++ /dev/null @@ -1,73 +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.LinkedHashMap; -import java.util.Map; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.HttpMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.junit.Test; - -public class HttpHeaderCaseTest extends BaseJettyTest { - - @Test - public void testHttpHeaderCase() throws Exception { - HttpClient client = new HttpClient(); - HttpMethod method = new PostMethod("http://localhost:" + getPort() + "/myapp/mytest"); - - method.setRequestHeader("clientHeader", "fooBAR"); - method.setRequestHeader("OTHER", "123"); - method.setRequestHeader("beer", "Carlsberg"); - - client.executeMethod(method); - - assertEquals("Bye World", method.getResponseBodyAsString()); - assertEquals("aBc123", method.getResponseHeader("MyCaseHeader").getValue()); - assertEquals("456DEf", method.getResponseHeader("otherCaseHeader").getValue()); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - from("jetty:http://localhost:{{port}}/myapp/mytest").process(new Processor() { - public void process(Exchange exchange) throws Exception { - - // headers received should be in case as well - Map<String, Object> map = new LinkedHashMap<String, Object>(); - map.putAll(exchange.getIn().getHeaders()); - - assertEquals("123", map.get("OTHER")); - assertEquals(null, map.get("other")); - assertEquals("Carlsberg", map.get("beer")); - assertEquals(null, map.get("Beer")); - - exchange.getOut().setBody("Bye World"); - exchange.getOut().setHeader("MyCaseHeader", "aBc123"); - exchange.getOut().setHeader("otherCaseHeader", "456DEf"); - } - }); - } - }; - } - -}