http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java deleted file mode 100644 index c3deb50..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpHeaderTest.java +++ /dev/null @@ -1,95 +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 java.util.Map.Entry; -import javax.servlet.ServletRequest; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -public class HttpHeaderTest extends BaseJettyTest { - - @Test - public void testHttpHeaders() throws Exception { - String result = template.requestBody("direct:start", "hello", String.class); - assertEquals("Should send a right http header to the server.", "Find the key!", result); - } - - @Test - public void testServerHeader() throws Exception { - Exchange ex = template.request("http://localhost:{{port}}/server/mytest", new Processor() { - @Override - public void process(Exchange exchange) throws Exception { - // Do nothing here - } - }); - - assertNotNull(ex.getOut().getHeader("Server")); - assertNull(ex.getOut().getHeader("Date")); - - ex = template.request("http://localhost:{{port2}}/server/mytest", new Processor() { - @Override - public void process(Exchange exchange) throws Exception { - // Do nothing here - } - }); - - assertNull(ex.getOut().getHeader("Server")); - assertNotNull(ex.getOut().getHeader("Date")); - } - - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - from("direct:start").setHeader("SOAPAction", constant("http://xxx.com/interfaces/ticket")) - .setHeader("Content-Type", constant("text/xml; charset=utf-8")) - .setHeader(Exchange.HTTP_PROTOCOL_VERSION, constant("HTTP/1.0")) - .to("http://localhost:{{port}}/myapp/mytest"); - - from("jetty:http://localhost:{{port}}/myapp/mytest").process(new Processor() { - public void process(Exchange exchange) throws Exception { - Map<String, Object> headers = exchange.getIn().getHeaders(); - ServletRequest request = exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST, ServletRequest.class); - assertNotNull(request); - assertEquals("Get a wong http protocol version", request.getProtocol(), "HTTP/1.0"); - for (Entry<String, Object> entry : headers.entrySet()) { - if ("SOAPAction".equals(entry.getKey()) && "http://xxx.com/interfaces/ticket".equals(entry.getValue())) { - exchange.getOut().setBody("Find the key!"); - return; - } - } - exchange.getOut().setBody("Cannot find the key!"); - } - }); - - from("jetty:http://localhost:{{port}}/server/mytest").transform(constant("Response!")); - - //The setting only effect on a new server endpoint - from("jetty:http://localhost:{{port2}}/server/mytest?sendServerVersion=false&sendDateHeader=true").transform(constant("Response!")); - - - } - }; - } - -}
http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpMethodRestrictTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpMethodRestrictTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpMethodRestrictTest.java deleted file mode 100644 index 8ff3990..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpMethodRestrictTest.java +++ /dev/null @@ -1,74 +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.Message; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.junit.Test; - -public class HttpMethodRestrictTest extends BaseJettyTest { - - private String getUrl() { - return "http://localhost:" + getPort() + "/methodRestrict"; - } - - @Test - public void testProperHttpMethod() throws Exception { - HttpClient httpClient = new HttpClient(); - PostMethod httpPost = new PostMethod(getUrl()); - - StringRequestEntity reqEntity = new StringRequestEntity("This is a test", null, null); - httpPost.setRequestEntity(reqEntity); - - int status = httpClient.executeMethod(httpPost); - - assertEquals("Get a wrong response status", 200, status); - - String result = httpPost.getResponseBodyAsString(); - assertEquals("Get a wrong result", "This is a test response", result); - } - - @Test - public void testImproperHttpMethod() throws Exception { - HttpClient httpClient = new HttpClient(); - GetMethod httpGet = new GetMethod(getUrl()); - int status = httpClient.executeMethod(httpGet); - - assertEquals("Get a wrong response status", 405, status); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - - from("jetty://http://localhost:{{port}}/methodRestrict?httpMethodRestrict=POST").process(new Processor() { - public void process(Exchange exchange) throws Exception { - Message in = exchange.getIn(); - String request = in.getBody(String.class); - exchange.getOut().setBody(request + " response"); - } - }); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpOperationsFailedExceptionUriTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpOperationsFailedExceptionUriTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpOperationsFailedExceptionUriTest.java deleted file mode 100644 index cc48438..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpOperationsFailedExceptionUriTest.java +++ /dev/null @@ -1,57 +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.RuntimeCamelException; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.http.HttpOperationFailedException; -import org.junit.Test; - -/** - * @version - */ -public class HttpOperationsFailedExceptionUriTest extends BaseJettyTest { - - @Test - public void testHttpOperationsFailedExceptionUri() throws Exception { - try { - template.requestBodyAndHeader("http://localhost:{{port}}/foo?bar=123", null, "foo", 123); - fail("Should have thrown an exception"); - } catch (RuntimeCamelException e) { - HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); - assertEquals(500, cause.getStatusCode()); - assertEquals("http://localhost:" + getPort() + "/foo?bar=123", cause.getUri()); - } - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/foo") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 500); - } - }); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingConsumerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingConsumerTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingConsumerTest.java deleted file mode 100644 index 41f1c59..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingConsumerTest.java +++ /dev/null @@ -1,63 +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.net.SocketTimeoutException; - -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -/** - * @version - */ -public class HttpPollingConsumerTest extends BaseJettyTest { - - @Test - public void testReceive() throws Exception { - String body = consumer.receiveBody("http://localhost:{{port}}/test", String.class); - assertEquals("Bye World", body); - } - - @Test - public void testReceiveTimeout() throws Exception { - String body = consumer.receiveBody("http://localhost:{{port}}/test", 5000, String.class); - assertEquals("Bye World", body); - } - - @Test - public void testReceiveTimeoutTriggered() throws Exception { - try { - consumer.receiveBody("http://localhost:{{port}}/test", 250, String.class); - fail("Should have thrown an exception"); - } catch (RuntimeCamelException e) { - assertIsInstanceOf(SocketTimeoutException.class, e.getCause()); - } - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test") - .delay(2000).transform(constant("Bye World")); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingGetTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingGetTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingGetTest.java deleted file mode 100644 index 9e3a3cf..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpPollingGetTest.java +++ /dev/null @@ -1,76 +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.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; - -/** - * @version - */ -public class HttpPollingGetTest extends BaseJettyTest { - - protected String expectedText = "<html"; - - @Test - public void testHttpPollingGet() throws Exception { - MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class); - mockEndpoint.expectedMinimumMessageCount(1); - - 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.debug("Headers: " + headers); - assertTrue("Should be more than one header but was: " + headers, headers.size() > 0); - - String body = in.getBody(String.class); - - log.debug("Body: " + body); - assertNotNull("Should have a body!", body); - assertTrue("body should contain: " + expectedText, body.contains(expectedText)); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - from("http://localhost:{{port}}/myservice?delay=5000").to("mock:results"); - - from("jetty:http://localhost:{{port}}/myservice").process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setBody("<html>Bye World</html>"); - } - }); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerByteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerByteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerByteTest.java deleted file mode 100644 index a03986d..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerByteTest.java +++ /dev/null @@ -1,44 +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.builder.RouteBuilder; -import org.junit.Test; - -/** - * @version - */ -public class HttpProducerByteTest extends BaseJettyTest { - - @Test - public void testHttpProducerByteTest() throws Exception { - byte[] data = "Hello World".getBytes(); - String out = template.requestBody("http://localhost:{{port}}/test", data, String.class); - assertEquals("Bye World", out); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test").transform(constant("Bye World")); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerConcurrentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerConcurrentTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerConcurrentTest.java deleted file mode 100644 index a9361eb..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerConcurrentTest.java +++ /dev/null @@ -1,92 +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.HashSet; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -/** - * HTTP producer concurrent test. - * - * @version - */ -public class HttpProducerConcurrentTest extends BaseJettyTest { - - @Test - public void testNoConcurrentProducers() throws Exception { - doSendMessages(1, 1); - } - - @Test - public void testConcurrentProducers() throws Exception { - doSendMessages(10, 5); - } - - private void doSendMessages(int files, int poolSize) throws Exception { - getMockEndpoint("mock:result").expectedMessageCount(files); - getMockEndpoint("mock:result").assertNoDuplicates(body()); - - ExecutorService executor = Executors.newFixedThreadPool(poolSize); - // we access the responses Map below only inside the main thread, - // so no need for a thread-safe Map implementation - Map<Integer, Future<String>> responses = new HashMap<Integer, Future<String>>(); - for (int i = 0; i < files; i++) { - final int index = i; - Future<String> out = executor.submit(new Callable<String>() { - public String call() throws Exception { - return template.requestBody("http://localhost:{{port}}/echo", "" + index, String.class); - } - }); - responses.put(index, out); - } - - assertMockEndpointsSatisfied(); - - assertEquals(files, responses.size()); - - // get all responses - Set<String> unique = new HashSet<String>(); - for (Future<String> future : responses.values()) { - unique.add(future.get()); - } - - // should be 'files' unique responses - assertEquals("Should be " + files + " unique responses", files, unique.size()); - executor.shutdownNow(); - } - - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - // expose a echo service - from("jetty:http://localhost:{{port}}/echo") - .transform(body().append(body())).to("mock:result"); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java deleted file mode 100644 index 15a71a2..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerJMXBeansIssueTest.java +++ /dev/null @@ -1,80 +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.Endpoint; -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.Producer; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @version - */ -public class HttpProducerJMXBeansIssueTest extends BaseJettyTest { - - private static final Logger LOG = LoggerFactory.getLogger(HttpProducerJMXBeansIssueTest.class); - - @Override - public void setUp() throws Exception { - // to enable the JMX connector - enableJMX(); - System.setProperty("org.apache.camel.jmx.createRmiConnector", "True"); - super.setUp(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty:http://localhost:{{port}}/leak").transform(constant("Bye World")); - - from("direct:leak").process(new Processor() { - public void process(Exchange exchange) throws Exception { - LOG.debug("URL is: " + exchange.getIn().getHeader("url")); - } - }).recipientList(header("url")); - } - }; - } - - @Test - public void testNothing() { - // do nothing as this test is manual - } - - // @Test - // TODO: disabled as this is a manual test - public void testSendAlot() throws Exception { - Endpoint ep = context.getEndpoint("direct:leak"); - Producer p = ep.createProducer(); - p.start(); - - for (int i = 0; i < 10000; i++) { - Exchange ex = ep.createExchange(); - ex.getIn().setHeader("url", "http://localhost:{{port}}/leak?id=" + i); - p.process(ex); - } - - p.stop(); - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerQueryParamTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerQueryParamTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerQueryParamTest.java deleted file mode 100644 index b98a554..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerQueryParamTest.java +++ /dev/null @@ -1,78 +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.junit.Test; - -/** - * @version - */ -public class HttpProducerQueryParamTest extends BaseJettyTest { - - private String url = "http://0.0.0.0:" + getPort() + "/cheese"; - - @Test - public void testQueryParameters() throws Exception { - Exchange exchange = template.request(url + "?quote=Camel%20rocks", null); - assertNotNull(exchange); - - String body = exchange.getOut().getBody(String.class); - Map<?, ?> headers = exchange.getOut().getHeaders(); - - assertEquals("Bye World", body); - assertEquals("Carlsberg", headers.get("beer")); - } - - @Test - public void testQueryParametersWithHeader() throws Exception { - Exchange exchange = template.request(url, new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getIn().setHeader(Exchange.HTTP_QUERY, "quote=Camel rocks"); - } - }); - assertNotNull(exchange); - - String body = exchange.getOut().getBody(String.class); - Map<?, ?> headers = exchange.getOut().getHeaders(); - - assertEquals("Bye World", body); - assertEquals("Carlsberg", headers.get("beer")); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty:" + url).process(new Processor() { - public void process(Exchange exchange) throws Exception { - String quote = exchange.getIn().getHeader("quote", String.class); - assertEquals("Camel rocks", quote); - - exchange.getOut().setBody("Bye World"); - exchange.getOut().setHeader("beer", "Carlsberg"); - } - }); - } - }; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerSOTimeoutTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerSOTimeoutTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerSOTimeoutTest.java deleted file mode 100644 index bf39a54..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerSOTimeoutTest.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.net.SocketTimeoutException; - -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.Test; - -/** - * Unit test for using http client SO timeout - * - * @version - */ -public class HttpProducerSOTimeoutTest extends BaseJettyTest { - - @Test - public void testSendWithSOTimeoutNoTimeout() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMessageCount(1); - - String out = template.requestBody("http://localhost:{{port}}/myservice?httpClient.soTimeout=5000", null, String.class); - assertEquals("Bye World", out); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testSendWithSOTimeoutTimeout() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMessageCount(1); - - try { - // we use a timeout of 1 second - template.requestBody("http://localhost:{{port}}/myservice?httpClient.soTimeout=1000", null, String.class); - fail("Should throw an exception"); - } catch (RuntimeCamelException e) { - assertIsInstanceOf(SocketTimeoutException.class, e.getCause()); - } - - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/myservice") - // but we wait for 2 sec before reply is sent back - .delay(2000) - .transform().constant("Bye World").to("mock:result"); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerSendEmptyHeaderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerSendEmptyHeaderTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerSendEmptyHeaderTest.java deleted file mode 100644 index 10b795c..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerSendEmptyHeaderTest.java +++ /dev/null @@ -1,54 +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.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.Test; - -/** - * - */ -public class HttpProducerSendEmptyHeaderTest extends BaseJettyTest { - - @Test - public void testHttpProducerSendEmptyHeader() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMessageCount(1); - - // Jetty 8 treats an empty header as "" while Jetty 9 treats it as null - String expectedValue = isJetty8() ? "" : null; - mock.expectedHeaderReceived("foo", expectedValue); - - template.sendBodyAndHeader("http://localhost:{{port}}/myapp/mytest", "Hello World", "foo", ""); - - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - allowNullHeaders(); - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty:http://localhost:{{port}}/myapp/mytest") - .convertBodyTo(String.class) - .to("mock:result"); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerTwoParametersWithSameKeyTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerTwoParametersWithSameKeyTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerTwoParametersWithSameKeyTest.java deleted file mode 100644 index 0b03809..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProducerTwoParametersWithSameKeyTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.jetty; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -/** - * - */ -public class HttpProducerTwoParametersWithSameKeyTest extends BaseJettyTest { - - @Test - public void testTwoParametersWithSameKey() throws Exception { - Exchange out = template.request("http://localhost:{{port}}/myapp?from=me&to=foo&to=bar", null); - - assertNotNull(out); - assertFalse("Should not fail", out.isFailed()); - assertEquals("OK", out.getOut().getBody(String.class)); - assertEquals("yes", out.getOut().getHeader("bar")); - - List<?> foo = out.getOut().getHeader("foo", List.class); - assertNotNull(foo); - assertEquals(2, foo.size()); - assertEquals("123", foo.get(0)); - assertEquals("456", foo.get(1)); - } - - @Test - public void testTwoHeadersWithSameKeyHeader() throws Exception { - Exchange out = template.request("http://localhost:{{port}}/myapp", new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody(null); - exchange.getIn().setHeader("from", "me"); - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - exchange.getIn().setHeader("to", list); - } - }); - - assertNotNull(out); - assertFalse("Should not fail", out.isFailed()); - assertEquals("OK", out.getOut().getBody(String.class)); - assertEquals("yes", out.getOut().getHeader("bar")); - - List<?> foo = out.getOut().getHeader("foo", List.class); - assertNotNull(foo); - assertEquals(2, foo.size()); - assertEquals("123", foo.get(0)); - assertEquals("456", foo.get(1)); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/myapp").process(new Processor() { - public void process(Exchange exchange) throws Exception { - String from = exchange.getIn().getHeader("from", String.class); - assertEquals("me", from); - - List<?> to = exchange.getIn().getHeader("to", List.class); - assertNotNull(to); - assertEquals(2, to.size()); - assertEquals("foo", to.get(0)); - assertEquals("bar", to.get(1)); - - // response - exchange.getOut().setBody("OK"); - // use multiple values for the foo header in the reply - List<Integer> list = new ArrayList<Integer>(); - list.add(123); - list.add(456); - exchange.getOut().setHeader("foo", list); - exchange.getOut().setHeader("bar", "yes"); - } - }); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteContentTypeTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteContentTypeTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteContentTypeTest.java deleted file mode 100644 index 7485a93..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteContentTypeTest.java +++ /dev/null @@ -1,52 +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.util.ExchangeHelper; -import org.junit.Test; - -public class HttpProxyRouteContentTypeTest extends BaseJettyTest { - - @Test - public void testHttpProxyWithContentType() throws Exception { - - String out = template.requestBodyAndHeader("http://localhost:{{port}}/hello", "test", "Content-Type", "application/xml", String.class); - - assertEquals("Get a wrong response ", "application/xml", out); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - from("jetty://http://localhost:{{port}}/hello").to("http://localhost:{{port}}/bye?throwExceptionOnFailure=false&bridgeEndpoint=true"); - - from("jetty://http://localhost:{{port}}/bye").process(new Processor() { - - public void process(Exchange exchange) throws Exception { - - exchange.getOut().setBody(ExchangeHelper.getContentType(exchange)); - } - - }); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.java deleted file mode 100644 index e0188f6..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpProxyRouteTest.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 org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.util.StopWatch; -import org.apache.camel.util.TimeUtils; -import org.junit.Test; - -public class HttpProxyRouteTest extends BaseJettyTest { - - private int size = 10; - - @Test - public void testHttpProxy() throws Exception { - log.info("Sending " + size + " messages to a http endpoint which is proxied/bridged"); - - StopWatch watch = new StopWatch(); - for (int i = 0; i < size; i++) { - String out = template.requestBody("http://localhost:{{port}}?foo=" + i, null, String.class); - assertEquals("Bye " + i, out); - } - - log.info("Time taken: " + TimeUtils.printDuration(watch.taken())); - } - - @Test - public void testHttpProxyWithDifferentPath() throws Exception { - String out = template.requestBody("http://localhost:{{port}}/proxy", null, String.class); - assertEquals("/otherEndpoint", out); - - out = template.requestBody("http://localhost:{{port}}/proxy/path", null, String.class); - assertEquals("/otherEndpoint/path", out); - } - - @Test - public void testHttpProxyHostHeader() throws Exception { - String out = template.requestBody("http://localhost:{{port}}/proxyServer", null, String.class); - assertEquals("Get a wrong host header", "localhost:" + getPort2(), out); - } - - @Test - public void testHttpProxyFormHeader() throws Exception { - String out = template.requestBodyAndHeader("http://localhost:{{port}}/form", "username=abc&pass=password", Exchange.CONTENT_TYPE, "application/x-www-form-urlencoded", String.class); - assertEquals("Get a wrong response message", "username=abc&pass=password", out); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - from("jetty://http://localhost:{{port}}") - .to("http://localhost:{{port}}/bye?throwExceptionOnFailure=false&bridgeEndpoint=true"); - - from("jetty://http://localhost:{{port}}/proxy?matchOnUriPrefix=true") - .to("http://localhost:{{port}}/otherEndpoint?throwExceptionOnFailure=false&bridgeEndpoint=true"); - - from("jetty://http://localhost:{{port}}/bye").transform(header("foo").prepend("Bye ")); - - from("jetty://http://localhost:{{port}}/otherEndpoint?matchOnUriPrefix=true").transform(header(Exchange.HTTP_URI)); - - from("jetty://http://localhost:{{port}}/proxyServer") - .to("http://localhost:{{port2}}/host?bridgeEndpoint=true"); - - from("jetty://http://localhost:{{port2}}/host").transform(header("host")); - - // check the from request - from("jetty://http://localhost:{{port}}/form?bridgeEndpoint=true") - .process(new Processor() { - @Override - public void process(Exchange exchange) throws Exception { - // just take out the message body and send it back - Message in = exchange.getIn(); - String request = in.getBody(String.class); - exchange.getOut().setBody(request); - } - - }); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectNoLocationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectNoLocationTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectNoLocationTest.java deleted file mode 100644 index b37b448..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectNoLocationTest.java +++ /dev/null @@ -1,59 +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.RuntimeCamelException; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.http.HttpOperationFailedException; -import org.junit.Test; - -/** - * @version - */ -public class HttpRedirectNoLocationTest extends BaseJettyTest { - - @Test - public void testHttpRedirectNoLocation() throws Exception { - try { - template.requestBody("http://localhost:{{port}}/test", "Hello World", String.class); - fail("Should have thrown an exception"); - } catch (RuntimeCamelException e) { - HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); - assertEquals(302, cause.getStatusCode()); - assertEquals(true, cause.isRedirectError()); - assertEquals(false, cause.hasRedirectLocation()); - assertEquals(null, cause.getRedirectLocation()); - } - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 302); - } - }); - } - }; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java deleted file mode 100644 index cd26dae..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRedirectTest.java +++ /dev/null @@ -1,89 +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.RuntimeCamelException; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.http.HttpOperationFailedException; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.Test; - -/** - * @version - */ -public class HttpRedirectTest extends BaseJettyTest { - - @Test - public void testHttpRedirect() throws Exception { - try { - template.requestBody("http://localhost:{{port}}/test", "Hello World", String.class); - fail("Should have thrown an exception"); - } catch (RuntimeCamelException e) { - HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, - e.getCause()); - assertEquals(301, cause.getStatusCode()); - assertEquals(true, cause.isRedirectError()); - assertEquals(true, cause.hasRedirectLocation()); - assertEquals("http://localhost:" + getPort() + "/test", cause.getUri()); - assertEquals("http://localhost:" + getPort() + "/newtest", cause.getRedirectLocation()); - } - } - - @Test - public void testHttpRedirectFromCamelRoute() throws Exception { - MockEndpoint errorEndpoint = context.getEndpoint("mock:error", MockEndpoint.class); - errorEndpoint.expectedMessageCount(1); - MockEndpoint resultEndpoint = context.getEndpoint("mock:result", MockEndpoint.class); - resultEndpoint.expectedMessageCount(0); - try { - template.requestBody("direct:start", "Hello World", String.class); - fail("Should have thrown an exception"); - } catch (RuntimeCamelException e) { - HttpOperationFailedException cause = assertIsInstanceOf(HttpOperationFailedException.class, - e.getCause()); - assertEquals(302, cause.getStatusCode()); - } - errorEndpoint.assertIsSatisfied(); - resultEndpoint.assertIsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test").process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 301); - exchange.getOut().setHeader("location", "http://localhost:" + getPort() + "/newtest"); - } - }); - from("jetty://http://localhost:{{port}}/remove").process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 302); - } - }); - - from("direct:start").onException(HttpOperationFailedException.class).to("mock:error").end() - .to("http://localhost:{{port}}/remove?throwExceptionOnFailure=true").to("mock:result"); - - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRequestResponseTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRequestResponseTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRequestResponseTest.java deleted file mode 100644 index 7c962c2..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRequestResponseTest.java +++ /dev/null @@ -1,81 +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 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.HttpMessage; -import org.junit.Test; - -/** - * Unit test for request response in message - */ -public class HttpRequestResponseTest extends BaseJettyTest { - - @Test - public void testHttpServletRequestResponse() 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("Written by servlet response<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 { - // START SNIPPET: e1 - from("jetty:http://localhost:{{port}}/myapp/myservice").process(new MyBookService()); - // END SNIPPET: e1 - } - }; - } - - 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); - - // we have access to the HttpServletResponse here and we can grab it if we need it - HttpServletResponse res = exchange.getIn().getBody(HttpServletResponse.class); - assertNotNull(res); - - // and they should also be on HttpMessage - HttpMessage msg = (HttpMessage) exchange.getIn(); - assertNotNull(msg.getRequest()); - assertNotNull(msg.getResponse()); - - // and we can use servlet response to write to output stream also - res.getOutputStream().print("Written by servlet response"); - - // for unit testing - assertEquals("bookid=123", body); - - // send a html response - exchange.getOut().setBody("<html><body>Book 123 is Camel in Action</body></html>"); - } - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnDataNotInputStreamConvertableTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnDataNotInputStreamConvertableTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnDataNotInputStreamConvertableTest.java deleted file mode 100644 index c057e18..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnDataNotInputStreamConvertableTest.java +++ /dev/null @@ -1,56 +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; - -/** - * @version - */ -public class HttpReturnDataNotInputStreamConvertableTest extends BaseJettyTest { - - @Test - public void testHttpReturnDataNotInputStreamConvertableTest() throws Exception { - String out = template.requestBody("http://localhost:{{port}}/test", "Hello World", String.class); - assertEquals("This is the response", out); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setBody(new MyResponseBean()); - } - }); - } - }; - } - - private static class MyResponseBean { - @Override - public String toString() { - return "This is the response"; - } - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java deleted file mode 100644 index 86f2e85..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpReturnFaultTest.java +++ /dev/null @@ -1,61 +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.HttpOperationFailedException; -import org.junit.Test; - -/** - * @version - */ -public class HttpReturnFaultTest extends BaseJettyTest { - - @Test - public void testHttpFault() throws Exception { - Exchange exchange = template.request("http://localhost:{{port}}/test", new Processor() { - @Override - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody("Hello World!"); - } - - }); - assertTrue(exchange.isFailed()); - HttpOperationFailedException exception = exchange.getException(HttpOperationFailedException.class); - assertNotNull(exception); - assertEquals("This is a fault", exception.getResponseBody()); - assertEquals(500, exception.getStatusCode()); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setFault(true); - exchange.getOut().setBody("This is a fault"); - } - }); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRoundtripHeaderTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRoundtripHeaderTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRoundtripHeaderTest.java deleted file mode 100644 index 16a9201..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRoundtripHeaderTest.java +++ /dev/null @@ -1,126 +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.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -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.apache.camel.impl.DefaultHeaderFilterStrategy; -import org.apache.camel.util.IOHelper; - -import org.junit.Test; - -public class HttpRoundtripHeaderTest extends BaseJettyTest { - protected final String uri = "http://localhost:" + getPort() + "/WhichWillGetCloseException"; - protected final String jettyUri = "jetty:" + uri; - protected final String outputText = ":output"; - protected String inputText = "input"; - protected String expectedText = inputText + outputText; - - // http://issues.apache.org/activemq/browse/CAMEL-324 - @Test - public void testHttpRoundTripHeaders() throws Exception { - MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class); - mockEndpoint.expectedMessageCount(1); - - InputStream answer = (InputStream) template.requestBody(uri, inputText); - - verifyMockGotExpectedText(mockEndpoint, expectedText); - - // read the response data - String lastLine = readLastLine(answer); - - assertNotNull("last response line", lastLine); - assertEquals("response matches: " + expectedText, expectedText, lastLine); - } - - @Test - public void testHttpRoundTripHeadersWithNoIgnoredHeaders() throws Exception { - MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class); - mockEndpoint.expectedMessageCount(1); - - JettyHttpEndpoint endpoint = context.getEndpoint(jettyUri, JettyHttpEndpoint.class); - // override the default set of ignored headers which includes Content-Length - ((DefaultHeaderFilterStrategy)endpoint.getHeaderFilterStrategy()).setOutFilter(null); - - // read the response data - InputStream answer = (InputStream) template.requestBody(uri, inputText); - verifyMockGotExpectedText(mockEndpoint, expectedText); - - String lastLine = readLastLine(answer); - assertNotNull("last response line", lastLine); - - // Content-Length from request will truncate the output to just the inputText - assertEquals("response matches: " + inputText, inputText, lastLine); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - Processor processor = new Processor() { - public void process(Exchange exchange) { - String input = (String) exchange.getIn().getBody(); - // append some text to invalidate Context-Length - // for the http reply - exchange.getIn().setBody(input + outputText); - } - }; - - // the unmarshaller does a copy from in message to out - // including all headers - from(jettyUri).unmarshal().string().process(processor).to("mock:results"); - } - }; - } - - private void verifyMockGotExpectedText(MockEndpoint mockEndpoint, String expected) throws InterruptedException { - 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(); - assertTrue("no headers are propagated", !headers.isEmpty()); - assertEquals("body has expectedText:" + expected, expected, in.getBody()); - } - - private String readLastLine(InputStream answer) throws IOException { - String lastLine = null; - BufferedReader reader = IOHelper.buffered(new InputStreamReader(answer)); - while (true) { - String line = reader.readLine(); - if (line == null) { - break; - } - lastLine = line; - log.info("Read: " + line); - } - reader.close(); - return lastLine; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/a59becd7/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java deleted file mode 100644 index adb78c7..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpRouteTest.java +++ /dev/null @@ -1,269 +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.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.List; -import java.util.Map; -import javax.servlet.http.HttpSession; - -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.HttpMessage; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.converter.stream.InputStreamCache; -import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.NameValuePair; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PostMethod; -import org.apache.commons.httpclient.methods.PutMethod; -import org.apache.commons.httpclient.methods.StringRequestEntity; -import org.junit.Test; - -/** - * @version - */ -public class HttpRouteTest extends BaseJettyTest { - protected static final String POST_MESSAGE = "<?xml version=\"1.0\" encoding=\"UTF-8\"?> " - + "<test>Hello World</test>"; - protected String expectedBody = "<hello>world!</hello>"; - - private int port1; - private int port2; - private int port3; - private int port4; - - @Test - public void testEndpoint() throws Exception { - MockEndpoint mockEndpoint = getMockEndpoint("mock:a"); - mockEndpoint.expectedBodiesReceived(expectedBody); - - invokeHttpEndpoint(); - - 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 testHelloEndpoint() throws Exception { - ByteArrayOutputStream os = new ByteArrayOutputStream(); - InputStream is = new URL("http://localhost:" + port2 + "/hello").openStream(); - int c; - while ((c = is.read()) >= 0) { - os.write(c); - } - - String data = new String(os.toByteArray()); - assertEquals("<b>Hello World</b>", data); - } - - @Test - public void testEchoEndpoint() throws Exception { - String out = template.requestBody("http://localhost:" + port1 + "/echo", "HelloWorld", String.class); - assertEquals("Get a wrong output " , "HelloWorld", out); - } - - @Test - public void testPostParameter() throws Exception { - NameValuePair[] data = {new NameValuePair("request", "PostParameter"), - new NameValuePair("others", "bloggs")}; - HttpClient client = new HttpClient(); - PostMethod post = new PostMethod("http://localhost:" + port1 + "/parameter"); - post.setRequestBody(data); - client.executeMethod(post); - InputStream response = post.getResponseBodyAsStream(); - String out = context.getTypeConverter().convertTo(String.class, response); - assertEquals("Get a wrong output " , "PostParameter", out); - } - - @Test - public void testPostXMLMessage() throws Exception { - HttpClient client = new HttpClient(); - PostMethod post = new PostMethod("http://localhost:" + port1 + "/postxml"); - StringRequestEntity entity = new StringRequestEntity(POST_MESSAGE, "application/xml", "UTF-8"); - post.setRequestEntity(entity); - client.executeMethod(post); - InputStream response = post.getResponseBodyAsStream(); - String out = context.getTypeConverter().convertTo(String.class, response); - assertEquals("Get a wrong output " , "OK", out); - } - - @Test - public void testPostParameterInURI() throws Exception { - HttpClient client = new HttpClient(); - PostMethod post = new PostMethod("http://localhost:" + port1 + "/parameter?request=PostParameter&others=bloggs"); - StringRequestEntity entity = new StringRequestEntity(POST_MESSAGE, "application/xml", "UTF-8"); - post.setRequestEntity(entity); - client.executeMethod(post); - InputStream response = post.getResponseBodyAsStream(); - String out = context.getTypeConverter().convertTo(String.class, response); - assertEquals("Get a wrong output " , "PostParameter", out); - } - - @Test - public void testPutParameterInURI() throws Exception { - HttpClient client = new HttpClient(); - PutMethod put = new PutMethod("http://localhost:" + port1 + "/parameter?request=PutParameter&others=bloggs"); - StringRequestEntity entity = new StringRequestEntity(POST_MESSAGE, "application/xml", "UTF-8"); - put.setRequestEntity(entity); - client.executeMethod(put); - InputStream response = put.getResponseBodyAsStream(); - String out = context.getTypeConverter().convertTo(String.class, response); - assertEquals("Get a wrong output " , "PutParameter", out); - } - - @Test - public void testDisableStreamCache() throws Exception { - String response = - template.requestBodyAndHeader("http://localhost:" + port3 + "/noStreamCache", - new ByteArrayInputStream("This is a test".getBytes()), "Content-Type", "application/xml", String.class); - - assertEquals("Get a wrong output ", "OK", response); - } - - @Test - public void testRequestBufferSize() throws Exception { - InputStream in = this.getClass().getResourceAsStream("/META-INF/LICENSE.txt"); - int fileSize = in.available(); - String response = - template.requestBodyAndHeader("http://localhost:" + port4 + "/requestBufferSize", - in, Exchange.CONTENT_TYPE, "application/txt", String.class); - assertEquals("Got a wrong response.", fileSize, response.length()); - } - - @Test - public void testResponseCode() throws Exception { - HttpClient client = new HttpClient(); - GetMethod get = new GetMethod("http://localhost:" + port1 + "/responseCode"); - client.executeMethod(get); - // just make sure we get the right - assertEquals("Get a wrong status code.", 400, get.getStatusCode()); - } - - - protected void invokeHttpEndpoint() throws IOException { - template.requestBodyAndHeader("http://localhost:" + port1 + "/test", expectedBody, "Content-Type", "application/xml"); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - port1 = getPort(); - port2 = getNextPort(); - port3 = getNextPort(); - port4 = getNextPort(); - - - // enable stream cache - context.setStreamCaching(true); - - from("jetty:http://localhost:" + port1 + "/test").to("mock:a"); - - Processor proc = new Processor() { - public void process(Exchange exchange) throws Exception { - try { - HttpMessage message = (HttpMessage)exchange.getIn(); - HttpSession session = message.getRequest().getSession(); - assertNotNull("we should get session here", session); - } catch (Exception e) { - exchange.getOut().setFault(true); - exchange.getOut().setBody(e); - } - exchange.getOut().setBody("<b>Hello World</b>"); - } - }; - - from("jetty:http://localhost:" + port1 + "/responseCode").setHeader(Exchange.HTTP_RESPONSE_CODE, simple("400")); - - Processor printProcessor = new Processor() { - public void process(Exchange exchange) throws Exception { - Message out = exchange.getOut(); - out.copyFrom(exchange.getIn()); - log.info("The body's object is " + exchange.getIn().getBody()); - log.info("Process body = " + exchange.getIn().getBody(String.class)); - InputStreamCache cache = out.getBody(InputStreamCache.class); - cache.reset(); - } - }; - from("jetty:http://localhost:" + port2 + "/hello?sessionSupport=true").process(proc); - - from("jetty:http://localhost:" + port1 + "/echo").process(printProcessor).process(printProcessor); - - Processor procParameters = new Processor() { - public void process(Exchange exchange) throws Exception { - // As the request input stream is cached by DefaultHttpBinding, - // HttpServletRequest can't get the parameters of post message - String value = exchange.getIn().getHeader("request", String.class); - if (value != null) { - assertNotNull("The value of the parameter should not be null", value); - exchange.getOut().setBody(value); - } else { - exchange.getOut().setBody("Can't get a right parameter"); - } - } - }; - - from("jetty:http://localhost:" + port1 + "/parameter").process(procParameters); - - from("jetty:http://localhost:" + port1 + "/postxml").process(new Processor() { - public void process(Exchange exchange) throws Exception { - String value = exchange.getIn().getBody(String.class); - assertEquals("The response message is wrong", value, POST_MESSAGE); - exchange.getOut().setBody("OK"); - } - }); - - from("jetty:http://localhost:" + port3 + "/noStreamCache?disableStreamCache=true").noStreamCaching().process(new Processor() { - public void process(Exchange exchange) throws Exception { - InputStream is = (InputStream)exchange.getIn().getBody(); - assertTrue("It should be a raw inputstream", is instanceof org.eclipse.jetty.server.HttpInput); - String request = exchange.getIn().getBody(String.class); - assertEquals("Got a wrong request", "This is a test", request); - exchange.getOut().setBody("OK"); - } - }); - - from("jetty:http://localhost:" + port4 + "/requestBufferSize").process(new Processor() { - public void process(Exchange exchange) throws Exception { - String string = exchange.getIn().getBody(String.class); - exchange.getOut().setBody(string); - } - }); - } - }; - } -} - -