http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpSendFileTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpSendFileTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpSendFileTest.java deleted file mode 100644 index 89cfbd0..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpSendFileTest.java +++ /dev/null @@ -1,70 +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 java.io.InputStream; - -import org.apache.camel.Exchange; -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 HttpSendFileTest extends BaseJettyTest { - - @Test - public void testSendImage() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMinimumMessageCount(1); - mock.message(0).body().isInstanceOf(InputStream.class); - mock.message(0).header("Content-Type").isEqualTo("image/jpeg"); - - Exchange out = template.send("http://localhost:{{port}}/myapp/myservice", new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody(new File("src/test/data/logo.jpeg")); - exchange.getIn().setHeader("Content-Type", "image/jpeg"); - } - }); - - assertMockEndpointsSatisfied(); - - assertEquals("OK", out.getOut().getBody(String.class)); - assertEquals("text/plain", out.getOut().getHeader("Content-Type")); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - from("jetty:http://localhost:{{port}}/myapp/myservice") - .to("mock:result") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - String body = exchange.getIn().getBody(String.class); - assertNotNull("Body should not be null", body); - } - }) - .transform(constant("OK")).setHeader("Content-Type", constant("text/plain")); - } - }; - } - -}
http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileIssueTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileIssueTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileIssueTest.java deleted file mode 100644 index d86b37b..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileIssueTest.java +++ /dev/null @@ -1,90 +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.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.converter.stream.CachedOutputStream; -import org.junit.Before; -import org.junit.Test; - -/** - * @version - */ -public class HttpStreamCacheFileIssueTest extends BaseJettyTest { - - private String body = "12345678901234567890123456789012345678901234567890"; - - @Override - @Before - public void setUp() throws Exception { - deleteDirectory("target/cachedir"); - createDirectory("target/cachedir"); - super.setUp(); - } - - @Test - public void testStreamCacheToFileShouldBeDeletedInCaseOfStop() throws Exception { - getMockEndpoint("mock:result").expectedMessageCount(1); - - String out = template.requestBody("direct:start", "Hello World", String.class); - assertEquals(body, out); - - // the temporary files should have been deleted - File file = new File("target/cachedir"); - String[] files = file.list(); - assertEquals("There should be no files", 0, files.length); - - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - // enable stream caching and use a low threshold so its forced to write to file - context.getProperties().put(CachedOutputStream.TEMP_DIR, "target/cachedir"); - context.getProperties().put(CachedOutputStream.THRESHOLD, "16"); - context.setStreamCaching(true); - - // use a route so we got an unit of work - from("direct:start") - .to("http://localhost:{{port}}/myserver") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - // there should be a temp cache file - File file = new File("target/cachedir"); - String[] files = file.list(); - assertTrue("There should be a temp cache file", files.length > 0); - } - }) - // TODO: CAMEL-3839: need to convert the body to a String as the tmp file will be deleted - // before the producer template can convert the result back - .convertBodyTo(String.class) - .to("mock:result"); - - from("jetty://http://localhost:{{port}}/myserver") - .transform().constant(body); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileResponseTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileResponseTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileResponseTest.java deleted file mode 100644 index f9432f3..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileResponseTest.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.BufferedInputStream; -import java.io.ByteArrayInputStream; -import java.io.File; - -import org.apache.camel.builder.RouteBuilder; -import org.junit.Before; -import org.junit.Test; - -/** - * @version - */ -public class HttpStreamCacheFileResponseTest extends BaseJettyTest { - - private String body = "12345678901234567890123456789012345678901234567890"; - private String body2 = "Bye " + body; - - @Override - @Before - public void setUp() throws Exception { - deleteDirectory("target/cachedir"); - createDirectory("target/cachedir"); - super.setUp(); - } - - @Test - public void testStreamCacheToFileShouldBeDeletedInCaseOfResponse() throws Exception { - String out = template.requestBody("http://localhost:{{port}}/myserver", body, String.class); - assertEquals(body2, out); - - // the temporary files should have been deleted - File file = new File("target/cachedir"); - String[] files = file.list(); - assertEquals("There should be no files", 0, files.length); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - // enable stream caching and use a low threshold so its forced to write to file - context.getStreamCachingStrategy().setSpoolDirectory("target/cachedir"); - context.getStreamCachingStrategy().setSpoolThreshold(16); - context.setStreamCaching(true); - - from("jetty://http://localhost:{{port}}/myserver") - // wrap the response in 2 input streams so it will force caching to disk - .transform().constant(new BufferedInputStream(new ByteArrayInputStream(body2.getBytes()))) - .to("log:reply"); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileStopIssueTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileStopIssueTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileStopIssueTest.java deleted file mode 100644 index 0eb40e8..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileStopIssueTest.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.io.File; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.converter.stream.CachedOutputStream; -import org.junit.Before; -import org.junit.Test; - -/** - * @version - */ -public class HttpStreamCacheFileStopIssueTest extends BaseJettyTest { - - private String body = "12345678901234567890123456789012345678901234567890"; - - @Override - @Before - public void setUp() throws Exception { - deleteDirectory("target/cachedir"); - createDirectory("target/cachedir"); - super.setUp(); - } - - @Test - public void testStreamCacheToFileShouldBeDeletedInCaseOfStop() throws Exception { - getMockEndpoint("mock:result").expectedMessageCount(0); - - String out = template.requestBody("direct:start", "Hello World", String.class); - assertEquals(body, out); - - // the temporary files should have been deleted - File file = new File("target/cachedir"); - String[] files = file.list(); - assertEquals("There should be no files", 0, files.length); - - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - // enable stream caching and use a low threshold so its forced to write to file - context.getProperties().put(CachedOutputStream.TEMP_DIR, "target/cachedir"); - context.getProperties().put(CachedOutputStream.THRESHOLD, "16"); - context.setStreamCaching(true); - - // use a route so we got an unit of work - from("direct:start") - .to("http://localhost:{{port}}/myserver") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - // there should be a temp cache file - File file = new File("target/cachedir"); - String[] files = file.list(); - assertTrue("There should be a temp cache file", files.length > 0); - } - }) - // TODO: CAMEL-3839: need to convert the body to a String as the tmp file will be deleted - // before the producer template can convert the result back - .convertBodyTo(String.class) - // mark the exchange to stop continue routing - .stop() - .to("mock:result"); - - from("jetty://http://localhost:{{port}}/myserver") - .transform().constant(body); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileTest.java deleted file mode 100644 index c72b418..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpStreamCacheFileTest.java +++ /dev/null @@ -1,101 +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.CamelExecutionException; -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.apache.camel.converter.stream.CachedOutputStream; -import org.junit.Before; -import org.junit.Test; - -/** - * @version - */ -public class HttpStreamCacheFileTest extends BaseJettyTest { - - private String body = "12345678901234567890123456789012345678901234567890"; - - @Override - @Before - public void setUp() throws Exception { - deleteDirectory("target/cachedir"); - createDirectory("target/cachedir"); - super.setUp(); - } - - @Test - public void testStreamCacheToFileShouldBeDeletedInCaseOfResponse() throws Exception { - String out = template.requestBody("direct:start", "Hello World", String.class); - assertEquals("Bye World", out); - - // the temporary files should have been deleted - File file = new File("target/cachedir"); - String[] files = file.list(); - assertEquals("There should be no files", 0, files.length); - } - - @Test - public void testStreamCacheToFileShouldBeDeletedInCaseOfException() throws Exception { - try { - template.requestBody("direct:start", null, String.class); - fail("Should have thrown an exception"); - } catch (CamelExecutionException e) { - HttpOperationFailedException hofe = assertIsInstanceOf(HttpOperationFailedException.class, e.getCause()); - String s = context.getTypeConverter().convertTo(String.class, hofe.getResponseBody()); - assertEquals("Response body", body, s); - } - - // the temporary files should have been deleted - File file = new File("target/cachedir"); - String[] files = file.list(); - assertEquals("There should be no files", 0, files.length); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - // enable stream caching and use a low threshold so its forced to write to file - context.getProperties().put(CachedOutputStream.TEMP_DIR, "target/cachedir"); - context.getProperties().put(CachedOutputStream.THRESHOLD, "16"); - context.setStreamCaching(true); - - // use a route so we got an unit of work - from("direct:start").to("http://localhost:{{port}}/myserver"); - - from("jetty://http://localhost:{{port}}/myserver") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - if (exchange.getIn().getBody() == null) { - exchange.getOut().setBody(body); - exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, 500); - } else { - exchange.getOut().setBody("Bye World"); - } - } - }); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpToFileTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpToFileTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpToFileTest.java deleted file mode 100644 index 7d07f31..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpToFileTest.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 java.io.File; - -import org.apache.camel.Exchange; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.converter.IOConverter; -import org.junit.Before; -import org.junit.Test; - -/** - * Unit testing demonstrating how to store incoming requests as files and serving a response back. - */ -public class HttpToFileTest extends BaseJettyTest { - - @Test - public void testToJettyAndSaveToFile() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedBodiesReceived("Hello World"); - - Object out = template.requestBody("http://localhost:{{port}}/myworld", "Hello World"); - - String response = context.getTypeConverter().convertTo(String.class, out); - assertEquals("Response from Jetty", "We got the file", response); - - assertMockEndpointsSatisfied(); - - // give file some time to save - Thread.sleep(500); - - File file = new File("target/myworld/hello.txt"); - assertTrue("File should exists", file.exists()); - - String content = IOConverter.toString(file, null); - assertEquals("File content", "Hello World", content); - } - - @Override - @Before - public void setUp() throws Exception { - deleteDirectory("target/myworld"); - super.setUp(); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - // put the incoming data on the seda queue and return a fixed response that we got the file - from("jetty:http://localhost:{{port}}/myworld") - .convertBodyTo(String.class) - .to("seda:in") - .setBody(constant("We got the file")); - - // store the content from the queue as a file - from("seda:in") - .setHeader(Exchange.FILE_NAME, constant("hello.txt")) - .convertBodyTo(String.class) - .to("file://target/myworld/") - .to("mock:result"); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoEndpointTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoEndpointTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoEndpointTest.java deleted file mode 100644 index 1d20aef..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoEndpointTest.java +++ /dev/null @@ -1,67 +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 HttpTwoEndpointTest extends BaseJettyTest { - - @Test - public void testTwoEndpoints() throws Exception { - Exchange a = template.request("direct:a", null); - assertNotNull(a); - - Exchange b = template.request("direct:b", null); - assertNotNull(b); - - assertEquals("Bye cheese", a.getOut().getBody(String.class)); - assertEquals(246, a.getOut().getHeader("foo", Integer.class).intValue()); - - assertEquals("Bye cake", b.getOut().getBody(String.class)); - assertEquals(912, b.getOut().getHeader("foo", Integer.class).intValue()); - - assertEquals(5, context.getEndpoints().size()); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:a").to("http://localhost:{{port}}/myapp?foo=123&bar=cheese"); - - from("direct:b").to("http://localhost:{{port}}/myapp?foo=456&bar=cake"); - - from("jetty://http://localhost:{{port}}/myapp").process(new Processor() { - public void process(Exchange exchange) throws Exception { - int foo = exchange.getIn().getHeader("foo", Integer.class); - String bar = exchange.getIn().getHeader("bar", String.class); - - exchange.getOut().setHeader("foo", foo * 2); - exchange.getOut().setBody("Bye " + bar); - } - }); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoServerPortsTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoServerPortsTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoServerPortsTest.java deleted file mode 100644 index 52510b1..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpTwoServerPortsTest.java +++ /dev/null @@ -1,75 +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 HttpTwoServerPortsTest extends BaseJettyTest { - - private int port1; - private int port2; - - @Test - public void testTwoServerPorts() throws Exception { - String reply = template.requestBody("direct:a", "World", String.class); - assertEquals("Bye World", reply); - - reply = template.requestBody("direct:b", "Camel", String.class); - assertEquals("Hi Camel", reply); - - reply = template.requestBody("direct:a", "Earth", String.class); - assertEquals("Bye Earth", reply); - - reply = template.requestBody("direct:b", "Moon", String.class); - assertEquals("Hi Moon", reply); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - port1 = getPort(); - port2 = getNextPort(); - - from("direct:a").to("http://localhost:" + port1 + "/myapp"); - - from("direct:b").to("http://localhost:" + port2 + "/myotherapp"); - - from("jetty://http://localhost:" + port1 + "/myapp").process(new Processor() { - public void process(Exchange exchange) throws Exception { - String in = exchange.getIn().getBody(String.class); - exchange.getOut().setBody("Bye " + in); - } - }); - - from("jetty://http://localhost:" + port2 + "/myotherapp").process(new Processor() { - public void process(Exchange exchange) throws Exception { - String in = exchange.getIn().getBody(String.class); - exchange.getOut().setBody("Hi " + in); - } - }); - } - }; - } -} \ 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/HttpUrlRewriteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpUrlRewriteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpUrlRewriteTest.java deleted file mode 100644 index d97c9f3..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpUrlRewriteTest.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 org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.impl.JndiRegistry; -import org.junit.Test; - -public class HttpUrlRewriteTest extends BaseJettyTest { - - private int port1; - private int port2; - - @Override - protected JndiRegistry createRegistry() throws Exception { - JndiRegistry jndi = super.createRegistry(); - jndi.bind("myRewrite", new MyUrlRewrite()); - return jndi; - } - - @Test - public void testUrlRewrite() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:result"); - mock.expectedMessageCount(1); - - String response = template.requestBody("http://localhost:" + port1 + "/foo?phrase=Bye", "Camel", String.class); - assertEquals("Get a wrong response", "Bye Camel", response); - - assertMockEndpointsSatisfied(); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - port1 = getPort(); - port2 = getNextPort(); - - from("jetty:http://localhost:" + port1 + "?matchOnUriPrefix=true") - .to("http://localhost:" + port2 + "?throwExceptionOnFailure=false&bridgeEndpoint=true&urlRewrite=#myRewrite"); - - from("jetty://http://localhost:" + port2 + "/bar") - .transform().simple("${header.phrase} ${body}") - .to("mock:result"); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteAddSslConnectorPropertiesTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteAddSslConnectorPropertiesTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteAddSslConnectorPropertiesTest.java deleted file mode 100644 index 53753fd..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteAddSslConnectorPropertiesTest.java +++ /dev/null @@ -1,55 +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.URISyntaxException; -import java.net.URL; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; - -public class HttpsRouteAddSslConnectorPropertiesTest extends HttpsRouteTest { - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws URISyntaxException { - // START SNIPPET: e1 - // keystore path - URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks"); - String path = keyStoreUrl.toURI().getPath(); - - JettyHttpComponent jetty = context.getComponent("jetty", JettyHttpComponent.class); - setSSLProps(jetty, path, pwd, pwd); - // 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/HttpsRouteAliasTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteAliasTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteAliasTest.java deleted file mode 100644 index 1c99e5d..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteAliasTest.java +++ /dev/null @@ -1,67 +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.URISyntaxException; - -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; - -public class HttpsRouteAliasTest extends HttpsRouteTest { - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws URISyntaxException { - JettyHttpComponent jetty = context.getComponent("jetty", JettyHttpComponent.class); - - KeyStoreParameters ksp = new KeyStoreParameters(); - ksp.setResource(this.getClass().getClassLoader().getResource("jsse/localhost-alias.ks").toString()); - ksp.setPassword(pwd); - - KeyManagersParameters kmp = new KeyManagersParameters(); - kmp.setKeyPassword(pwd); - kmp.setKeyStore(ksp); - - SSLContextParameters sslContextParameters = new SSLContextParameters(); - sslContextParameters.setKeyManagers(kmp); - - // Specify "server" cert alias - sslContextParameters.setCertAlias("server"); - - jetty.setSslContextParameters(sslContextParameters); - - setSSLProps(jetty, "", "asdfasdfasdfdasfs", "sadfasdfasdfas"); - - 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"); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSetupWithSystemPropsTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSetupWithSystemPropsTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSetupWithSystemPropsTest.java deleted file mode 100644 index b569eed..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSetupWithSystemPropsTest.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.URL; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; -import org.junit.Before; - -public class HttpsRouteSetupWithSystemPropsTest extends HttpsRouteTest { - - @Override - @Before - public void setUp() throws Exception { - // ensure jsse clients can validate the self signed dummy localhost cert, - // use the server keystore as the trust store for these tests - URL trustStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks"); - setSystemProp("javax.net.ssl.trustStore", trustStoreUrl.getPath()); - - // START SNIPPET: e1 - // setup SSL using system properties - setSystemProp("org.eclipse.jetty.ssl.keystore", trustStoreUrl.getPath()); - setSystemProp("org.eclipse.jetty.ssl.keypassword", pwd); - setSystemProp("org.eclipse.jetty.ssl.password", pwd); - // END SNIPPET: e1 - - super.setUp(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() { - 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/HttpsRouteSslContextParametersInComponentTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSslContextParametersInComponentTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSslContextParametersInComponentTest.java deleted file mode 100644 index 378f77c..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSslContextParametersInComponentTest.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.URISyntaxException; - -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; - -public class HttpsRouteSslContextParametersInComponentTest extends HttpsRouteTest { - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws URISyntaxException { - JettyHttpComponent jetty = getContext().getComponent("jetty", JettyHttpComponent.class); - - 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); - jetty.setSslContextParameters(sslContextParameters); - // NOTE: These are here to check that they are properly ignored. - setSSLProps(jetty, "", "asdfasdfasdfdasfs", "sadfasdfasdfas"); - - 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/HttpsRouteSslContextParametersInUriTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSslContextParametersInUriTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSslContextParametersInUriTest.java deleted file mode 100644 index 43c8349..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSslContextParametersInUriTest.java +++ /dev/null @@ -1,71 +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.URISyntaxException; - -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.jsse.KeyManagersParameters; -import org.apache.camel.util.jsse.KeyStoreParameters; -import org.apache.camel.util.jsse.SSLContextParameters; - -public class HttpsRouteSslContextParametersInUriTest extends HttpsRouteTest { - - @Override - protected JndiRegistry createRegistry() 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); - - JndiRegistry registry = super.createRegistry(); - registry.bind("sslContextParameters", sslContextParameters); - - return registry; - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws URISyntaxException { - JettyHttpComponent jetty = getContext().getComponent("jetty", JettyHttpComponent.class); - // NOTE: These are here to check that they are properly ignored. - setSSLProps(jetty, "", "asdfasdfasdfdasfs", "sadfasdfasdfas"); - - from("jetty:https://localhost:" + port1 + "/test?sslContextParametersRef=sslContextParameters").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?sslContextParametersRef=sslContextParameters").process(proc); - - from("jetty:https://localhost:" + port2 + "/test?sslContextParametersRef=sslContextParameters").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/HttpsRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java deleted file mode 100644 index 56cf84b..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteTest.java +++ /dev/null @@ -1,210 +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.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.net.SocketException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -import org.apache.camel.Exchange; -import org.apache.camel.Message; -import org.apache.camel.Processor; -import org.apache.camel.RuntimeCamelException; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.eclipse.jetty.util.ssl.SslContextFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -public class HttpsRouteTest extends BaseJettyTest { - - private static final String NULL_VALUE_MARKER = CamelTestSupport.class.getCanonicalName(); - - protected String expectedBody = "<hello>world!</hello>"; - protected String pwd = "changeit"; - protected Properties originalValues = new Properties(); - protected int port1; - protected int port2; - - public String getHttpProducerScheme() { - return "https://"; - } - - @Override - @Before - public void setUp() throws Exception { - port1 = getNextPort(); - port2 = getNextPort(port1 + 1); - - super.setUp(); - // ensure jsse clients can validate the self signed dummy localhost cert, - // use the server keystore as the trust store for these tests - URL trustStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks"); - setSystemProp("javax.net.ssl.trustStore", trustStoreUrl.toURI().getPath()); - } - - @Override - @After - public void tearDown() throws Exception { - restoreSystemProperties(); - super.tearDown(); - } - - protected void setSystemProp(String key, String value) { - String originalValue = System.setProperty(key, value); - originalValues.put(key, originalValue != null ? originalValue : NULL_VALUE_MARKER); - } - - protected void restoreSystemProperties() { - for (Object key : originalValues.keySet()) { - Object value = originalValues.get(key); - if (NULL_VALUE_MARKER.equals(value)) { - System.getProperties().remove(key); - } else { - System.setProperty((String)key, (String)value); - } - } - } - - @Test - public void testEndpoint() throws Exception { - // these tests does not run well on Windows - if (isPlatform("windows")) { - return; - } - - MockEndpoint mockEndpointA = resolveMandatoryEndpoint("mock:a", MockEndpoint.class); - mockEndpointA.expectedBodiesReceived(expectedBody); - MockEndpoint mockEndpointB = resolveMandatoryEndpoint("mock:b", MockEndpoint.class); - mockEndpointB.expectedBodiesReceived(expectedBody); - - invokeHttpEndpoint(); - - mockEndpointA.assertIsSatisfied(); - mockEndpointB.assertIsSatisfied(); - List<Exchange> list = mockEndpointA.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 testEndpointWithoutHttps() throws Exception { - // these tests does not run well on Windows - if (isPlatform("windows")) { - return; - } - - MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:a", MockEndpoint.class); - try { - template.sendBodyAndHeader("http://localhost:" + port1 + "/test", expectedBody, "Content-Type", "application/xml"); - fail("expect exception on access to https endpoint via http"); - } catch (RuntimeCamelException expected) { - } - assertTrue("mock endpoint was not called", mockEndpoint.getExchanges().isEmpty()); - } - - @Test - public void testHelloEndpoint() throws Exception { - // these tests does not run well on Windows - if (isPlatform("windows")) { - return; - } - - ByteArrayOutputStream os = new ByteArrayOutputStream(); - InputStream is = new URL("https://localhost:" + port1 + "/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 testHelloEndpointWithoutHttps() throws Exception { - // these tests does not run well on Windows - if (isPlatform("windows")) { - return; - } - - try { - new URL("http://localhost:" + port1 + "/hello").openStream(); - fail("expected SocketException on use ot http"); - } catch (SocketException expected) { - } - } - - protected void invokeHttpEndpoint() throws IOException { - template.sendBodyAndHeader(getHttpProducerScheme() + "localhost:" + port1 + "/test", expectedBody, "Content-Type", "application/xml"); - template.sendBodyAndHeader(getHttpProducerScheme() + "localhost:" + port2 + "/test", expectedBody, "Content-Type", "application/xml"); - } - - protected void configureSslContextFactory(SslContextFactory sslContextFactory) { - sslContextFactory.setKeyManagerPassword(pwd); - sslContextFactory.setKeyStorePassword(pwd); - URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks"); - try { - sslContextFactory.setKeyStorePath(keyStoreUrl.toURI().getPath()); - } catch (URISyntaxException e) { - throw new RuntimeException(e.getMessage(), e); - } - sslContextFactory.setTrustStoreType("JKS"); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws URISyntaxException { - JettyHttpComponent componentJetty = (JettyHttpComponent) context.getComponent("jetty"); - componentJetty.setSslPassword(pwd); - componentJetty.setSslKeyPassword(pwd); - URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks"); - componentJetty.setKeystore(keyStoreUrl.toURI().getPath()); - - 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"); - } - }; - } -} - http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteWithSslConnectorPropertiesTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteWithSslConnectorPropertiesTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteWithSslConnectorPropertiesTest.java deleted file mode 100644 index b85bd61..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteWithSslConnectorPropertiesTest.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 java.net.URISyntaxException; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; - -import org.apache.camel.Exchange; -import org.apache.camel.Processor; -import org.apache.camel.builder.RouteBuilder; - -public class HttpsRouteWithSslConnectorPropertiesTest extends HttpsRouteTest { - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws URISyntaxException { - // START SNIPPET: e1 - // keystore path - URL keyStoreUrl = this.getClass().getClassLoader().getResource("jsse/localhost.ks"); - String path = keyStoreUrl.toURI().getPath(); - - JettyHttpComponent jetty = getContext().getComponent("jetty", JettyHttpComponent.class); - setSSLProps(jetty, path, pwd, pwd); - // 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"); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/InterfacesTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/InterfacesTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/InterfacesTest.java deleted file mode 100644 index d28af2f..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/InterfacesTest.java +++ /dev/null @@ -1,135 +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.net.Inet6Address; -import java.net.InetAddress; -import java.net.NetworkInterface; -import java.net.URL; -import java.util.Enumeration; - -import org.apache.camel.builder.RouteBuilder; -import org.junit.Test; - -public class InterfacesTest extends BaseJettyTest { - private static boolean isMacOS = System.getProperty("os.name").startsWith("Mac"); - private String remoteInterfaceAddress; - - private int port1; - private int port2; - private int port3; - private int port4; - - public InterfacesTest() throws IOException { - // Retrieve an address of some remote network interface - Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); - - while (remoteInterfaceAddress == null && interfaces.hasMoreElements()) { - NetworkInterface interfaze = interfaces.nextElement(); - Enumeration<InetAddress> addresses = interfaze.getInetAddresses(); - if (addresses.hasMoreElements()) { - InetAddress nextAddress = addresses.nextElement(); - if (nextAddress.isLoopbackAddress() || !nextAddress.isReachable(2000)) { - continue; - } - if (nextAddress instanceof Inet6Address) { - continue; - } else { - remoteInterfaceAddress = nextAddress.getHostAddress(); - } - } - } - } - - @Test - public void testLocalInterfaceHandled() throws IOException, InterruptedException { - int expectedMessages = (remoteInterfaceAddress != null) ? 3 : 2; - getMockEndpoint("mock:endpoint").expectedMessageCount(expectedMessages); - - URL localUrl = new URL("http://localhost:" + port1 + "/testRoute"); - String localResponse = context.getTypeConverter().convertTo(String.class, localUrl.openStream()); - assertEquals("local", localResponse); - - if (!isMacOS) { - localUrl = new URL("http://127.0.0.1:" + port2 + "/testRoute"); - } else { - localUrl = new URL("http://localhost:" + port2 + "/testRoute"); - } - localResponse = context.getTypeConverter().convertTo(String.class, localUrl.openStream()); - assertEquals("local-differentPort", localResponse); - - if (remoteInterfaceAddress != null) { - URL url = new URL("http://" + remoteInterfaceAddress + ":" + port3 + "/testRoute"); - String remoteResponse = context.getTypeConverter().convertTo(String.class, url.openStream()); - assertEquals("remote", remoteResponse); - } - - assertMockEndpointsSatisfied(); - } - - @Test - public void testAllInterfaces() throws Exception { - int expectedMessages = (remoteInterfaceAddress != null) ? 2 : 1; - getMockEndpoint("mock:endpoint").expectedMessageCount(expectedMessages); - - URL localUrl = new URL("http://localhost:" + port4 + "/allInterfaces"); - String localResponse = context.getTypeConverter().convertTo(String.class, localUrl.openStream()); - assertEquals("allInterfaces", localResponse); - - if (remoteInterfaceAddress != null) { - URL url = new URL("http://" + remoteInterfaceAddress + ":" + port4 + "/allInterfaces"); - String remoteResponse = context.getTypeConverter().convertTo(String.class, url.openStream()); - assertEquals("allInterfaces", remoteResponse); - } - - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - - @Override - public void configure() throws Exception { - port1 = getNextPort(); - port2 = getNextPort(port1 + 1); - port3 = getNextPort(port2 + 1); - port4 = getNextPort(port3 + 1); - - from("jetty:http://localhost:" + port1 + "/testRoute") - .setBody().constant("local") - .to("mock:endpoint"); - - from("jetty:http://localhost:" + port2 + "/testRoute") - .setBody().constant("local-differentPort") - .to("mock:endpoint"); - - if (remoteInterfaceAddress != null) { - from("jetty:http://" + remoteInterfaceAddress + ":" + port3 + "/testRoute") - .setBody().constant("remote") - .to("mock:endpoint"); - } - - from("jetty:http://0.0.0.0:" + port4 + "/allInterfaces") - .setBody().constant("allInterfaces") - .to("mock:endpoint"); - - } - }; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCallHttpThenExceptionTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCallHttpThenExceptionTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCallHttpThenExceptionTest.java deleted file mode 100644 index 7468083..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCallHttpThenExceptionTest.java +++ /dev/null @@ -1,71 +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 JettyCallHttpThenExceptionTest extends BaseJettyTest { - - @Test - public void testJettyCallHttpThenException() throws Exception { - getMockEndpoint("mock:foo").expectedBodiesReceived("World"); - getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World"); - - Exchange reply = template.request("http://localhost:{{port}}/myserver?throwExceptionOnFailure=false", new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getIn().setBody("World"); - } - }); - - assertMockEndpointsSatisfied(); - - assertNotNull(reply); - assertTrue(reply.getOut().getBody(String.class).startsWith("java.lang.IllegalArgumentException: I cannot do this")); - assertEquals(500, reply.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE)); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/myserver") - .to("log:A") - // remove http headers before and after invoking http service - .removeHeaders("CamelHttp*") - .to("http://localhost:{{port}}/other") - .removeHeaders("CamelHttp*") - .to("mock:bar") - // now just force an exception immediately - .throwException(new IllegalArgumentException("I cannot do this")); - - from("jetty://http://localhost:{{port}}/other") - .convertBodyTo(String.class) - .to("log:C") - .to("mock:foo") - .transform().simple("Bye ${body}"); - } - }; - } - -} \ 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/JettyCamelHttpUrlCBRTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCamelHttpUrlCBRTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCamelHttpUrlCBRTest.java deleted file mode 100644 index 7e48c9f..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyCamelHttpUrlCBRTest.java +++ /dev/null @@ -1,55 +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.builder.RouteBuilder; -import org.junit.Test; - -public class JettyCamelHttpUrlCBRTest extends BaseJettyTest { - - @Test - public void testCamelHttpUrl() throws Exception { - getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World"); - getMockEndpoint("mock:foo").expectedHeaderReceived("beer", "yes"); - getMockEndpoint("mock:foo").expectedHeaderReceived(Exchange.HTTP_METHOD, "POST"); - getMockEndpoint("mock:foo").expectedHeaderReceived(Exchange.HTTP_URL, "http://localhost:" + getPort() + "/foo"); - getMockEndpoint("mock:foo").expectedHeaderReceived(Exchange.HTTP_URI, "/foo"); - getMockEndpoint("mock:foo").expectedHeaderReceived(Exchange.HTTP_QUERY, "beer=yes"); - getMockEndpoint("mock:foo").expectedHeaderReceived(Exchange.HTTP_PATH, ""); - - String out = template.requestBody("http://localhost:{{port}}/foo?beer=yes", "Hello World", String.class); - assertEquals("Bye World", out); - - assertMockEndpointsSatisfied(); - } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("jetty:http://0.0.0.0:{{port}}/foo") - .filter().simple("${header.CamelHttpUrl} contains 'foo'") - .to("mock:foo") - .end() - .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/JettyComponentSpringConfiguredTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.java deleted file mode 100644 index 7814e02..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.java +++ /dev/null @@ -1,48 +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.spring.CamelSpringTestSupport; -import org.junit.Ignore; -import org.junit.Test; -import org.springframework.context.support.AbstractApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -/** - * - */ -public class JettyComponentSpringConfiguredTest extends CamelSpringTestSupport { - - @Override - protected boolean useJmx() { - return true; - } - - @Override - protected AbstractApplicationContext createApplicationContext() { - return new ClassPathXmlApplicationContext("org/apache/camel/component/jetty/JettyComponentSpringConfiguredTest.xml"); - } - - @Test - @Ignore("run manual test") - public void testJetty2() throws Exception { - assertNotNull("Should have jetty2 component", context.hasComponent("jetty2")); - - String reply = template.requestBody("jetty2:http://localhost:9090/myapp", "Camel", String.class); - assertEquals("Hello Camel", reply); - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/0d96e56d/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentBasedRouteTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentBasedRouteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentBasedRouteTest.java deleted file mode 100644 index 2a60a34..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentBasedRouteTest.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.builder.RouteBuilder; -import org.apache.camel.component.mock.MockEndpoint; -import org.junit.Test; - -/** - * Unit test with a simple route test. - */ -public class JettyContentBasedRouteTest extends BaseJettyTest { - - private String serverUri = "http://localhost:" + getPort() + "/myservice"; - - @Test - public void testSendOne() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:one"); - - mock.expectedHeaderReceived("one", "true"); - - template.requestBody(serverUri + "?one=true", null, Object.class); - - assertMockEndpointsSatisfied(); - } - - @Test - public void testSendOther() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:other"); - - mock.expectedHeaderReceived("two", "true"); - - template.requestBody(serverUri + "?two=true", null, Object.class); - - assertMockEndpointsSatisfied(); - } - - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - public void configure() throws Exception { - // START SNIPPET: e1 - from("jetty:" + serverUri) - .choice() - .when().simple("${header.one}").to("mock:one") - .otherwise() - .to("mock:other"); - // 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/JettyContentTypeTest.java ---------------------------------------------------------------------- diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java deleted file mode 100644 index d2262a8..0000000 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyContentTypeTest.java +++ /dev/null @@ -1,110 +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.builder.RouteBuilder; -import org.apache.camel.util.ExchangeHelper; -import org.apache.camel.util.MessageHelper; -import org.junit.Test; - -/** - * Unit test for content-type - */ -public class JettyContentTypeTest extends BaseJettyTest { - - protected void sendMessageWithContentType(String charset, boolean usingGZip) { - Endpoint endpoint = context.getEndpoint("http://localhost:{{port}}/myapp/myservice"); - Exchange exchange = endpoint.createExchange(); - exchange.getIn().setBody("<order>123</order>"); - exchange.getIn().setHeader("User", "Claus"); - exchange.getIn().setHeader("SOAPAction", "test"); - if (charset == null) { - exchange.getIn().setHeader("Content-Type", "text/xml"); - } else { - exchange.getIn().setHeader("Content-Type", "text/xml; charset=" + charset); - } - if (usingGZip) { - exchange.getIn().setHeader(Exchange.CONTENT_ENCODING, "gzip"); - } - template.send(endpoint, exchange); - - String body = exchange.getOut().getBody(String.class); - assertEquals("<order>OK</order>", body); - assertEquals("Get a wrong content-type ", MessageHelper.getContentType(exchange.getOut()), "text/xml"); - } - - @Test - public void testSameContentType() throws Exception { - sendMessageWithContentType(null, false); - sendMessageWithContentType("UTF-8", false); - } - - @Test - public void testContentTypeWithGZipEncoding() throws Exception { - sendMessageWithContentType(null, true); - sendMessageWithContentType("UTF-8", true); - } - - @Test - public void testMixedContentType() throws Exception { - Endpoint endpoint = context.getEndpoint("http://localhost:{{port}}/myapp/myservice"); - Exchange exchange = endpoint.createExchange(); - exchange.getIn().setBody("<order>123</order>"); - exchange.getIn().setHeader("Content-Type", "text/xml"); - template.send(endpoint, exchange); - - String body = exchange.getOut().getBody(String.class); - assertEquals("FAIL", body); - assertEquals("Get a wrong content-type ", MessageHelper.getContentType(exchange.getOut()), "text/plain"); - } - - @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 { - String user = exchange.getIn().getHeader("User", String.class); - String contentType = ExchangeHelper.getContentType(exchange); - String body = exchange.getIn().getBody(String.class); - String encoding = exchange.getIn().getHeader(Exchange.CONTENT_ENCODING, String.class); - if (encoding != null) { - exchange.getOut().setHeader(Exchange.CONTENT_ENCODING, encoding); - } - if ("Claus".equals(user) && contentType.startsWith("text/xml") && body.equals("<order>123</order>")) { - assertEquals("test", exchange.getIn().getHeader("SOAPAction", String.class)); - if (contentType.endsWith("UTF-8")) { - assertEquals("Get a wrong charset name.", exchange.getProperty(Exchange.CHARSET_NAME, String.class), "UTF-8"); - } - exchange.getOut().setBody("<order>OK</order>"); - exchange.getOut().setHeader("Content-Type", "text/xml"); - } else { - exchange.getOut().setBody("FAIL"); - exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "text/plain"); - } - } - } - -} \ No newline at end of file