Repository: camel Updated Branches: refs/heads/master bf82a5ed1 -> 16d6fc385
CAMEL-10980: removed camel-undertow duplicate handler check Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7f789212 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7f789212 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7f789212 Branch: refs/heads/master Commit: 7f7892127b6cba06e69d20093caf12c7900c0618 Parents: ca9d0c1 Author: Scott Cranton <sc...@cranton.com> Authored: Fri Mar 10 12:26:36 2017 -0500 Committer: Claus Ibsen <davscl...@apache.org> Committed: Fri Mar 10 21:40:58 2017 +0100 ---------------------------------------------------------------------- .../undertow/handlers/CamelMethodHandler.java | 5 -- .../rest/RestUndertowHttpGetCorsTest.java | 53 ++++++++++++++++++-- 2 files changed, 48 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/7f789212/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/handlers/CamelMethodHandler.java ---------------------------------------------------------------------- diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/handlers/CamelMethodHandler.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/handlers/CamelMethodHandler.java index 26584b5..ed7eb93 100644 --- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/handlers/CamelMethodHandler.java +++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/handlers/CamelMethodHandler.java @@ -51,11 +51,6 @@ public class CamelMethodHandler implements HttpHandler { public synchronized void add(String[] methods, HttpHandler handler) { Map<String, HttpHandler> adding = new HashMap<String, HttpHandler>(); for (String method : methods) { - HttpHandler existing = methodMap.get(method); - if (methodMap.get(method) != null) { - throw new IllegalArgumentException(String.format( - "Duplicate handler for a method '%s': '%s', '%s'", method, existing, handler)); - } adding.put(method, handler); } methodMap.putAll(adding); http://git-wip-us.apache.org/repos/asf/camel/blob/7f789212/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetCorsTest.java ---------------------------------------------------------------------- diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetCorsTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetCorsTest.java index c54fbef..562188b 100644 --- a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetCorsTest.java +++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetCorsTest.java @@ -26,9 +26,9 @@ import org.junit.Test; public class RestUndertowHttpGetCorsTest extends BaseUndertowTest { @Test - public void testCors() throws Exception { + public void testCorsGet() throws Exception { // send OPTIONS first which should not be routed - getMockEndpoint("mock:input").expectedMessageCount(0); + getMockEndpoint("mock:inputGet").expectedMessageCount(0); Exchange out = template.request("http://localhost:" + getPort() + "/users/123/basic", new Processor() { @Override @@ -45,11 +45,45 @@ public class RestUndertowHttpGetCorsTest extends BaseUndertowTest { assertMockEndpointsSatisfied(); resetMocks(); - getMockEndpoint("mock:input").expectedMessageCount(1); + getMockEndpoint("mock:inputGet").expectedMessageCount(1); // send GET request which should be routed - String out2 = template.requestBody("http://localhost:" + getPort() + "/users/123/basic", null, String.class); + String out2 = fluentTemplate.to("http://localhost:" + getPort() + "/users/123/basic") + .withHeader(Exchange.HTTP_METHOD, "GET") + .request(String.class); + assertEquals("123;Donald Duck", out2); + + assertMockEndpointsSatisfied(); + } + + @Test + public void testCorsPut() throws Exception { + // send OPTIONS first which should not be routed + getMockEndpoint("mock:inputPut").expectedMessageCount(0); + + Exchange out = template.request("http://localhost:" + getPort() + "/users/123/basic", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setHeader(Exchange.HTTP_METHOD, "OPTIONS"); + } + }); + + assertEquals(RestConfiguration.CORS_ACCESS_CONTROL_ALLOW_ORIGIN, out.getOut().getHeader("Access-Control-Allow-Origin")); + assertEquals(RestConfiguration.CORS_ACCESS_CONTROL_ALLOW_METHODS, out.getOut().getHeader("Access-Control-Allow-Methods")); + assertEquals(RestConfiguration.CORS_ACCESS_CONTROL_ALLOW_HEADERS, out.getOut().getHeader("Access-Control-Allow-Headers")); + assertEquals(RestConfiguration.CORS_ACCESS_CONTROL_MAX_AGE, out.getOut().getHeader("Access-Control-Max-Age")); + + assertMockEndpointsSatisfied(); + + resetMocks(); + getMockEndpoint("mock:inputPut").expectedMessageCount(1); + + // send PUT request which should be routed + + String out2 = fluentTemplate.to("http://localhost:" + getPort() + "/users/123/basic") + .withHeader(Exchange.HTTP_METHOD, "PUT") + .request(String.class); assertEquals("123;Donald Duck", out2); assertMockEndpointsSatisfied(); @@ -67,7 +101,16 @@ public class RestUndertowHttpGetCorsTest extends BaseUndertowTest { rest("/users/") .get("{id}/basic") .route() - .to("mock:input") + .to("mock:inputGet") + .process(new Processor() { + public void process(Exchange exchange) throws Exception { + String id = exchange.getIn().getHeader("id", String.class); + exchange.getOut().setBody(id + ";Donald Duck"); + } + }).endRest() + .put("{id}/basic") + .route() + .to("mock:inputPut") .process(new Processor() { public void process(Exchange exchange) throws Exception { String id = exchange.getIn().getHeader("id", String.class);