You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/05/24 09:41:14 UTC
camel git commit: CAMEL-11312: camel-undertow - Rest-DSL should
support OPTIONS
Repository: camel
Updated Branches:
refs/heads/master 2b9caff09 -> 38bc5a91a
CAMEL-11312: camel-undertow - Rest-DSL should support OPTIONS
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/38bc5a91
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/38bc5a91
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/38bc5a91
Branch: refs/heads/master
Commit: 38bc5a91ab9d88f3571531711bd104075c4c6dc6
Parents: 2b9caff
Author: Claus Ibsen <da...@apache.org>
Authored: Wed May 24 11:41:01 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed May 24 11:41:01 2017 +0200
----------------------------------------------------------------------
.../component/undertow/UndertowComponent.java | 18 +++++++++++++-----
.../component/undertow/UndertowConsumer.java | 5 ++++-
.../rest/RestUndertowHttpOptionsTest.java | 10 ++++------
3 files changed, 21 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/38bc5a91/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
index bdb7616..ff522f7 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
@@ -198,10 +198,23 @@ public class UndertowComponent extends DefaultComponent implements RestConsumerF
}
}
+ boolean explicitOptions = true;
+ // must use upper case for restrict
+ String restrict = verb.toUpperCase(Locale.US);
+ // allow OPTIONS in rest-dsl to allow clients to call the API and have responses with ALLOW headers
+ if (!restrict.contains("OPTIONS")) {
+ restrict += ",OPTIONS";
+ // this is not an explicit OPTIONS path in the rest-dsl
+ explicitOptions = false;
+ }
+
boolean cors = config.isEnableCORS();
if (cors) {
// allow HTTP Options as we want to handle CORS in rest-dsl
map.put("optionsEnabled", "true");
+ } else if (explicitOptions) {
+ // the rest-dsl is using OPTIONS
+ map.put("optionsEnabled", "true");
}
String query = URISupport.createQueryString(map);
@@ -213,11 +226,6 @@ public class UndertowComponent extends DefaultComponent implements RestConsumerF
url = "undertow:%s://%s:%s/%s?matchOnUriPrefix=false&httpMethodRestrict=%s";
}
- // must use upper case for restrict
- String restrict = verb.toUpperCase(Locale.US);
- if (cors) {
- restrict += ",OPTIONS";
- }
// get the endpoint
url = String.format(url, scheme, host, port, path, restrict);
http://git-wip-us.apache.org/repos/asf/camel/blob/38bc5a91/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
index 1f89a54..f57286d 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
@@ -91,7 +91,10 @@ public class UndertowConsumer extends DefaultConsumer implements HttpHandler {
if (Methods.OPTIONS.equals(requestMethod) && !getEndpoint().isOptionsEnabled()) {
String allowedMethods;
if (getEndpoint().getHttpMethodRestrict() != null) {
- allowedMethods = "OPTIONS," + getEndpoint().getHttpMethodRestrict();
+ allowedMethods = getEndpoint().getHttpMethodRestrict();
+ if (!allowedMethods.contains("OPTIONS")) {
+ allowedMethods = "OPTIONS," + allowedMethods;
+ }
} else {
allowedMethods = "GET,HEAD,POST,PUT,DELETE,TRACE,OPTIONS,CONNECT,PATCH";
}
http://git-wip-us.apache.org/repos/asf/camel/blob/38bc5a91/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpOptionsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpOptionsTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpOptionsTest.java
index d353be4..ebd7ce8 100644
--- a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpOptionsTest.java
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpOptionsTest.java
@@ -20,10 +20,8 @@ import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.undertow.BaseUndertowTest;
-import org.junit.Ignore;
import org.junit.Test;
-@Ignore("Not supported by camel-undertow yet")
public class RestUndertowHttpOptionsTest extends BaseUndertowTest {
@Test
@@ -36,13 +34,13 @@ public class RestUndertowHttpOptionsTest extends BaseUndertowTest {
});
assertEquals(200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
- assertEquals("OPTIONS,GET", exchange.getOut().getHeader("ALLOW"));
+ assertEquals("GET,OPTIONS", exchange.getOut().getHeader("ALLOW"));
assertEquals("", exchange.getOut().getBody(String.class));
exchange = fluentTemplate.to("undertow:http://localhost:" + getPort() + "/users/v1/123").withHeader(Exchange.HTTP_METHOD, "OPTIONS").send();
- assertEquals(200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
- assertEquals("OPTIONS,PUT", exchange.getOut().getHeader("ALLOW"));
- assertEquals("", exchange.getOut().getBody(String.class));
+ assertEquals(200, exchange.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE));
+ assertEquals("PUT,OPTIONS", exchange.getIn().getHeader("ALLOW"));
+ assertEquals("", exchange.getIn().getBody(String.class));
}
@Override