Repository: camel Updated Branches: refs/heads/master 1300aa625 -> 36fdb1e5a
CAMEL-9129. Add OptionsVerbDefinition. Extend Rest & VerbDefintion to include OPTIONS. Create unit test Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/36fdb1e5 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/36fdb1e5 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/36fdb1e5 Branch: refs/heads/master Commit: 36fdb1e5af8bdc1dd610f7cb9c3f58cebf2cb3c6 Parents: 1300aa6 Author: Charles Moulliard <cmoulli...@apache.org> Authored: Sun Sep 13 17:57:34 2015 +0200 Committer: Charles Moulliard <cmoulli...@apache.org> Committed: Sun Sep 13 18:01:49 2015 +0200 ---------------------------------------------------------------------- .../camel/model/rest/OptionsVerbDefinition.java | 33 +++++++++ .../apache/camel/model/rest/RestDefinition.java | 10 +++ .../apache/camel/model/rest/VerbDefinition.java | 2 + .../component/rest/FromRestOptionsTest.java | 77 ++++++++++++++++++++ 4 files changed, 122 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/36fdb1e5/camel-core/src/main/java/org/apache/camel/model/rest/OptionsVerbDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/OptionsVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/OptionsVerbDefinition.java new file mode 100644 index 0000000..11a121c --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/model/rest/OptionsVerbDefinition.java @@ -0,0 +1,33 @@ +/** + * 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.model.rest; + +import org.apache.camel.spi.Metadata; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Rest OPTIONS command + */ +@Metadata(label = "rest") +@XmlRootElement(name = "options") +@XmlAccessorType(XmlAccessType.FIELD) +public class OptionsVerbDefinition extends VerbDefinition { + +} http://git-wip-us.apache.org/repos/asf/camel/blob/36fdb1e5/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java index 1af77fc..4c5c044 100644 --- a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java @@ -213,6 +213,14 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> return addVerb("head", uri); } + public RestDefinition options() { + return addVerb("options", null); + } + + public RestDefinition options(String uri) { + return addVerb("options", uri); + } + public RestDefinition verb(String verb) { return addVerb(verb, null); } @@ -480,6 +488,8 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> answer = new HeadVerbDefinition(); } else if ("put".equals(verb)) { answer = new PutVerbDefinition(); + } else if ("options".equals(verb)) { + answer = new OptionsVerbDefinition(); } else { answer = new VerbDefinition(); answer.setMethod(verb); http://git-wip-us.apache.org/repos/asf/camel/blob/36fdb1e5/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java index 90a32ce..7e119c5 100644 --- a/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java @@ -369,6 +369,8 @@ public class VerbDefinition extends OptionalIdentifiedDefinition<VerbDefinition> return "delete"; } else if (this instanceof HeadVerbDefinition) { return "head"; + } else if (this instanceof OptionsVerbDefinition) { + return "options"; } else { return method; } http://git-wip-us.apache.org/repos/asf/camel/blob/36fdb1e5/camel-core/src/test/java/org/apache/camel/component/rest/FromRestOptionsTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestOptionsTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestOptionsTest.java new file mode 100644 index 0000000..b8409c3 --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestOptionsTest.java @@ -0,0 +1,77 @@ +/** + * 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.rest; + +import org.apache.camel.ContextTestSupport; +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.model.ToDefinition; +import org.apache.camel.model.rest.OptionsVerbDefinition; +import org.apache.camel.model.rest.RestDefinition; +import org.apache.camel.model.rest.RestParamType; +import org.apache.camel.spi.RestConfiguration; + +import java.util.Arrays; +import java.util.List; + +public class FromRestOptionsTest extends ContextTestSupport { + + final static String ALLOWS = "HEAD,GET,PUT,POST,DELETE,OPTIONS"; + + @Override + protected JndiRegistry createRegistry() throws Exception { + JndiRegistry jndi = super.createRegistry(); + jndi.bind("dummy-rest", new DummyRestConsumerFactory()); + return jndi; + } + + public void testRestOptionsModel() throws Exception { + + RestDefinition rest = context.getRestDefinitions().get(0); + assertNotNull(rest); + assertEquals("/say/hello", rest.getPath()); + assertEquals(1, rest.getVerbs().size()); + assertIsInstanceOf(OptionsVerbDefinition.class, rest.getVerbs().get(0)); + + Exchange out = template.request("seda:options-say-hello", new Processor() { + @Override + public void process(Exchange exchange) throws Exception { + exchange.getIn().setBody("Me"); + } + }); + assertMockEndpointsSatisfied(); + assertNotNull(out); + assertEquals(out.getOut().getHeader("Allow"), ALLOWS); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + restConfiguration().host("localhost"); + rest("/say/hello") + .options() + .route() + .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200)) + .setHeader("Allow", constant(ALLOWS)); + } + }; + } +}