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 2014/07/20 08:53:07 UTC
[01/33] git commit: CAMEL-7354: rest-binding in camel-core
Repository: camel
Updated Branches:
refs/heads/master d6476426b -> b08ff977a
CAMEL-7354: rest-binding in camel-core
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/08d68bca
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/08d68bca
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/08d68bca
Branch: refs/heads/master
Commit: 08d68bcaad6c74404f78db0197210ac69928b32c
Parents: d647642
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 1 13:01:13 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:46 2014 +0200
----------------------------------------------------------------------
.../restbinding/RestBindingComponent.java | 48 ++++++++++++
.../restbinding/RestBindingConsumer.java | 29 +++++++
.../restbinding/RestBindingEndpoint.java | 81 ++++++++++++++++++++
3 files changed, 158 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/08d68bca/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
new file mode 100644
index 0000000..62a5f84
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
@@ -0,0 +1,48 @@
+/**
+ * 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.restbinding;
+
+import java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.util.ObjectHelper;
+
+public class RestBindingComponent extends UriEndpointComponent {
+
+ public RestBindingComponent() {
+ super(RestBindingEndpoint.class);
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ RestBindingEndpoint answer = new RestBindingEndpoint(uri, this);
+ setProperties(answer, parameters);
+
+ if (!remaining.contains(":")) {
+ throw new IllegalArgumentException("Invalid syntax. Must be rest-binding:verb:path");
+ }
+
+ String verb = ObjectHelper.before(remaining, ":");
+ String path = ObjectHelper.after(remaining, ":");
+
+ answer.setVerb(verb);
+ answer.setPath(path);
+
+ return answer;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/08d68bca/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingConsumer.java b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingConsumer.java
new file mode 100644
index 0000000..4480bf4
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingConsumer.java
@@ -0,0 +1,29 @@
+/**
+ * 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.restbinding;
+
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultConsumer;
+
+public class RestBindingConsumer extends DefaultConsumer {
+
+ public RestBindingConsumer(RestBindingEndpoint endpoint, Processor processor) {
+ super(endpoint, processor);
+ }
+
+ // TODO: lookup which components support rest binding and create an endpoint and create the delegate consumer
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/08d68bca/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
new file mode 100644
index 0000000..df7c62f
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
@@ -0,0 +1,81 @@
+/**
+ * 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.restbinding;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+
+@UriEndpoint(scheme = "rest", consumerClass = RestBindingConsumer.class)
+public class RestBindingEndpoint extends DefaultEndpoint {
+
+ @UriParam
+ private String verb;
+ @UriParam
+ private String path;
+ @UriParam
+ private String accept;
+
+ public RestBindingEndpoint(String endpointUri, Component component) {
+ super(endpointUri, component);
+ }
+
+ public String getVerb() {
+ return verb;
+ }
+
+ public void setVerb(String verb) {
+ this.verb = verb;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public String getAccept() {
+ return accept;
+ }
+
+ public void setAccept(String accept) {
+ this.accept = accept;
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ throw new UnsupportedOperationException("Producer not supported");
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ Consumer consumer = new RestBindingConsumer(this, processor);
+ configureConsumer(consumer);
+ return consumer;
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return true;
+ }
+}
[03/33] git commit: CAMEL-7354: rest-binding DSL in java and xml.
Posted by da...@apache.org.
CAMEL-7354: rest-binding DSL in java and xml.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/71eaf52b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/71eaf52b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/71eaf52b
Branch: refs/heads/master
Commit: 71eaf52b8d591b7f733fb911bef54973e52be719
Parents: 2f19857
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 1 14:27:36 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:47 2014 +0200
----------------------------------------------------------------------
.../resources/org/apache/camel/model/jaxb.index | 2 +-
.../DummyRestBindingCapableComponent.java | 4 ++
.../restbinding/SpringFromRestGetTest.java | 29 +++++++++++++++
.../restbinding/SpringFromRestGetTest.xml | 39 ++++++++++++++++++++
.../issues/AdviceWithTransactionIssueTest.xml | 8 ++--
5 files changed, 77 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/71eaf52b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
index 4afe1f1..61991d5 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
@@ -30,7 +30,7 @@ ExpressionSubElementDefinition
FilterDefinition
FinallyDefinition
FromDefinition
-RestFromDefinition
+FromRestDefinition
IdempotentConsumerDefinition
InOnlyDefinition
InOutDefinition
http://git-wip-us.apache.org/repos/asf/camel/blob/71eaf52b/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java
index 6374b70..cf3a4ae 100644
--- a/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java
+++ b/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java
@@ -28,6 +28,10 @@ import org.apache.camel.spi.RestBindingCapable;
public class DummyRestBindingCapableComponent extends DefaultComponent implements RestBindingCapable {
+ public void enlist() {
+ getCamelContext().addComponent("dummy-rest", this);
+ }
+
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
return null;
http://git-wip-us.apache.org/repos/asf/camel/blob/71eaf52b/components/camel-spring/src/test/java/org/apache/camel/component/restbinding/SpringFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/restbinding/SpringFromRestGetTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/restbinding/SpringFromRestGetTest.java
new file mode 100644
index 0000000..371721c
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/restbinding/SpringFromRestGetTest.java
@@ -0,0 +1,29 @@
+/**
+ * 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.restbinding;
+
+import org.apache.camel.CamelContext;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringFromRestGetTest extends FromRestGetTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/component/restbinding/SpringFromRestGetTest.xml");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/71eaf52b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
new file mode 100644
index 0000000..0626079
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- use a dummy rest component and enlist it in the CamelContext -->
+ <bean id="dummy-rest" class="org.apache.camel.component.restbinding.DummyRestBindingCapableComponent"
+ init-method="enlist"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <route id="foo">
+ <fromRest verb="get" path="/hello"/>
+ <to uri="mock:foo"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+ </camelContext>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/71eaf52b/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml
index ebab224..1d4bcb2 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml
@@ -25,11 +25,11 @@
<import resource="../interceptor/transactionalClientDataSource.xml"/>
<camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/spring">
-
<route id="route1">
- <get path="/customer/:name"/>
- <to uri="bean:customerService?method=findCustomer($header.name})"/>
+ <from uri="seda:start"/>
+ <transacted/>
+ <to id="mock-a" uri="mock:a"/>
+ <to id="mock-b" uri="mock:b"/>
</route>
-
</camelContext>
</beans>
[16/33] git commit: CAMEL-7354: Migrating rest DSL to be separated
from regular Camel routes.
Posted by da...@apache.org.
CAMEL-7354: Migrating rest DSL to be separated from regular Camel routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/31269fd9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/31269fd9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/31269fd9
Branch: refs/heads/master
Commit: 31269fd9da5477e8d1bd109fa46979bcdb3c40de
Parents: aff5987
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 2 19:53:56 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:50 2014 +0200
----------------------------------------------------------------------
.../camel/component/restbinding/FromRestGetTest.java | 15 +++++++++++++--
.../camel/management/ManagedFromRestGetTest.java | 14 ++++++++------
.../component/restbinding/SpringFromRestGetTest.xml | 2 +-
.../component/restbinding/FromRestGetTest.xml | 2 +-
4 files changed, 23 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/31269fd9/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
index 72798fc..da8a765 100644
--- a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
@@ -32,7 +32,7 @@ public class FromRestGetTest extends ContextTestSupport {
return jndi;
}
- public void testFromRestModel() {
+ public void testFromRestModel() throws Exception {
assertEquals(2 + 3, context.getRoutes().size());
RestDefinition rest = context.getRestDefinitions().get(0);
@@ -51,6 +51,17 @@ public class FromRestGetTest extends ContextTestSupport {
assertEquals("direct:bye", to.getUri());
assertEquals(null, path.getVerbs().get(2).getUri());
+
+ // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
+
+ getMockEndpoint("mock:update").expectedMessageCount(1);
+ template.sendBody("seda:post-say", "I was here");
+ assertMockEndpointsSatisfied();
+
+ String out = template.requestBody("seda:get-say-hello", "Me", String.class);
+ assertEquals("Hello World", out);
+ String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
+ assertEquals("Bye World", out2);
}
@Override
@@ -62,7 +73,7 @@ public class FromRestGetTest extends ContextTestSupport {
.path("/say")
.get("/hello").to("direct:hello")
.get("/bye").to("direct:bye")
- .post().to("seda:update");
+ .post().to("mock:update");
from("direct:hello")
.transform().constant("Hello World");
http://git-wip-us.apache.org/repos/asf/camel/blob/31269fd9/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
index 17060bf..43c9d37 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
@@ -19,17 +19,19 @@ package org.apache.camel.management;
import javax.management.MBeanServer;
import javax.management.ObjectName;
+import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.restbinding.DummyRestConsumerFactory;
-import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.SimpleRegistry;
public class ManagedFromRestGetTest extends ManagementTestSupport {
@Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry jndi = super.createRegistry();
- jndi.bind("dummy-test", new DummyRestConsumerFactory());
- return jndi;
+ protected CamelContext createCamelContext() throws Exception {
+ SimpleRegistry registry = new SimpleRegistry();
+ registry.put("dummy-test", new DummyRestConsumerFactory());
+ return new DefaultCamelContext(registry);
}
public void testFromRestModel() throws Exception {
@@ -69,7 +71,7 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
.path("/say")
.get("/hello").to("direct:hello")
.get("/bye").to("direct:bye")
- .post().to("seda:update");
+ .post().to("mock:update");
from("direct:hello")
.transform().constant("Hello World");
http://git-wip-us.apache.org/repos/asf/camel/blob/31269fd9/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
index 156a2c1..8929e75 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
@@ -36,7 +36,7 @@
<to uri="direct:bye"/>
</get>
<post>
- <to uri="seda:update"/>
+ <to uri="mock:update"/>
</post>
</path>
</rest>
http://git-wip-us.apache.org/repos/asf/camel/blob/31269fd9/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
index 2ba7b41..f5e83f5 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
@@ -34,7 +34,7 @@
<to uri="direct:bye"/>
</get>
<post>
- <to uri="seda:update"/>
+ <to uri="mock:update"/>
</post>
</path>
</rest>
[06/33] git commit: CAMEL-7354: Migrating rest DSL to be separated
from regular Camel routes.
Posted by da...@apache.org.
CAMEL-7354: Migrating rest DSL to be separated from regular Camel routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0dd457a6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0dd457a6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0dd457a6
Branch: refs/heads/master
Commit: 0dd457a68adf3e01c7b55621efa71e6df3e5750a
Parents: 3e2c6fc
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 2 13:35:16 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:48 2014 +0200
----------------------------------------------------------------------
.../component/restbinding/FromRestGetTest.java | 52 ++++++++++++++++++
.../component/restbinding/FromRestGetTest.xml | 56 ++++++++++++++++++++
2 files changed, 108 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0dd457a6/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java
new file mode 100644
index 0000000..ce3b3b9
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java
@@ -0,0 +1,52 @@
+/**
+ * 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.test.blueprint.component.restbinding;
+
+import org.apache.camel.model.rest.PathDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
+import org.junit.Test;
+
+public class FromRestGetTest extends CamelBlueprintTestSupport {
+
+ @Override
+ protected String getBlueprintDescriptor() {
+ return "org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml";
+ }
+
+ @Test
+ public void testFromRestModel() {
+ assertEquals(2, context.getRoutes().size());
+
+ RestDefinition rest = context.getRestDefinitions().get(0);
+ assertNotNull(rest);
+
+ PathDefinition path = rest.getPaths().get(0);
+ assertNotNull(0);
+ assertEquals("/say", path.getUri());
+
+ assertEquals("/hello", path.getVerbs().get(0).getUri());
+ assertEquals("direct:hello", path.getVerbs().get(0).getTo().getUri());
+
+ assertEquals("/bye", path.getVerbs().get(1).getUri());
+ assertEquals("direct:bye", path.getVerbs().get(1).getTo().getUri());
+
+ assertEquals(null, path.getVerbs().get(2).getUri());
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/0dd457a6/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
new file mode 100644
index 0000000..806124b
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <!-- use a dummy rest component for the rest engine -->
+ <!--<bean id="dummy-rest" class="org.apache.camel.component.restbinding.DummyRestBindingCapableComponent"/>-->
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+ <rest component="dummy-rest" routeId="myRestRoute">
+ <path uri="/say">
+ <get uri="/hello">
+ <to uri="direct:hello"/>
+ </get>
+ <get uri="/bye">
+ <to uri="direct:bye"/>
+ </get>
+ <post>
+ <to uri="seda:update"/>
+ </post>
+ </path>
+ </rest>
+
+ <route id="helloRoute">
+ <from uri="direct:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </route>
+ <route id="byeRoute">
+ <from uri="direct:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+ </camelContext>
+
+</blueprint>
\ No newline at end of file
[14/33] git commit: CAMEL-7354: include accept in the rest DSL
Posted by da...@apache.org.
CAMEL-7354: include accept in the rest DSL
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d3b5059c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d3b5059c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d3b5059c
Branch: refs/heads/master
Commit: d3b5059c0058a95ce6a4609feabede2776ac3b35
Parents: 3862067
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 15 13:27:14 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:50 2014 +0200
----------------------------------------------------------------------
.../org/apache/camel/model/rest/PathDefinition.java | 12 ++++++++++++
.../org/apache/camel/model/rest/VerbDefinition.java | 11 +++++++++++
.../apache/camel/component/rest/FromRestGetTest.java | 3 ++-
.../camel/component/rest/SpringFromRestGetTest.xml | 2 +-
.../test/blueprint/component/rest/FromRestGetTest.xml | 2 +-
5 files changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d3b5059c/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
index 2c29b2f..c41a610 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -89,6 +89,18 @@ public class PathDefinition {
return this;
}
+ public PathDefinition accept(String accept) {
+ // add to last verb
+ if (getVerbs().isEmpty()) {
+ throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
+ }
+
+ VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
+ verb.setAccept(accept);
+
+ return this;
+ }
+
public PathDefinition to(String url) {
// add to last verb
if (getVerbs().isEmpty()) {
http://git-wip-us.apache.org/repos/asf/camel/blob/d3b5059c/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 c486045..6dea3de 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
@@ -39,6 +39,9 @@ public class VerbDefinition {
@XmlAttribute
private String uri;
+ @XmlAttribute
+ private String accept;
+
@XmlElementRef
private List<ProcessorDefinition<?>> outputs = new ArrayList<ProcessorDefinition<?>>();
@@ -66,6 +69,14 @@ public class VerbDefinition {
this.uri = uri;
}
+ public String getAccept() {
+ return accept;
+ }
+
+ public void setAccept(String accept) {
+ this.accept = accept;
+ }
+
public List<ProcessorDefinition<?>> getOutputs() {
return outputs;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/d3b5059c/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index bc16772..a21cbae 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -51,6 +51,7 @@ public class FromRestGetTest extends ContextTestSupport {
assertEquals("direct:hello", to.getUri());
assertEquals("/bye", path.getVerbs().get(1).getUri());
+ assertEquals("application/json", path.getVerbs().get(1).getAccept());
to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
assertEquals("direct:bye", to.getUri());
@@ -76,7 +77,7 @@ public class FromRestGetTest extends ContextTestSupport {
rest()
.path("/say")
.get("/hello").routeId("hello").to("direct:hello")
- .get("/bye").routeId("bye").to("direct:bye")
+ .get("/bye").accept("application/json").routeId("bye").to("direct:bye")
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/d3b5059c/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
index f33e99d..918085f 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
@@ -32,7 +32,7 @@
<get uri="/hello" routeId="hello">
<to uri="direct:hello"/>
</get>
- <get uri="/bye" routeId="bye">
+ <get uri="/bye" accept="application/json" routeId="bye">
<to uri="direct:bye"/>
</get>
<post>
http://git-wip-us.apache.org/repos/asf/camel/blob/d3b5059c/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
index 0ee3624..ff38c7a 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
@@ -30,7 +30,7 @@
<get uri="/hello" routeId="hello">
<to uri="direct:hello"/>
</get>
- <get uri="/bye" routeId="bye">
+ <get uri="/bye" accept="application/json" routeId="bye">
<to uri="direct:bye"/>
</get>
<post>
[13/33] git commit: CAMEL-7354: Prepare for rest DSL embedding routes.
Posted by da...@apache.org.
CAMEL-7354: Prepare for rest DSL embedding routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/96a521de
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/96a521de
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/96a521de
Branch: refs/heads/master
Commit: 96a521de7677d895230b9ef2b1b35b3db9edb414
Parents: d3b5059
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 15 13:40:16 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:50 2014 +0200
----------------------------------------------------------------------
.../camel/component/rest/FromRestGetTest.java | 6 +-
.../SpringFromRestGetEmbeddedRouteTest.java | 71 ++++++++++++++++++++
.../rest/SpringFromRestGetEmbeddedRouteTest.xml | 49 ++++++++++++++
3 files changed, 125 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/96a521de/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index a21cbae..f9076a6 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -32,8 +32,12 @@ public class FromRestGetTest extends ContextTestSupport {
return jndi;
}
+ protected int getExpectedNumberOfRoutes() {
+ return 2 + 3;
+ }
+
public void testFromRestModel() throws Exception {
- assertEquals(2 + 3, context.getRoutes().size());
+ assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
http://git-wip-us.apache.org/repos/asf/camel/blob/96a521de/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.java
new file mode 100644
index 0000000..daee273
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.CamelContext;
+import org.apache.camel.model.TransformDefinition;
+import org.apache.camel.model.rest.PathDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringFromRestGetEmbeddedRouteTest extends FromRestGetTest {
+
+ @Override
+ protected int getExpectedNumberOfRoutes() {
+ return 3;
+ }
+
+ public void testFromRestModel() throws Exception {
+ assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+
+ RestDefinition rest = context.getRestDefinitions().get(0);
+ assertNotNull(rest);
+
+ // we should have a hello and bye route
+ assertNotNull(context.getRouteDefinition("hello"));
+ assertNotNull(context.getRouteDefinition("bye"));
+
+ PathDefinition path = rest.getPaths().get(0);
+ assertNotNull(0);
+ assertEquals("/say", path.getUri());
+
+ assertEquals("/hello", path.getVerbs().get(0).getUri());
+ assertIsInstanceOf(TransformDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
+
+ assertEquals("/bye", path.getVerbs().get(1).getUri());
+ assertEquals("application/json", path.getVerbs().get(1).getAccept());
+
+ assertEquals(null, path.getVerbs().get(2).getUri());
+
+ // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
+
+ getMockEndpoint("mock:update").expectedMessageCount(1);
+ template.sendBody("seda:post-say", "I was here");
+ assertMockEndpointsSatisfied();
+
+ String out = template.requestBody("seda:get-say-hello", "Me", String.class);
+ assertEquals("Hello World", out);
+ String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
+ assertEquals("Bye World", out2);
+ }
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/96a521de/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
new file mode 100644
index 0000000..ed9bc34
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- use a dummy rest consumer factory for the rest engine -->
+ <bean id="dummy-rest" class="org.apache.camel.component.rest.DummyRestConsumerFactory"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <rest component="dummy-rest">
+ <path uri="/say">
+ <get uri="/hello" routeId="hello">
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </get>
+ <get uri="/bye" accept="application/json" routeId="bye">
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </get>
+ <post>
+ <to uri="mock:update"/>
+ </post>
+ </path>
+ </rest>
+ </camelContext>
+
+</beans>
[10/33] git commit: CAMEL-7354: Migrating rest DSL to be separated
from regular Camel routes.
Posted by da...@apache.org.
CAMEL-7354: Migrating rest DSL to be separated from regular Camel routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/aff59879
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/aff59879
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/aff59879
Branch: refs/heads/master
Commit: aff598798e6830c442cfd260e984c766eebfc7cc
Parents: 2ffb9a5
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 2 19:34:20 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:49 2014 +0200
----------------------------------------------------------------------
.../restbinding/RestBindingComponent.java | 21 --------
.../restbinding/RestBindingEndpoint.java | 54 +++++++++++++++++---
.../apache/camel/model/AggregateDefinition.java | 2 +-
.../apache/camel/model/ChoiceDefinition.java | 2 +-
.../org/apache/camel/model/ExpressionNode.java | 2 +-
.../apache/camel/model/ProcessorDefinition.java | 2 +-
.../apache/camel/model/rest/PathDefinition.java | 2 +-
.../apache/camel/model/rest/RestDefinition.java | 2 +-
.../apache/camel/model/rest/VerbDefinition.java | 25 ++++++---
.../apache/camel/spi/RestBindingCapable.java | 37 --------------
.../apache/camel/spi/RestConsumerFactory.java | 43 ++++++++++++++++
.../DummyRestBindingCapableComponent.java | 51 ------------------
.../restbinding/DummyRestConsumerFactory.java | 43 ++++++++++++++++
.../component/restbinding/FromRestGetTest.java | 20 ++++----
.../management/ManagedFromRestGetTest.java | 18 +++----
.../restbinding/SpringFromRestGetTest.xml | 4 +-
.../restbinding/DummyRestConsumerFactory.java | 43 ++++++++++++++++
.../component/restbinding/FromRestGetTest.java | 10 ++--
.../component/restbinding/FromRestGetTest.xml | 4 +-
19 files changed, 225 insertions(+), 160 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
index d24b72e..b10f06f 100644
--- a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
@@ -18,10 +18,8 @@ package org.apache.camel.component.restbinding;
import java.util.Map;
-import org.apache.camel.Component;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.UriEndpointComponent;
-import org.apache.camel.spi.RestBindingCapable;
import org.apache.camel.util.ObjectHelper;
public class RestBindingComponent extends UriEndpointComponent {
@@ -32,8 +30,6 @@ public class RestBindingComponent extends UriEndpointComponent {
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- preCheckConditions();
-
RestBindingEndpoint answer = new RestBindingEndpoint(uri, this);
setProperties(answer, parameters);
answer.setParameters(parameters);
@@ -51,21 +47,4 @@ public class RestBindingComponent extends UriEndpointComponent {
return answer;
}
-
- protected void preCheckConditions() throws Exception {
- if (lookupRestBindingCapableComponent() == null) {
- throw new IllegalStateException("There are no registered components in CamelContext that is RestBindingCapable");
- }
- }
-
- public RestBindingCapable lookupRestBindingCapableComponent() {
- for (String id : getCamelContext().getComponentNames()) {
- Component component = getCamelContext().getComponent(id);
- if (component instanceof RestBindingCapable) {
- return (RestBindingCapable) component;
- }
- }
- return null;
- }
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
index da6ce09..42595b2 100644
--- a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
@@ -17,12 +17,14 @@
package org.apache.camel.component.restbinding;
import java.util.Map;
+import java.util.Set;
+import org.apache.camel.Component;
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.camel.spi.RestBindingCapable;
+import org.apache.camel.spi.RestConsumerFactory;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
@@ -35,6 +37,8 @@ public class RestBindingEndpoint extends DefaultEndpoint {
private String path;
@UriParam
private String accept;
+ @UriParam
+ private String componentName;
private Map<String, Object> parameters;
@@ -71,6 +75,14 @@ public class RestBindingEndpoint extends DefaultEndpoint {
this.accept = accept;
}
+ public String getComponentName() {
+ return componentName;
+ }
+
+ public void setComponentName(String componentName) {
+ this.componentName = componentName;
+ }
+
public Map<String, Object> getParameters() {
return parameters;
}
@@ -86,16 +98,42 @@ public class RestBindingEndpoint extends DefaultEndpoint {
@Override
public Consumer createConsumer(Processor processor) throws Exception {
- // create the consumer directly from the component that supports rest binding
- // TODO: should we have a RestBindingConsumer class that delegates to the actual consumer?
- // TODO: what if there is 2+ RestBindingCapable components in the registry?
- RestBindingCapable component = getComponent().lookupRestBindingCapableComponent();
- if (component != null) {
- Consumer consumer = component.createConsumer(this, processor);
+ RestConsumerFactory factory = null;
+
+ if (getComponentName() != null) {
+ Component comp = getCamelContext().getComponent(getComponentName());
+ if (comp != null && comp instanceof RestConsumerFactory) {
+ factory = (RestConsumerFactory) comp;
+ } else {
+ throw new IllegalArgumentException("Component " + getComponentName() + " is not a RestConsumerFactory");
+ }
+ }
+
+ // try all components
+ if (factory == null) {
+ for (String name : getCamelContext().getComponentNames()) {
+ Component comp = getCamelContext().getComponent(name);
+ if (comp != null && comp instanceof RestConsumerFactory) {
+ factory = (RestConsumerFactory) comp;
+ break;
+ }
+ }
+ }
+
+ // lookup in registry
+ if (factory == null) {
+ Set<RestConsumerFactory> factories = getCamelContext().getRegistry().findByType(RestConsumerFactory.class);
+ if (factories != null && factories.size() == 1) {
+ factory = factories.iterator().next();
+ }
+ }
+
+ if (factory != null) {
+ Consumer consumer = factory.createConsumer(getCamelContext(), processor, getVerb(), getPath(), getAccept(), getParameters());
configureConsumer(consumer);
return consumer;
} else {
- throw new IllegalStateException("There are no registered components in CamelContext that is RestBindingCapable");
+ throw new IllegalStateException("Cannot find RestConsumerFactory in Registry or as a Component to use");
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java b/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
index e31743f..59c2104 100644
--- a/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
@@ -263,7 +263,7 @@ public class AggregateDefinition extends ProcessorDefinition<AggregateDefinition
}
@Override
- protected void configureChild(ProcessorDefinition<?> output) {
+ public void configureChild(ProcessorDefinition<?> output) {
if (expression != null && expression instanceof ExpressionClause) {
ExpressionClause<?> clause = (ExpressionClause<?>) expression;
if (clause.getExpressionType() != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java
index e8e31e4..202f86a 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ChoiceDefinition.java
@@ -227,7 +227,7 @@ public class ChoiceDefinition extends ProcessorDefinition<ChoiceDefinition> {
}
@Override
- protected void configureChild(ProcessorDefinition<?> output) {
+ public void configureChild(ProcessorDefinition<?> output) {
if (whenClauses == null || whenClauses.isEmpty()) {
return;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java b/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java
index ef64c2d..2e1f764 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ExpressionNode.java
@@ -121,7 +121,7 @@ public class ExpressionNode extends ProcessorDefinition<ExpressionNode> {
}
@Override
- protected void configureChild(ProcessorDefinition<?> output) {
+ public void configureChild(ProcessorDefinition<?> output) {
// reuse the logic from pre create processor
preCreateProcessor();
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 833457c..1503d3c 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -641,7 +641,7 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
*
* @param output the child to be added as output to this
*/
- protected void configureChild(ProcessorDefinition<?> output) {
+ public void configureChild(ProcessorDefinition<?> output) {
// noop
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
index bfa8d79..d646916 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -87,7 +87,7 @@ public class PathDefinition {
}
VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
- verb.setTo(new ToDefinition(url));
+ verb.addOutput(new ToDefinition(url));
return this;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/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 d63badc..db48564 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
@@ -90,7 +90,7 @@ public class RestDefinition {
RouteDefinition route = new RouteDefinition();
route.fromRest(from);
answer.add(route);
- route.getOutputs().add(verb.getTo());
+ route.getOutputs().addAll(verb.getOutputs());
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/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 388b4ea..5ef289e 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
@@ -16,13 +16,15 @@
*/
package org.apache.camel.model.rest;
+import java.util.ArrayList;
+import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
-import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.ProcessorDefinition;
@XmlRootElement(name = "verb")
@XmlAccessorType(XmlAccessType.FIELD)
@@ -34,8 +36,8 @@ public class VerbDefinition {
@XmlAttribute
private String uri;
- @XmlElementRef(required = false)
- private ToDefinition to;
+ @XmlElementRef
+ private List<ProcessorDefinition<?>> outputs = new ArrayList<ProcessorDefinition<?>>();
public String getMethod() {
return method;
@@ -53,12 +55,21 @@ public class VerbDefinition {
this.uri = uri;
}
- public ToDefinition getTo() {
- return to;
+ public List<ProcessorDefinition<?>> getOutputs() {
+ return outputs;
}
- public void setTo(ToDefinition to) {
- this.to = to;
+ public void setOutputs(List<ProcessorDefinition<?>> outputs) {
+ this.outputs = outputs;
+
+ if (outputs != null) {
+ for (ProcessorDefinition<?> output : outputs) {
+ output.configureChild(output);
+ }
+ }
}
+ public void addOutput(ProcessorDefinition<?> output) {
+ outputs.add(output);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/main/java/org/apache/camel/spi/RestBindingCapable.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestBindingCapable.java b/camel-core/src/main/java/org/apache/camel/spi/RestBindingCapable.java
deleted file mode 100644
index 645f1bc..0000000
--- a/camel-core/src/main/java/org/apache/camel/spi/RestBindingCapable.java
+++ /dev/null
@@ -1,37 +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.spi;
-
-import org.apache.camel.Consumer;
-import org.apache.camel.Processor;
-import org.apache.camel.component.restbinding.RestBindingEndpoint;
-
-public interface RestBindingCapable {
-
- /**
- * Creates a new REST <a
- * href="http://camel.apache.org/event-driven-consumer.html">Event
- * Driven Consumer</a>, using the details from the {@link org.apache.camel.component.restbinding.RestBindingEndpoint},
- * which consumes messages from the endpoint using the given processor
- *
- * @param endpoint the binding endpoint
- * @param processor the processor
- * @return a newly created REST consumer
- * @throws Exception can be thrown
- */
- Consumer createConsumer(RestBindingEndpoint endpoint, Processor processor) throws Exception;
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java b/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java
new file mode 100644
index 0000000..bab308a
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java
@@ -0,0 +1,43 @@
+/**
+ * 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.spi;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+
+public interface RestConsumerFactory {
+
+ /**
+ * Creates a new REST <a
+ * href="http://camel.apache.org/event-driven-consumer.html">Event
+ * Driven Consumer</a>, which consumes messages from the endpoint using the given processor
+ *
+ * @param camelContext the camel context
+ * @param processor the processor
+ * @param verb HTTP verb such as GET, POST
+ * @param path HTTP context-path
+ * @param accept accept-type, is <tt>null</tt> to accept anything
+ * @param parameters additional parameters
+ * @return a newly created REST consumer
+ * @throws Exception can be thrown
+ */
+ Consumer createConsumer(CamelContext camelContext, Processor processor,
+ String verb, String path, String accept, Map<String, Object> parameters) throws Exception;
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java
deleted file mode 100644
index cf3a4ae..0000000
--- a/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java
+++ /dev/null
@@ -1,51 +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.restbinding;
-
-import java.util.Map;
-
-import org.apache.camel.Consumer;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Processor;
-import org.apache.camel.component.seda.SedaEndpoint;
-import org.apache.camel.impl.ActiveMQUuidGenerator;
-import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.spi.RestBindingCapable;
-
-public class DummyRestBindingCapableComponent extends DefaultComponent implements RestBindingCapable {
-
- public void enlist() {
- getCamelContext().addComponent("dummy-rest", this);
- }
-
- @Override
- protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- return null;
- }
-
- @Override
- public Consumer createConsumer(RestBindingEndpoint endpoint, Processor processor) throws Exception {
- // just use a seda endpoint for testing purpose
- String id = ActiveMQUuidGenerator.generateSanitizedId(endpoint.getPath());
- // remove leading dash as we add that ourselves
- if (id.startsWith("-")) {
- id = id.substring(1);
- }
- SedaEndpoint seda = getCamelContext().getEndpoint("seda:" + endpoint.getVerb() + "-" + id, SedaEndpoint.class);
- return seda.createConsumer(processor);
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestConsumerFactory.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestConsumerFactory.java
new file mode 100644
index 0000000..95d8106
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestConsumerFactory.java
@@ -0,0 +1,43 @@
+/**
+ * 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.restbinding;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.component.seda.SedaEndpoint;
+import org.apache.camel.impl.ActiveMQUuidGenerator;
+import org.apache.camel.spi.RestConsumerFactory;
+
+public class DummyRestConsumerFactory implements RestConsumerFactory {
+
+ @Override
+ public Consumer createConsumer(CamelContext camelContext, Processor processor,
+ String verb, String path, String accept, Map<String, Object> parameters) throws Exception {
+ // just use a seda endpoint for testing purpose
+ String id = ActiveMQUuidGenerator.generateSanitizedId(path);
+ // remove leading dash as we add that ourselves
+ if (id.startsWith("-")) {
+ id = id.substring(1);
+ }
+ SedaEndpoint seda = camelContext.getEndpoint("seda:" + verb + "-" + id, SedaEndpoint.class);
+ return seda.createConsumer(processor);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
index 5e0565c..72798fc 100644
--- a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
@@ -16,22 +16,20 @@
*/
package org.apache.camel.component.restbinding;
-import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.model.ToDefinition;
import org.apache.camel.model.rest.PathDefinition;
import org.apache.camel.model.rest.RestDefinition;
public class FromRestGetTest extends ContextTestSupport {
@Override
- protected CamelContext createCamelContext() throws Exception {
- CamelContext context = super.createCamelContext();
-
- // register our dummy rest capable component
- context.addComponent("dummy-rest", new DummyRestBindingCapableComponent());
-
- return context;
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("dummy-test", new DummyRestConsumerFactory());
+ return jndi;
}
public void testFromRestModel() {
@@ -45,10 +43,12 @@ public class FromRestGetTest extends ContextTestSupport {
assertEquals("/say", path.getUri());
assertEquals("/hello", path.getVerbs().get(0).getUri());
- assertEquals("direct:hello", path.getVerbs().get(0).getTo().getUri());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("direct:hello", to.getUri());
assertEquals("/bye", path.getVerbs().get(1).getUri());
- assertEquals("direct:bye", path.getVerbs().get(1).getTo().getUri());
+ to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
+ assertEquals("direct:bye", to.getUri());
assertEquals(null, path.getVerbs().get(2).getUri());
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
index f70d372..17060bf 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
@@ -19,23 +19,17 @@ package org.apache.camel.management;
import javax.management.MBeanServer;
import javax.management.ObjectName;
-import org.apache.camel.CamelContext;
-import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.restbinding.DummyRestBindingCapableComponent;
-import org.apache.camel.model.rest.PathDefinition;
-import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.component.restbinding.DummyRestConsumerFactory;
+import org.apache.camel.impl.JndiRegistry;
public class ManagedFromRestGetTest extends ManagementTestSupport {
@Override
- protected CamelContext createCamelContext() throws Exception {
- CamelContext context = super.createCamelContext();
-
- // register our dummy rest capable component
- context.addComponent("dummy-rest", new DummyRestBindingCapableComponent());
-
- return context;
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("dummy-test", new DummyRestConsumerFactory());
+ return jndi;
}
public void testFromRestModel() throws Exception {
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
index 12ae236..156a2c1 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
@@ -22,8 +22,8 @@
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
- <!-- use a dummy rest component for the rest engine -->
- <bean id="dummy-rest" class="org.apache.camel.component.restbinding.DummyRestBindingCapableComponent" init-method="enlist"/>
+ <!-- use a dummy rest consumer factory for the rest engine -->
+ <bean id="dummy-rest" class="org.apache.camel.component.restbinding.DummyRestConsumerFactory"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/DummyRestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/DummyRestConsumerFactory.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/DummyRestConsumerFactory.java
new file mode 100644
index 0000000..b8349c5
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/DummyRestConsumerFactory.java
@@ -0,0 +1,43 @@
+/**
+ * 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.test.blueprint.component.restbinding;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.component.seda.SedaEndpoint;
+import org.apache.camel.impl.ActiveMQUuidGenerator;
+import org.apache.camel.spi.RestConsumerFactory;
+
+public class DummyRestConsumerFactory implements RestConsumerFactory {
+
+ @Override
+ public Consumer createConsumer(CamelContext camelContext, Processor processor,
+ String verb, String path, String accept, Map<String, Object> parameters) throws Exception {
+ // just use a seda endpoint for testing purpose
+ String id = ActiveMQUuidGenerator.generateSanitizedId(path);
+ // remove leading dash as we add that ourselves
+ if (id.startsWith("-")) {
+ id = id.substring(1);
+ }
+ SedaEndpoint seda = camelContext.getEndpoint("seda:" + verb + "-" + id, SedaEndpoint.class);
+ return seda.createConsumer(processor);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java
index ce3b3b9..c02c1de 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java
@@ -16,6 +16,7 @@
*/
package org.apache.camel.test.blueprint.component.restbinding;
+import org.apache.camel.model.ToDefinition;
import org.apache.camel.model.rest.PathDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
@@ -30,7 +31,7 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
@Test
public void testFromRestModel() {
- assertEquals(2, context.getRoutes().size());
+ assertEquals(2 + 3, context.getRoutes().size());
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
@@ -40,13 +41,14 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
assertEquals("/say", path.getUri());
assertEquals("/hello", path.getVerbs().get(0).getUri());
- assertEquals("direct:hello", path.getVerbs().get(0).getTo().getUri());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("direct:hello", to.getUri());
assertEquals("/bye", path.getVerbs().get(1).getUri());
- assertEquals("direct:bye", path.getVerbs().get(1).getTo().getUri());
+ to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
+ assertEquals("direct:bye", to.getUri());
assertEquals(null, path.getVerbs().get(2).getUri());
}
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/aff59879/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
index 806124b..2ba7b41 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
@@ -20,8 +20,8 @@
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
- <!-- use a dummy rest component for the rest engine -->
- <!--<bean id="dummy-rest" class="org.apache.camel.component.restbinding.DummyRestBindingCapableComponent"/>-->
+ <!-- use a dummy rest consumer factory for the rest engine -->
+ <bean id="dummy-rest" class="org.apache.camel.test.blueprint.component.restbinding.DummyRestConsumerFactory"/>
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
[24/33] git commit: CAMEL-7354: migrate camel-spark-rest to the new
Rest DSL
Posted by da...@apache.org.
CAMEL-7354: migrate camel-spark-rest to the new Rest DSL
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6d40039c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6d40039c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6d40039c
Branch: refs/heads/master
Commit: 6d40039c513627c9668fb12c3e63f07f2347d7ab
Parents: 81928f2
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 16 15:25:23 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:52 2014 +0200
----------------------------------------------------------------------
.../component/sparkrest/SparkComponent.java | 11 +++
.../component/sparkrest/SparkRouteBuilder.java | 91 --------------------
.../CamelSparkRouteBuilderPostTest.java | 45 ----------
.../sparkrest/CamelSparkRouteBuilderTest.java | 45 ----------
.../sparkrest/RestCamelSparkAcceptTest.java | 34 ++++++++
.../sparkrest/RestCamelSparkParamTest.java | 35 ++++++++
.../RestCamelSparkRequestBeanTest.java | 35 ++++++++
.../sparkrest/RestCamelSparkSplatTest.java | 34 ++++++++
8 files changed, 149 insertions(+), 181 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/6d40039c/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
index df58a7c..d055ce0 100644
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
+++ b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
@@ -17,6 +17,8 @@
package org.apache.camel.component.sparkrest;
import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import org.apache.camel.CamelContext;
import org.apache.camel.Consumer;
@@ -30,6 +32,8 @@ import spark.SparkBase;
public class SparkComponent extends UriEndpointComponent implements RestConsumerFactory {
+ private final Pattern pattern = Pattern.compile("\\{(.*?)\\}");
+
private int port = SparkBase.SPARK_DEFAULT_PORT;
private SparkConfiguration sparkConfiguration = new SparkConfiguration();
private SparkBinding sparkBinding = new DefaultSparkBinding();
@@ -100,6 +104,13 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
@Override
public Consumer createConsumer(CamelContext camelContext, Processor processor,
String verb, String path, String consumes, Map<String, Object> parameters) throws Exception {
+
+ if (ObjectHelper.isNotEmpty(path)) {
+ // spark-rest uses :name syntax instead of {name} so we need to replace those
+ Matcher matcher = pattern.matcher(path);
+ path = matcher.replaceAll(":$1");
+ }
+
// get the endpoint
SparkEndpoint endpoint;
if (consumes != null) {
http://git-wip-us.apache.org/repos/asf/camel/blob/6d40039c/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkRouteBuilder.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkRouteBuilder.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkRouteBuilder.java
deleted file mode 100644
index 2265da8..0000000
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkRouteBuilder.java
+++ /dev/null
@@ -1,91 +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.sparkrest;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.model.RouteDefinition;
-
-/**
- * A Spark extended {@link org.apache.camel.builder.RouteBuilder} which allows to define routes using the Spark DSL.
- */
-public abstract class SparkRouteBuilder extends RouteBuilder {
-
- public RouteDefinition get(String path) {
- return from("spark-rest:get:" + path);
- }
-
- public RouteDefinition get(String path, String accept) {
- return from("spark-rest:get:" + path + "?accept=" + accept);
- }
-
- public RouteDefinition post(String path) {
- return from("spark-rest:post:" + path);
- }
-
- public RouteDefinition post(String path, String accept) {
- return from("spark-rest:post:" + path + "?accept=" + accept);
- }
-
- public RouteDefinition put(String path) {
- return from("spark-rest:post:" + path);
- }
-
- public RouteDefinition put(String path, String accept) {
- return from("spark-rest:post:" + path + "?accept=" + accept);
- }
-
- public RouteDefinition delete(String path) {
- return from("spark-rest:delete:" + path);
- }
-
- public RouteDefinition delete(String path, String accept) {
- return from("spark-rest:delete:" + path + "?accept=" + accept);
- }
-
- public RouteDefinition head(String path) {
- return from("spark-rest:head:" + path);
- }
-
- public RouteDefinition head(String path, String accept) {
- return from("spark-rest:head:" + path + "?accept=" + accept);
- }
-
- public RouteDefinition trace(String path) {
- return from("spark-rest:trace:" + path);
- }
-
- public RouteDefinition trace(String path, String accept) {
- return from("spark-rest:trace:" + path + "?accept=" + accept);
- }
-
- public RouteDefinition connect(String path) {
- return from("spark-rest:connect:" + path);
- }
-
- public RouteDefinition connect(String path, String accept) {
- return from("spark-rest:connect:" + path + "?accept=" + accept);
- }
-
- public RouteDefinition options(String path) {
- return from("spark-rest:options:" + path);
- }
-
- public RouteDefinition options(String path, String accept) {
- return from("spark-rest:options:" + path + "?accept=" + accept);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/6d40039c/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkRouteBuilderPostTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkRouteBuilderPostTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkRouteBuilderPostTest.java
deleted file mode 100644
index 8d0ff4a..0000000
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkRouteBuilderPostTest.java
+++ /dev/null
@@ -1,45 +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.sparkrest;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.Test;
-
-public class CamelSparkRouteBuilderPostTest extends BaseSparkTest {
-
- @Test
- public void testSparkPost() throws Exception {
- getMockEndpoint("mock:foo").expectedMessageCount(1);
-
- String out = template.requestBody("http://0.0.0.0:" + getPort() + "/hello", "I was here", String.class);
- assertEquals("Bye I was here", out);
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new SparkRouteBuilder() {
- @Override
- public void configure() throws Exception {
- post("hello")
- .to("mock:foo")
- .transform().simple("Bye ${body}");
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/6d40039c/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkRouteBuilderTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkRouteBuilderTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkRouteBuilderTest.java
deleted file mode 100644
index 56c7301..0000000
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/CamelSparkRouteBuilderTest.java
+++ /dev/null
@@ -1,45 +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.sparkrest;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.junit.Test;
-
-public class CamelSparkRouteBuilderTest extends BaseSparkTest {
-
- @Test
- public void testSparkGet() throws Exception {
- getMockEndpoint("mock:foo").expectedMessageCount(1);
-
- String out = template.requestBody("http://0.0.0.0:" + getPort() + "/hello", null, String.class);
- assertEquals("Bye World", out);
-
- assertMockEndpointsSatisfied();
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new SparkRouteBuilder() {
- @Override
- public void configure() throws Exception {
- get("hello")
- .to("mock:foo")
- .transform().constant("Bye World");
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/6d40039c/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
new file mode 100644
index 0000000..70b7636
--- /dev/null
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
@@ -0,0 +1,34 @@
+/**
+ * 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.sparkrest;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class RestCamelSparkAcceptTest extends CamelSparkAcceptTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ rest().path("/hello").get().consumes("application/json")
+ .to("mock:foo")
+ .transform().constant("{ \"reply\": \"Bye World\" }");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6d40039c/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
new file mode 100644
index 0000000..4133704
--- /dev/null
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
@@ -0,0 +1,35 @@
+/**
+ * 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.sparkrest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class RestCamelSparkParamTest extends CamelSparkParamTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ rest().path("/hello/{name}").get()
+ .to("mock:foo")
+ .transform().simple("Bye ${header.name}");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6d40039c/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
new file mode 100644
index 0000000..f881f53
--- /dev/null
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
@@ -0,0 +1,35 @@
+/**
+ * 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.sparkrest;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class RestCamelSparkRequestBeanTest extends CamelSparkRequestBeanTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ rest().path("/hello/*/to/*").get()
+ .to("mock:foo")
+ .bean(RestCamelSparkRequestBeanTest.class, "doSomething");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/6d40039c/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
new file mode 100644
index 0000000..fefb211
--- /dev/null
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
@@ -0,0 +1,34 @@
+/**
+ * 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.sparkrest;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class RestCamelSparkSplatTest extends CamelSparkSplatTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ rest().path("/hello/*/to/*").get()
+ .to("mock:foo")
+ .transform().simple("Bye big ${header.splat[1]} from ${header.splat[0]}");
+ }
+ };
+ }
+}
[09/33] git commit: CAMEL-7354: Migrating rest DSL to be separated
from regular Camel routes.
Posted by da...@apache.org.
CAMEL-7354: Migrating rest DSL to be separated from regular Camel routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7e16d71c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7e16d71c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7e16d71c
Branch: refs/heads/master
Commit: 7e16d71c48300425cf8d78d1c9a964a1c75a2b60
Parents: 3c2bff2
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 2 13:11:52 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:48 2014 +0200
----------------------------------------------------------------------
.../org/apache/camel/model/rest/GetVerbDefinition.java | 3 +++
.../org/apache/camel/model/rest/PathDefinition.java | 7 +++----
.../apache/camel/model/rest/PostVerbDefinition.java | 3 +++
.../org/apache/camel/model/rest/VerbDefinition.java | 13 +++++++++++--
.../resources/org/apache/camel/model/rest/jaxb.index | 3 ++-
.../core/xml/AbstractCamelContextFactoryBean.java | 3 +++
.../camel/spring/handler/CamelNamespaceHandler.java | 1 +
.../component/restbinding/SpringFromRestGetTest.xml | 5 +++++
8 files changed, 31 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7e16d71c/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java
index f3e398e..03315d4 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java
@@ -24,4 +24,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
public class GetVerbDefinition extends VerbDefinition {
+ public GetVerbDefinition() {
+ setMethod("get");
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7e16d71c/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
index 2eb7b4a..bfa8d79 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -27,19 +27,17 @@ import javax.xml.bind.annotation.XmlRootElement;
import org.apache.camel.model.ToDefinition;
@XmlRootElement(name = "path")
-@XmlAccessorType(XmlAccessType.FIELD)
+@XmlAccessorType(XmlAccessType.PROPERTY)
public class PathDefinition {
- @XmlAttribute
private String uri;
-
- @XmlElementRef
private List<VerbDefinition> verbs = new ArrayList<VerbDefinition>();
public String getUri() {
return uri;
}
+ @XmlAttribute
public void setUri(String uri) {
this.uri = uri;
}
@@ -48,6 +46,7 @@ public class PathDefinition {
return verbs;
}
+ @XmlElementRef
public void setVerbs(List<VerbDefinition> verbs) {
this.verbs = verbs;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7e16d71c/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java
index a5d2fb0..3a8f39e 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java
@@ -24,4 +24,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
public class PostVerbDefinition extends VerbDefinition {
+ public PostVerbDefinition() {
+ setMethod("post");
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7e16d71c/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 c0721bb..63e3142 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
@@ -28,14 +28,23 @@ import org.apache.camel.model.ToDefinition;
@XmlAccessorType(XmlAccessType.FIELD)
public class VerbDefinition {
- // TODO: we would ideally want this to be abstract and not in the XML DSL
+ @XmlAttribute
+ private String method;
@XmlAttribute
private String uri;
- @XmlElementRef(required = true)
+ @XmlElementRef
private ToDefinition to;
+ public String getMethod() {
+ return method;
+ }
+
+ public void setMethod(String method) {
+ this.method = method;
+ }
+
public String getUri() {
return uri;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7e16d71c/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
index 98ae8de..77197e8 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
@@ -18,4 +18,5 @@ GetVerbDefinition
PostVerbDefinition
PathDefinition
RestDefinition
-RestsDefinition
\ No newline at end of file
+RestsDefinition
+VerbDefinition
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/7e16d71c/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index d411edd..b80fb6f 100644
--- a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -311,6 +311,9 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
findRouteBuilders();
installRoutes();
+
+ // and add the rests
+ getContext().addRestDefinitions(getRests());
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7e16d71c/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
index 957c792..ffbfae9 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
@@ -311,6 +311,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
CamelContextFactoryBean factoryBean = (CamelContextFactoryBean) value;
builder.addPropertyValue("id", contextId);
builder.addPropertyValue("implicitId", implicitId);
+ builder.addPropertyValue("rests", factoryBean.getRests());
builder.addPropertyValue("routes", factoryBean.getRoutes());
builder.addPropertyValue("intercepts", factoryBean.getIntercepts());
builder.addPropertyValue("interceptFroms", factoryBean.getInterceptFroms());
http://git-wip-us.apache.org/repos/asf/camel/blob/7e16d71c/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
index d238f43..0ee6aec 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
@@ -39,6 +39,11 @@
<to uri="seda:update"/>
</post>
</path>
+ <path uri="/foo">
+ <verb method="get" uri="/bla">
+ <to uri="somewhere"/>
+ </verb>
+ </path>
</rest>
<route id="helloRoute">
[07/33] git commit: CAMEL-7354: Migrating rest DSL to be separated
from regular Camel routes.
Posted by da...@apache.org.
CAMEL-7354: Migrating rest DSL to be separated from regular Camel routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3e2c6fc6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3e2c6fc6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3e2c6fc6
Branch: refs/heads/master
Commit: 3e2c6fc65c96a0ea0478bc4786e8c8de56a00dd3
Parents: 7e16d71
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 2 13:23:49 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:48 2014 +0200
----------------------------------------------------------------------
.../apache/camel/model/rest/VerbDefinition.java | 2 +-
.../handler/CamelNamespaceHandler.java | 2 +
.../camel/blueprint/BlueprintJaxbRestTest.java | 81 ++++++++++++++++++++
.../camel/blueprint/BlueprintJaxbTest.java | 3 +-
.../src/test/resources/test-rest.xml | 38 +++++++++
.../spring/handler/CamelNamespaceHandler.java | 2 +
.../restbinding/SpringFromRestGetTest.xml | 5 --
7 files changed, 126 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3e2c6fc6/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 63e3142..388b4ea 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
@@ -34,7 +34,7 @@ public class VerbDefinition {
@XmlAttribute
private String uri;
- @XmlElementRef
+ @XmlElementRef(required = false)
private ToDefinition to;
public String getMethod() {
http://git-wip-us.apache.org/repos/asf/camel/blob/3e2c6fc6/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
index e25621d..5c077f5 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
@@ -527,6 +527,7 @@ public class CamelNamespaceHandler implements NamespaceHandler {
}
protected Set<Class<?>> getJaxbPackages() {
+ // we nedd to have a class from each different package with jaxb models
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(CamelContextFactoryBean.class);
classes.add(AbstractCamelContextFactoryBean.class);
@@ -536,6 +537,7 @@ public class CamelNamespaceHandler implements NamespaceHandler {
classes.add(org.apache.camel.model.dataformat.DataFormatsDefinition.class);
classes.add(org.apache.camel.model.language.ExpressionDefinition.class);
classes.add(org.apache.camel.model.loadbalancer.RoundRobinLoadBalancerDefinition.class);
+ classes.add(org.apache.camel.model.rest.RestDefinition.class);
classes.add(SSLContextParametersFactoryBean.class);
return classes;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3e2c6fc6/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
new file mode 100644
index 0000000..dc8ec0a
--- /dev/null
+++ b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
@@ -0,0 +1,81 @@
+/**
+ * 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.blueprint;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.camel.blueprint.handler.CamelNamespaceHandler;
+import org.apache.camel.test.junit4.TestSupport;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class BlueprintJaxbRestTest extends TestSupport {
+
+ @Test
+ public void test() throws Exception {
+ if (isJava16() && isJavaVendor("ibm")) {
+ // does not test well on java6 with ibm
+ return;
+ }
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document doc = db.parse(getClass().getClassLoader().getResourceAsStream("test-rest.xml"));
+ Element elem = null;
+ NodeList nl = doc.getDocumentElement().getChildNodes();
+ for (int i = 0; i < nl.getLength(); i++) {
+ Node node = nl.item(i);
+ if (node instanceof Element) {
+ elem = (Element) node;
+ break;
+ }
+ }
+ CamelNamespaceHandler.renameNamespaceRecursive(elem, CamelNamespaceHandler.BLUEPRINT_NS, CamelNamespaceHandler.SPRING_NS);
+
+ JAXBContext context = JAXBContext.newInstance("org.apache.camel.blueprint:"
+ + "org.apache.camel:org.apache.camel.model:"
+ + "org.apache.camel.model.config:"
+ + "org.apache.camel.model.dataformat:"
+ + "org.apache.camel.model.language:"
+ + "org.apache.camel.model.loadbalancer:"
+ + "org.apache.camel.model.rest");
+ Unmarshaller unmarshaller = context.createUnmarshaller();
+ Object object = unmarshaller.unmarshal(elem);
+ assertNotNull(object);
+ assertTrue(object instanceof CamelContextFactoryBean);
+ assertNotNull(((CamelContextFactoryBean) object).getRoutes());
+ assertEquals(0, ((CamelContextFactoryBean) object).getRoutes().size());
+
+ CamelContextFactoryBean cfb = (CamelContextFactoryBean) object;
+ assertEquals(1, cfb.getRests().size());
+ assertEquals(1, cfb.getRests().get(0).getPaths().size());
+ assertEquals("/say", cfb.getRests().get(0).getPaths().get(0).getUri());
+ assertEquals(3, cfb.getRests().get(0).getPaths().get(0).getVerbs().size());
+ assertEquals("get", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(0).getMethod());
+ assertEquals("/hello", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(0).getUri());
+ assertEquals("get", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(1).getMethod());
+ assertEquals("/bye", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(1).getUri());
+ assertEquals("post", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(2).getMethod());
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3e2c6fc6/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java
index 2c49753..aabf472 100644
--- a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java
+++ b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbTest.java
@@ -59,7 +59,8 @@ public class BlueprintJaxbTest extends TestSupport {
+ "org.apache.camel.model.config:"
+ "org.apache.camel.model.dataformat:"
+ "org.apache.camel.model.language:"
- + "org.apache.camel.model.loadbalancer");
+ + "org.apache.camel.model.loadbalancer:"
+ + "org.apache.camel.model.rest");
Unmarshaller unmarshaller = context.createUnmarshaller();
Object object = unmarshaller.unmarshal(elem);
assertNotNull(object);
http://git-wip-us.apache.org/repos/asf/camel/blob/3e2c6fc6/components/camel-blueprint/src/test/resources/test-rest.xml
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/resources/test-rest.xml b/components/camel-blueprint/src/test/resources/test-rest.xml
new file mode 100644
index 0000000..f6958b7
--- /dev/null
+++ b/components/camel-blueprint/src/test/resources/test-rest.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!--
+
+ 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.
+
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+ <rest component="dummy-rest" routeId="myRestRoute">
+ <path uri="/say">
+ <get uri="/hello">
+ <to uri="direct:hello"/>
+ </get>
+ <get uri="/bye">
+ <to uri="direct:bye"/>
+ </get>
+ <post>
+ <to uri="seda:update"/>
+ </post>
+ </path>
+ </rest>
+ </camelContext>
+
+</blueprint>
http://git-wip-us.apache.org/repos/asf/camel/blob/3e2c6fc6/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
index ffbfae9..66efd34 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
@@ -189,6 +189,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
}
protected Set<Class<?>> getJaxbPackages() {
+ // we nedd to have a class from each different package with jaxb models
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(org.apache.camel.spring.CamelContextFactoryBean.class);
classes.add(CamelJMXAgentDefinition.class);
@@ -198,6 +199,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
classes.add(org.apache.camel.model.dataformat.DataFormatsDefinition.class);
classes.add(org.apache.camel.model.language.ExpressionDefinition.class);
classes.add(org.apache.camel.model.loadbalancer.RoundRobinLoadBalancerDefinition.class);
+ classes.add(org.apache.camel.model.rest.RestDefinition.class);
classes.add(org.apache.camel.util.spring.SSLContextParametersFactoryBean.class);
return classes;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3e2c6fc6/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
index 0ee6aec..d238f43 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
@@ -39,11 +39,6 @@
<to uri="seda:update"/>
</post>
</path>
- <path uri="/foo">
- <verb method="get" uri="/bla">
- <to uri="somewhere"/>
- </verb>
- </path>
</rest>
<route id="helloRoute">
[11/33] git commit: CAMEL-7354: Migrating rest DSL to be separated
from regular Camel routes.
Posted by da...@apache.org.
CAMEL-7354: Migrating rest DSL to be separated from regular Camel routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2e4e7f88
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2e4e7f88
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2e4e7f88
Branch: refs/heads/master
Commit: 2e4e7f88ac2ed9329790737f28b67b626b0b7d4a
Parents: 0dd457a
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 2 17:24:12 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:49 2014 +0200
----------------------------------------------------------------------
.../org/apache/camel/builder/RouteBuilder.java | 9 ++++----
.../apache/camel/impl/DefaultCamelContext.java | 11 +++++----
.../apache/camel/model/rest/RestDefinition.java | 24 ++++++++++++++++++++
.../component/restbinding/FromRestGetTest.java | 2 +-
.../restbinding/SpringFromRestGetTest.xml | 2 +-
5 files changed, 37 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2e4e7f88/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index 8864da7..9e4e334 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -274,14 +274,13 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
}
public void addRoutesToCamelContext(CamelContext context) throws Exception {
+ // must configure routes before rests
configureRoutes((ModelCamelContext)context);
- // add routes to Camel by populating them
- populateRoutes();
-
- // after routes then configure and populate rests
configureRests((ModelCamelContext) context);
- // add rests to Camel by populating them
+
+ // but populate rests before routes, as we want to turn rests into routes
populateRests();
+ populateRoutes();
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/2e4e7f88/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 846f647..eca6e89 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -1415,10 +1415,13 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
public void addRestDefinitions(Collection<RestDefinition> restDefinitions) throws Exception {
this.restDefinitions.addAll(restDefinitions);
- // TODO: should we support not starting rest?
- //if (shouldStartRoutes()) {
- // startRouteDefinitions(routeDefinitions);
- //}
+
+ // convert rests into routes so we reuse routes for runtime
+ List<RouteDefinition> routes = new ArrayList<RouteDefinition>();
+ for (RestDefinition rest : restDefinitions) {
+ routes.addAll(rest.asRouteDefinition(this));
+ }
+ addRouteDefinitions(routes);
}
public List<InterceptStrategy> getInterceptStrategies() {
http://git-wip-us.apache.org/repos/asf/camel/blob/2e4e7f88/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 4b4826d..56cc843 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
@@ -24,6 +24,9 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.RouteDefinition;
+
/**
* Represents an XML <rest/> element
*/
@@ -72,4 +75,25 @@ public class RestDefinition {
return answer;
}
+ /**
+ * Transforms this REST definition into a list of {@link org.apache.camel.model.RouteDefinition} which
+ * Camel routing engine can add and run. This allows us to define REST services using this
+ * REST DSL and turn those into regular Camel routes.
+ */
+ public List<RouteDefinition> asRouteDefinition(ModelCamelContext camelContext) throws Exception {
+ List<RouteDefinition> answer = new ArrayList<RouteDefinition>();
+
+ for (PathDefinition path : getPaths()) {
+ String uri = path.getUri();
+ for (VerbDefinition verb : path.getVerbs()) {
+ String from = "rest-binding:" + verb.getMethod() + ":" + uri + (verb.getUri() != null ? verb.getUri() : "");
+ RouteDefinition route = new RouteDefinition(from);
+ answer.add(route);
+ route.getOutputs().add(verb.getTo());
+ }
+ }
+
+ return answer;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2e4e7f88/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
index 211f768..5e0565c 100644
--- a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
@@ -35,7 +35,7 @@ public class FromRestGetTest extends ContextTestSupport {
}
public void testFromRestModel() {
- assertEquals(2, context.getRoutes().size());
+ assertEquals(2 + 3, context.getRoutes().size());
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
http://git-wip-us.apache.org/repos/asf/camel/blob/2e4e7f88/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
index d238f43..12ae236 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
@@ -23,7 +23,7 @@
">
<!-- use a dummy rest component for the rest engine -->
- <bean id="dummy-rest" class="org.apache.camel.component.restbinding.DummyRestBindingCapableComponent"/>
+ <bean id="dummy-rest" class="org.apache.camel.component.restbinding.DummyRestBindingCapableComponent" init-method="enlist"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
[18/33] git commit: CAMEL-7354: Rest DSL can embed routes.
Posted by da...@apache.org.
CAMEL-7354: Rest DSL can embed routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/490f2d89
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/490f2d89
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/490f2d89
Branch: refs/heads/master
Commit: 490f2d89327fd61ed4bd005cf171f1911ebdea1e
Parents: 89a945b
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 15 15:07:30 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:51 2014 +0200
----------------------------------------------------------------------
.../camel/model/rest/DeleteVerbDefinition.java | 30 +++++++++
.../camel/model/rest/HeadVerbDefinition.java | 30 +++++++++
.../apache/camel/model/rest/PathDefinition.java | 66 +++++++++++++++-----
.../camel/model/rest/PutVerbDefinition.java | 30 +++++++++
.../apache/camel/model/rest/VerbDefinition.java | 32 ++++++++++
5 files changed, 171 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/490f2d89/camel-core/src/main/java/org/apache/camel/model/rest/DeleteVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/DeleteVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/DeleteVerbDefinition.java
new file mode 100644
index 0000000..137c607
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/DeleteVerbDefinition.java
@@ -0,0 +1,30 @@
+/**
+ * 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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "delete")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class DeleteVerbDefinition extends VerbDefinition {
+
+ public DeleteVerbDefinition() {
+ setMethod("delete");
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/490f2d89/camel-core/src/main/java/org/apache/camel/model/rest/HeadVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/HeadVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/HeadVerbDefinition.java
new file mode 100644
index 0000000..7db89a3
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/HeadVerbDefinition.java
@@ -0,0 +1,30 @@
+/**
+ * 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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "head")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class HeadVerbDefinition extends VerbDefinition {
+
+ public HeadVerbDefinition() {
+ setMethod("head");
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/490f2d89/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
index 92b072c..e60fff7 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -37,7 +37,7 @@ public class PathDefinition {
return uri;
}
- @XmlAttribute
+ @XmlAttribute(required = true)
public void setUri(String uri) {
this.uri = uri;
}
@@ -64,31 +64,51 @@ public class PathDefinition {
}
public PathDefinition get() {
- return get(null);
+ return addVerb("get", null);
}
public PathDefinition get(String url) {
- GetVerbDefinition answer = new GetVerbDefinition();
- answer.setPath(this);
- getVerbs().add(answer);
- if (url != null) {
- answer.setUri(url);
- }
- return this;
+ return addVerb("get", url);
}
public PathDefinition post() {
- return post(null);
+ return addVerb("post", null);
}
public PathDefinition post(String url) {
- PostVerbDefinition answer = new PostVerbDefinition();
- answer.setPath(this);
- getVerbs().add(answer);
- if (url != null) {
- answer.setUri(url);
- }
- return this;
+ return addVerb("post", url);
+ }
+
+ public PathDefinition put() {
+ return addVerb("put", null);
+ }
+
+ public PathDefinition put(String url) {
+ return addVerb("put", url);
+ }
+
+ public PathDefinition delete() {
+ return addVerb("delete", null);
+ }
+
+ public PathDefinition delete(String url) {
+ return addVerb("delete", url);
+ }
+
+ public PathDefinition head() {
+ return addVerb("head", null);
+ }
+
+ public PathDefinition head(String url) {
+ return addVerb("head", url);
+ }
+
+ public PathDefinition verb(String verb) {
+ return addVerb(verb, null);
+ }
+
+ public PathDefinition verb(String verb, String url) {
+ return addVerb(verb, url);
}
public PathDefinition accept(String accept) {
@@ -103,6 +123,7 @@ public class PathDefinition {
return this;
}
+ @Deprecated
public VerbDefinition to(String url) {
// add to last verb
if (getVerbs().isEmpty()) {
@@ -115,4 +136,15 @@ public class PathDefinition {
return verb;
}
+ private PathDefinition addVerb(String verb, String url) {
+ VerbDefinition answer = new VerbDefinition();
+ answer.setMethod(verb);
+ answer.setPath(this);
+ getVerbs().add(answer);
+ if (url != null) {
+ answer.setUri(url);
+ }
+ return this;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/490f2d89/camel-core/src/main/java/org/apache/camel/model/rest/PutVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PutVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PutVerbDefinition.java
new file mode 100644
index 0000000..2a2f616
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PutVerbDefinition.java
@@ -0,0 +1,30 @@
+/**
+ * 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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "put")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class PutVerbDefinition extends VerbDefinition {
+
+ public PutVerbDefinition() {
+ setMethod("put");
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/490f2d89/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 c4e006e..7b1fbd7 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
@@ -102,4 +102,36 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
return path.post(url);
}
+ public PathDefinition put() {
+ return path.put();
+ }
+
+ public PathDefinition put(String url) {
+ return path.put(url);
+ }
+
+ public PathDefinition delete() {
+ return path.delete();
+ }
+
+ public PathDefinition delete(String url) {
+ return path.delete(url);
+ }
+
+ public PathDefinition head() {
+ return path.head();
+ }
+
+ public PathDefinition head(String url) {
+ return path.head(url);
+ }
+
+ public PathDefinition verb(String verb) {
+ return path.verb(verb);
+ }
+
+ public PathDefinition verb(String verb, String url) {
+ return path.verb(verb, url);
+ }
+
}
[26/33] git commit: CAMEL-7364: Rest DSL allow rest to setup uri
prefix and verbs to specify postfix uri.
Posted by da...@apache.org.
CAMEL-7364: Rest DSL allow rest to setup uri prefix and verbs to specify postfix uri.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b3a717fe
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b3a717fe
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b3a717fe
Branch: refs/heads/master
Commit: b3a717fe1915bcd5d192deb35fb4e2881f739e65
Parents: 3c52555
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 17 10:40:41 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:52 2014 +0200
----------------------------------------------------------------------
.../org/apache/camel/builder/RouteBuilder.java | 12 ++++
.../apache/camel/model/rest/RestDefinition.java | 53 ++++++++++++++-
.../camel/model/rest/RestsDefinition.java | 18 ++++-
.../apache/camel/model/rest/VerbDefinition.java | 35 ++++++++++
.../rest/FromRestExplicitComponentTest.java | 43 ++++++++++++
.../camel/component/rest/FromRestGetTest.java | 2 +-
.../component/rest/FromRestUriPrefixTest.java | 71 ++++++++++++++++++++
.../rest/SpringFromRestUriPrefixTest.java | 29 ++++++++
.../rest/SpringFromRestUriPrefixTest.xml | 57 ++++++++++++++++
.../component/rest/FromRestUriPrefixTest.java | 63 +++++++++++++++++
.../component/rest/FromRestUriPrefixTest.xml | 55 +++++++++++++++
.../example/spark/MySparkRouteBuilder.java | 2 +-
12 files changed, 435 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index 0fb2a52..e5d36bf 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -74,6 +74,18 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
/**
* Creates a new REST service
*
+ * @return the builder
+ */
+ public RestDefinition rest() {
+ getRestCollection().setCamelContext(getContext());
+ RestDefinition answer = getRestCollection().rest();
+ configureRest(answer);
+ return answer;
+ }
+
+ /**
+ * Creates a new REST service
+ *
* @param uri the path
* @return the builder
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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 460e081..7257d37 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
@@ -29,6 +29,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ToDefinition;
+import org.apache.camel.util.FileUtil;
import org.apache.camel.util.URISupport;
/**
@@ -73,6 +74,14 @@ public class RestDefinition {
//-------------------------------------------------------------------------
/**
+ * To set the uri
+ */
+ public RestDefinition uri(String uri) {
+ setUri(uri);
+ return this;
+ }
+
+ /**
* To use a specific Camel rest component
*/
public RestDefinition component(String componentId) {
@@ -84,26 +93,50 @@ public class RestDefinition {
return addVerb("get", null);
}
+ public RestDefinition get(String uri) {
+ return addVerb("get", uri);
+ }
+
public RestDefinition post() {
return addVerb("post", null);
}
+ public RestDefinition post(String uri) {
+ return addVerb("post", uri);
+ }
+
public RestDefinition put() {
return addVerb("put", null);
}
+ public RestDefinition put(String uri) {
+ return addVerb("put", uri);
+ }
+
public RestDefinition delete() {
return addVerb("delete", null);
}
+ public RestDefinition delete(String uri) {
+ return addVerb("delete", uri);
+ }
+
public RestDefinition head() {
return addVerb("head", null);
}
+ public RestDefinition head(String uri) {
+ return addVerb("head", uri);
+ }
+
public RestDefinition verb(String verb) {
return addVerb(verb, null);
}
+ public RestDefinition verb(String verb, String uri) {
+ return addVerb(verb, uri);
+ }
+
public RestDefinition consumes(String accept) {
// add to last verb
if (getVerbs().isEmpty()) {
@@ -132,7 +165,7 @@ public class RestDefinition {
// Implementation
//-------------------------------------------------------------------------
- private RestDefinition addVerb(String verb, String url) {
+ private RestDefinition addVerb(String verb, String uri) {
VerbDefinition answer;
if ("get".equals(verb)) {
@@ -151,6 +184,7 @@ public class RestDefinition {
}
answer.setRest(this);
+ answer.setUri(uri);
getVerbs().add(answer);
return this;
}
@@ -164,7 +198,7 @@ public class RestDefinition {
List<RouteDefinition> answer = new ArrayList<RouteDefinition>();
for (VerbDefinition verb : getVerbs()) {
- String from = "rest:" + verb.asVerb() + ":" + uri;
+ String from = "rest:" + verb.asVerb() + ":" + buildUri(verb);
// append options
Map<String, Object> options = new HashMap<String, Object>();
if (getComponent() != null) {
@@ -187,4 +221,19 @@ public class RestDefinition {
return answer;
}
+ private String buildUri(VerbDefinition verb) {
+ if (uri != null && verb.getUri() != null) {
+ // make sure there is only one / slash separator between the two
+ String s = FileUtil.stripTrailingSeparator(uri);
+ String s2 = FileUtil.stripLeadingSeparator(verb.getUri());
+ return s + "/" + s2;
+ } else if (uri != null) {
+ return uri;
+ } else if (verb.getUri() != null) {
+ return verb.getUri();
+ } else {
+ return "";
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
index ebc3057..3386903 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
@@ -28,7 +28,7 @@ import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.OptionalIdentifiedDefinition;
/**
- * Represents a collection of RESTs
+ * Represents a collection of {@link org.apache.camel.model.rest.RestDefinition REST's}
*/
@XmlRootElement(name = "rests")
@XmlAccessorType(XmlAccessType.FIELD)
@@ -77,12 +77,28 @@ public class RestsDefinition extends OptionalIdentifiedDefinition<RestsDefinitio
// Fluent API
//-------------------------------------------------------------------------
+ /**
+ * Creates a rest DSL
+ */
+ public RestDefinition rest() {
+ RestDefinition rest = createRest();
+ return rest(rest);
+ }
+
+ /**
+ * Creates a rest DSL
+ *
+ * @param uri the rest path
+ */
public RestDefinition rest(String uri) {
RestDefinition rest = createRest();
rest.setUri(uri);
return rest(rest);
}
+ /**
+ * Adds the {@link org.apache.camel.model.rest.RestsDefinition}
+ */
public RestDefinition rest(RestDefinition rest) {
getRests().add(rest);
return rest;
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/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 282e562..4347e75 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
@@ -32,6 +32,9 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
private String method;
@XmlAttribute
+ private String uri;
+
+ @XmlAttribute
private String consumes;
@XmlTransient
@@ -53,6 +56,14 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
this.method = method;
}
+ public String getUri() {
+ return uri;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
public String getConsumes() {
return consumes;
}
@@ -68,26 +79,50 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
return rest.get();
}
+ public RestDefinition get(String uri) {
+ return rest.get(uri);
+ }
+
public RestDefinition post() {
return rest.post();
}
+ public RestDefinition post(String uri) {
+ return rest.post(uri);
+ }
+
public RestDefinition put() {
return rest.put();
}
+ public RestDefinition put(String uri) {
+ return rest.put(uri);
+ }
+
public RestDefinition delete() {
return rest.delete();
}
+ public RestDefinition delete(String uri) {
+ return rest.delete(uri);
+ }
+
public RestDefinition head() {
return rest.head();
}
+ public RestDefinition head(String uri) {
+ return rest.head(uri);
+ }
+
public RestDefinition verb(String verb) {
return rest.verb(verb);
}
+ public RestDefinition verb(String verb, String uri) {
+ return rest.verb(verb, uri);
+ }
+
public String asVerb() {
// we do not want the jaxb model to repeat itself, by outputting <get method="get">
// so we defer the verb from the instance type
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
new file mode 100644
index 0000000..63a1e48
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
@@ -0,0 +1,43 @@
+/**
+ * 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.builder.RouteBuilder;
+
+public class FromRestExplicitComponentTest extends FromRestGetTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ rest("/say/hello").component("dummy-rest")
+ .get().to("direct:hello");
+
+ rest().component("dummy-rest").uri("/say/bye")
+ .get().consumes("application/json").to("direct:bye").endRest()
+ .post().to("mock:update");
+
+ from("direct:hello")
+ .transform().constant("Hello World");
+
+ from("direct:bye")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index fdbe60a..2b40fd4 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -27,7 +27,7 @@ public class FromRestGetTest extends ContextTestSupport {
@Override
protected JndiRegistry createRegistry() throws Exception {
JndiRegistry jndi = super.createRegistry();
- jndi.bind("dummy-test", new DummyRestConsumerFactory());
+ jndi.bind("dummy-rest", new DummyRestConsumerFactory());
return jndi;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
new file mode 100644
index 0000000..5369d4a
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+
+public class FromRestUriPrefixTest extends FromRestGetTest {
+
+ public void testFromRestModel() throws Exception {
+ assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+
+ assertEquals(1, context.getRestDefinitions().size());
+ RestDefinition rest = context.getRestDefinitions().get(0);
+ assertNotNull(rest);
+ assertEquals("/say/", rest.getUri());
+ assertEquals(3, rest.getVerbs().size());
+ assertEquals("/hello", rest.getVerbs().get(0).getUri());
+ assertEquals("bye", rest.getVerbs().get(1).getUri());
+ assertEquals("/bye", rest.getVerbs().get(2).getUri());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("direct:hello", to.getUri());
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getOutputs().get(0));
+ assertEquals("direct:bye", to.getUri());
+
+ // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
+ getMockEndpoint("mock:update").expectedMessageCount(1);
+ template.sendBody("seda:post-say-bye", "I was here");
+ assertMockEndpointsSatisfied();
+
+ String out = template.requestBody("seda:get-say-hello", "Me", String.class);
+ assertEquals("Hello World", out);
+ String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
+ assertEquals("Bye World", out2);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // we have logic to cleanup those paths so there is only one / between the paths
+ rest("/say/")
+ .get("/hello").to("direct:hello")
+ .get("bye").consumes("application/json").to("direct:bye")
+ .post("/bye").to("mock:update");
+
+ from("direct:hello")
+ .transform().constant("Hello World");
+
+ from("direct:bye")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.java
new file mode 100644
index 0000000..6eafd23
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.java
@@ -0,0 +1,29 @@
+/**
+ * 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.CamelContext;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringFromRestUriPrefixTest extends FromRestUriPrefixTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml
new file mode 100644
index 0000000..c2a8aa7
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestUriPrefixTest.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- use a dummy rest consumer factory for the rest engine -->
+ <bean id="dummy-rest" class="org.apache.camel.component.rest.DummyRestConsumerFactory"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <rest uri="/say/">
+ <get uri="/hello">
+ <to uri="direct:hello"/>
+ </get>
+ <get uri="bye" consumes="application/json">
+ <to uri="direct:bye"/>
+ </get>
+ <post uri="/bye">
+ <to uri="mock:update"/>
+ </post>
+ </rest>
+
+ <route>
+ <from uri="direct:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </route>
+ <route>
+ <from uri="direct:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+
+ </camelContext>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
new file mode 100644
index 0000000..cf6d7b8
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
@@ -0,0 +1,63 @@
+/**
+ * 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.test.blueprint.component.rest;
+
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
+import org.junit.Test;
+
+public class FromRestUriPrefixTest extends CamelBlueprintTestSupport {
+
+ @Override
+ protected String getBlueprintDescriptor() {
+ return "org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml";
+ }
+
+ protected int getExpectedNumberOfRoutes() {
+ return 2 + 3;
+ }
+
+ @Test
+ public void testFromRestModel() throws Exception {
+ assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+
+ assertEquals(1, context.getRestDefinitions().size());
+ RestDefinition rest = context.getRestDefinitions().get(0);
+ assertNotNull(rest);
+ assertEquals("/say/", rest.getUri());
+ assertEquals(3, rest.getVerbs().size());
+ assertEquals("/hello", rest.getVerbs().get(0).getUri());
+ assertEquals("bye", rest.getVerbs().get(1).getUri());
+ assertEquals("/bye", rest.getVerbs().get(2).getUri());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("direct:hello", to.getUri());
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getOutputs().get(0));
+ assertEquals("direct:bye", to.getUri());
+
+ // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
+ getMockEndpoint("mock:update").expectedMessageCount(1);
+ template.sendBody("seda:post-say-bye", "I was here");
+ assertMockEndpointsSatisfied();
+
+ String out = template.requestBody("seda:get-say-hello", "Me", String.class);
+ assertEquals("Hello World", out);
+ String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
+ assertEquals("Bye World", out2);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml
new file mode 100644
index 0000000..2319f0d
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <!-- use a dummy rest consumer factory for the rest engine -->
+ <bean id="dummy-rest" class="org.apache.camel.test.blueprint.component.rest.DummyRestConsumerFactory"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+ <rest uri="/say/">
+ <get uri="/hello">
+ <to uri="direct:hello"/>
+ </get>
+ <get uri="bye" consumes="application/json">
+ <to uri="direct:bye"/>
+ </get>
+ <post uri="/bye">
+ <to uri="mock:update"/>
+ </post>
+ </rest>
+
+ <route>
+ <from uri="direct:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </route>
+ <route>
+ <from uri="direct:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+
+ </camelContext>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/b3a717fe/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
index 891746a..504a9a6 100644
--- a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
+++ b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
@@ -28,7 +28,7 @@ public class MySparkRouteBuilder extends RouteBuilder {
// we only have a GET service, but we have PUT, POST, and all the other REST verbs we can use
- rest("hello/:me").component("spark-rest")
+ rest().component("spark-rest").uri("hello/:me")
.get().consumes("text/plain")
.to("log:input")
.transform().simple("Hello ${header.me}").endRest()
[29/33] git commit: CAMEL-7364: Rest DSL allow to configure embedded
routes. And have a shorthand for a singular to without the needed for
explicit defining route.
Posted by da...@apache.org.
CAMEL-7364: Rest DSL allow to configure embedded routes. And have a shorthand for a singular to without the needed for explicit defining route.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/df7b90c4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/df7b90c4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/df7b90c4
Branch: refs/heads/master
Commit: df7b90c4972281961d975e897eff10fbaefc547c
Parents: 7bbb88b
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Jul 19 08:35:43 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:53 2014 +0200
----------------------------------------------------------------------
.../apache/camel/model/ProcessorDefinition.java | 23 +----
.../org/apache/camel/model/RouteDefinition.java | 11 +++
.../apache/camel/model/rest/RestDefinition.java | 43 +++++++--
.../apache/camel/model/rest/VerbDefinition.java | 75 +++++++++++++---
.../rest/FromRestConfigurationTest.java | 2 +-
.../rest/FromRestExplicitComponentTest.java | 2 +-
.../rest/FromRestGetEmbeddedRouteTest.java | 7 +-
.../component/rest/FromRestGetEndPathTest.java | 34 ++++++-
.../camel/component/rest/FromRestGetTest.java | 4 +-
.../component/rest/FromRestUriPrefixTest.java | 4 +-
.../ManagedFromRestGetEmbeddedRouteTest.java | 93 ++++++++++++++++++++
.../management/ManagedFromRestGetTest.java | 3 +
.../component/restlet/RestRestletGetTest.java | 1 +
.../sparkrest/RestCamelSparkAcceptTest.java | 1 +
.../sparkrest/RestCamelSparkParamTest.java | 1 +
.../RestCamelSparkRequestBeanTest.java | 1 +
.../sparkrest/RestCamelSparkSplatTest.java | 1 +
.../rest/SpringFromRestGetEmbeddedRouteTest.xml | 20 +++--
.../rest/FromRestGetEmbeddedRouteTest.java | 4 +-
.../component/rest/FromRestGetTest.java | 4 +-
.../component/rest/FromRestUriPrefixTest.java | 4 +-
.../rest/FromRestGetEmbeddedRouteTest.xml | 20 +++--
.../example/spark/MySparkRouteBuilder.java | 5 +-
23 files changed, 296 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index b7095fc..0f98218 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -53,7 +53,6 @@ import org.apache.camel.model.language.ConstantExpression;
import org.apache.camel.model.language.ExpressionDefinition;
import org.apache.camel.model.language.LanguageExpression;
import org.apache.camel.model.rest.RestDefinition;
-import org.apache.camel.model.rest.VerbDefinition;
import org.apache.camel.processor.InterceptEndpointProcessor;
import org.apache.camel.processor.Pipeline;
import org.apache.camel.processor.aggregate.AggregationStrategy;
@@ -1325,27 +1324,13 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
*/
public RestDefinition endRest() {
ProcessorDefinition<?> def = this;
- if (def.getParent() instanceof VerbDefinition) {
- return ((VerbDefinition) def.getParent()).getRest();
- }
-
- // are we already a choice?
- if (def instanceof VerbDefinition) {
- return ((VerbDefinition) def).getRest();
- }
- // okay end this and get back to the choice
- def = end();
- if (def.getParent() instanceof VerbDefinition) {
- return ((VerbDefinition) def.getParent()).getRest();
- }
-
- // are we already a choice?
- if (def instanceof VerbDefinition) {
- return ((VerbDefinition) def).getRest();
+ RouteDefinition route = ProcessorDefinitionHelper.getRoute(def);
+ if (route != null) {
+ return route.getRestDefinition();
}
- throw new IllegalArgumentException("Cannot find VerbDefinition to allow endRest");
+ throw new IllegalArgumentException("Cannot find RouteDefinition to allow endRest");
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
index 7f12ccf..5ecd5a4 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -44,6 +44,7 @@ import org.apache.camel.builder.AdviceWithTask;
import org.apache.camel.builder.ErrorHandlerBuilderRef;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultRouteContext;
+import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.processor.interceptor.HandleFault;
import org.apache.camel.spi.LifecycleStrategy;
import org.apache.camel.spi.RouteContext;
@@ -81,6 +82,7 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
// (will by default be context scoped of no explicit error handler configured)
private boolean contextScopedErrorHandler = true;
private Boolean rest;
+ private RestDefinition restDefinition;
public RouteDefinition() {
}
@@ -779,6 +781,15 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
return rest;
}
+ public RestDefinition getRestDefinition() {
+ return restDefinition;
+ }
+
+ @XmlTransient
+ public void setRestDefinition(RestDefinition restDefinition) {
+ this.restDefinition = restDefinition;
+ }
+
@SuppressWarnings("deprecation")
public boolean isContextScopedErrorHandler(CamelContext context) {
if (!contextScopedErrorHandler) {
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 9301ef9..e40c663 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
@@ -131,17 +131,39 @@ public class RestDefinition {
return this;
}
- @Deprecated
- public VerbDefinition to(String url) {
+ /**
+ * Routes directly to the given endpoint.
+ * <p/>
+ * If you need additional routing capabilities, then use {@link #route()} instead.
+ *
+ * @param uri the uri of the endpoint
+ * @return this builder
+ */
+ public RestDefinition to(String uri) {
// add to last verb
if (getVerbs().isEmpty()) {
throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
}
+ ToDefinition to = new ToDefinition(uri);
+
VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
- verb.addOutput(new ToDefinition(url));
+ verb.setTo(to);
+ return this;
+ }
- return verb;
+ public RouteDefinition route() {
+ // add to last verb
+ if (getVerbs().isEmpty()) {
+ throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
+ }
+
+ // link them together so we can navigate using Java DSL
+ RouteDefinition route = new RouteDefinition();
+ route.setRestDefinition(this);
+ VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
+ verb.setRoute(route);
+ return route;
}
// Implementation
@@ -191,10 +213,19 @@ public class RestDefinition {
from = from + "?" + query;
}
- RouteDefinition route = new RouteDefinition();
+ // either the verb has a singular to or a embedded route
+ RouteDefinition route = verb.getRoute();
+ if (route == null) {
+ // it was a singular to, so add a new route and add the singular
+ // to as output to this route
+ route = new RouteDefinition();
+ route.getOutputs().add(verb.getTo());
+ }
+
+ // the route should be from this rest endpoint
route.fromRest(from);
+ route.setRestDefinition(this);
answer.add(route);
- route.getOutputs().addAll(verb.getOutputs());
}
return answer;
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/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 4347e75..fd73f02 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
@@ -19,14 +19,18 @@ package org.apache.camel.model.rest;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
-import org.apache.camel.model.OutputDefinition;
+import org.apache.camel.model.OptionalIdentifiedDefinition;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.ToDefinition;
@XmlRootElement(name = "verb")
@XmlAccessorType(XmlAccessType.FIELD)
-public class VerbDefinition extends OutputDefinition<VerbDefinition> {
+public class VerbDefinition {
@XmlAttribute
private String method;
@@ -37,17 +41,22 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
@XmlAttribute
private String consumes;
+ // used by XML DSL to either select a <to> or <route>
+ // so we need to use the common type OptionalIdentifiedDefinition
+ @XmlElements({
+ @XmlElement(required = false, name = "to", type = ToDefinition.class),
+ @XmlElement(required = false, name = "route", type = RouteDefinition.class)}
+ )
+ private OptionalIdentifiedDefinition toOrRoute;
+
+ // the Java DSL uses the to or route definition directory
+ @XmlTransient
+ private ToDefinition to;
+ @XmlTransient
+ private RouteDefinition route;
@XmlTransient
private RestDefinition rest;
- public RestDefinition getRest() {
- return rest;
- }
-
- public void setRest(RestDefinition rest) {
- this.rest = rest;
- }
-
public String getMethod() {
return method;
}
@@ -72,6 +81,52 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
this.consumes = consumes;
}
+ public RestDefinition getRest() {
+ return rest;
+ }
+
+ public void setRest(RestDefinition rest) {
+ this.rest = rest;
+ }
+
+ public RouteDefinition getRoute() {
+ if (route != null) {
+ return route;
+ } else if (toOrRoute instanceof RouteDefinition) {
+ return (RouteDefinition) toOrRoute;
+ } else {
+ return null;
+ }
+ }
+
+ public void setRoute(RouteDefinition route) {
+ this.route = route;
+ this.toOrRoute = route;
+ }
+
+ public ToDefinition getTo() {
+ if (to != null) {
+ return to;
+ } else if (toOrRoute instanceof ToDefinition) {
+ return (ToDefinition) toOrRoute;
+ } else {
+ return null;
+ }
+ }
+
+ public void setTo(ToDefinition to) {
+ this.to = to;
+ this.toOrRoute = to;
+ }
+
+ public OptionalIdentifiedDefinition getToOrRoute() {
+ return toOrRoute;
+ }
+
+ public void setToOrRoute(OptionalIdentifiedDefinition toOrRoute) {
+ this.toOrRoute = toOrRoute;
+ }
+
// Fluent API
// -------------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
index 49fb6c8..3f22c0f 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
@@ -41,7 +41,7 @@ public class FromRestConfigurationTest extends FromRestGetTest {
.get().to("direct:hello");
rest("/say/bye")
- .get().consumes("application/json").to("direct:bye").endRest()
+ .get().consumes("application/json").to("direct:bye")
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
index 9e6d44c..3220f2e 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
@@ -32,7 +32,7 @@ public class FromRestExplicitComponentTest extends FromRestGetTest {
.get().to("direct:hello");
rest("dummy-rest").uri("/say/bye")
- .get().consumes("application/json").to("direct:bye").endRest()
+ .get().consumes("application/json").to("direct:bye")
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
index 088085d..ce96957 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -43,7 +43,7 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
assertNotNull(rest);
assertEquals("/say/hello", rest.getUri());
assertEquals(1, rest.getVerbs().size());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
assertEquals("mock:hello", to.getUri());
rest = context.getRestDefinitions().get(1);
@@ -51,7 +51,7 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
assertEquals("/say/bye", rest.getUri());
assertEquals(2, rest.getVerbs().size());
assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
- to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
assertEquals("mock:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
@@ -72,13 +72,16 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
public void configure() throws Exception {
rest("/say/hello")
.get()
+ .route()
.to("mock:hello")
.transform(constant("Hello World"));
rest("/say/bye")
.get().consumes("application/json")
+ .route()
.to("mock:bye")
.transform(constant("Bye World"))
+ .endRest()
.post()
.to("mock:update");
}
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
index 9a09a7d..7f2d439 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
@@ -17,9 +17,41 @@
package org.apache.camel.component.rest;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.rest.RestDefinition;
public class FromRestGetEndPathTest extends FromRestGetTest {
+ public void testFromRestModel() throws Exception {
+ assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+
+ assertEquals(2, context.getRestDefinitions().size());
+ RestDefinition rest = context.getRestDefinitions().get(0);
+ assertNotNull(rest);
+ assertEquals("/say/hello", rest.getUri());
+ assertEquals(1, rest.getVerbs().size());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
+ assertEquals("direct:hello", to.getUri());
+
+ rest = context.getRestDefinitions().get(1);
+ assertNotNull(rest);
+ assertEquals("/say/bye", rest.getUri());
+ assertEquals(2, rest.getVerbs().size());
+ assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
+ assertEquals("direct:bye", to.getUri());
+
+ // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
+ getMockEndpoint("mock:update").expectedMessageCount(1);
+ template.sendBody("seda:post-say-bye", "I was here");
+ assertMockEndpointsSatisfied();
+
+ String out = template.requestBody("seda:get-say-hello", "Me", String.class);
+ assertEquals("Hello World", out);
+ String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
+ assertEquals("Bye World", out2);
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@@ -29,7 +61,7 @@ public class FromRestGetEndPathTest extends FromRestGetTest {
.get().to("direct:hello");
rest("/say/bye")
- .get().consumes("application/json").to("direct:bye").endRest()
+ .get().consumes("application/json").route().to("direct:bye").endRest()
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index 2b40fd4..02864db 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -43,7 +43,7 @@ public class FromRestGetTest extends ContextTestSupport {
assertNotNull(rest);
assertEquals("/say/hello", rest.getUri());
assertEquals(1, rest.getVerbs().size());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
assertEquals("direct:hello", to.getUri());
rest = context.getRestDefinitions().get(1);
@@ -51,7 +51,7 @@ public class FromRestGetTest extends ContextTestSupport {
assertEquals("/say/bye", rest.getUri());
assertEquals(2, rest.getVerbs().size());
assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
- to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
assertEquals("direct:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
index 5369d4a..3a5da15 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestUriPrefixTest.java
@@ -33,9 +33,9 @@ public class FromRestUriPrefixTest extends FromRestGetTest {
assertEquals("/hello", rest.getVerbs().get(0).getUri());
assertEquals("bye", rest.getVerbs().get(1).getUri());
assertEquals("/bye", rest.getVerbs().get(2).getUri());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
assertEquals("direct:hello", to.getUri());
- to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getOutputs().get(0));
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getTo());
assertEquals("direct:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java
new file mode 100644
index 0000000..9e09b89
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetEmbeddedRouteTest.java
@@ -0,0 +1,93 @@
+/**
+ * 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.management;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.rest.DummyRestConsumerFactory;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.impl.SimpleRegistry;
+
+public class ManagedFromRestGetEmbeddedRouteTest extends ManagementTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ SimpleRegistry registry = new SimpleRegistry();
+ registry.put("dummy-test", new DummyRestConsumerFactory());
+ return new DefaultCamelContext(registry);
+ }
+
+ public void testFromRestModel() throws Exception {
+ // JMX tests dont work well on AIX CI servers (hangs them)
+ if (isPlatform("aix")) {
+ return;
+ }
+
+ MBeanServer mbeanServer = getMBeanServer();
+
+ ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
+
+ String xml = (String) mbeanServer.invoke(on, "dumpRestsAsXml", null, null);
+ assertNotNull(xml);
+ log.info(xml);
+
+ assertTrue(xml.contains("<rests"));
+ assertTrue(xml.contains("<rest uri=\"/say/hello\">"));
+ assertTrue(xml.contains("<rest uri=\"/say/bye\">"));
+ assertTrue(xml.contains("</rest>"));
+ assertTrue(xml.contains("<get>"));
+ assertTrue(xml.contains("<route"));
+ assertTrue(xml.contains("<transform"));
+ assertTrue(xml.contains("<post>"));
+ assertTrue(xml.contains("application/json"));
+ assertTrue(xml.contains("</rests>"));
+
+ String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
+ log.info(xml2);
+ // and we should have rest in the routes that indicate its from a rest dsl
+ assertTrue(xml2.contains("rest=\"true\""));
+
+ // there should be 2 + 1 routes
+ assertEquals(2 + 1, context.getRouteDefinitions().size());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ rest("/say/hello")
+ .get()
+ .route()
+ .to("mock:hello")
+ .transform(constant("Hello World"));
+
+ rest("/say/bye")
+ .get().consumes("application/json")
+ .route()
+ .to("mock:bye")
+ .transform(constant("Bye World"))
+ .endRest()
+ .post()
+ .to("mock:update");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
index 47a307e..651359b 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
@@ -61,6 +61,9 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
log.info(xml2);
// and we should have rest in the routes that indicate its from a rest dsl
assertTrue(xml2.contains("rest=\"true\""));
+
+ // there should be 3 + 2 routes
+ assertEquals(3 + 2, context.getRouteDefinitions().size());
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
index 409a401..5c1809e 100644
--- a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
@@ -43,6 +43,7 @@ public class RestRestletGetTest extends RestletTestSupport {
// use the rest DSL to define the rest services
rest("/users/")
.get("{id}/basic")
+ .route()
.to("mock:input")
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
index 92ebbcf..cb00875 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
@@ -27,6 +27,7 @@ public class RestCamelSparkAcceptTest extends CamelSparkAcceptTest {
public void configure() throws Exception {
rest("/hello")
.get().consumes("application/json")
+ .route()
.to("mock:foo")
.transform().constant("{ \"reply\": \"Bye World\" }");
}
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
index c9d014f..2ae55fe 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
@@ -27,6 +27,7 @@ public class RestCamelSparkParamTest extends CamelSparkParamTest {
@Override
public void configure() throws Exception {
rest("/hello/{name}").get()
+ .route()
.to("mock:foo")
.transform().simple("Bye ${header.name}");
}
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
index eb7da29..0685e02 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
@@ -26,6 +26,7 @@ public class RestCamelSparkRequestBeanTest extends CamelSparkRequestBeanTest {
@Override
public void configure() throws Exception {
rest("/hello/*/to/*").get()
+ .route()
.to("mock:foo")
.bean(RestCamelSparkRequestBeanTest.class, "doSomething");
}
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
index 08f0b83..470623b 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
@@ -26,6 +26,7 @@ public class RestCamelSparkSplatTest extends CamelSparkSplatTest {
@Override
public void configure() throws Exception {
rest("/hello/*/to/*").get()
+ .route()
.to("mock:foo")
.transform().simple("Bye big ${header.splat[1]} from ${header.splat[0]}");
}
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
index 1b26601..4961e7e 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
@@ -29,18 +29,22 @@
<rest uri="/say/hello">
<get>
- <to uri="mock:hello"/>
- <transform>
- <constant>Hello World</constant>
- </transform>
+ <route>
+ <to uri="mock:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </route>
</get>
</rest>
<rest uri="/say/bye">
<get consumes="application/json">
- <to uri="mock:bye"/>
- <transform>
- <constant>Bye World</constant>
- </transform>
+ <route>
+ <to uri="mock:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
</get>
<post>
<to uri="mock:update"/>
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
index 9074f40..e0c9af6 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -41,7 +41,7 @@ public class FromRestGetEmbeddedRouteTest extends CamelBlueprintTestSupport {
assertNotNull(rest);
assertEquals("/say/hello", rest.getUri());
assertEquals(1, rest.getVerbs().size());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
assertEquals("mock:hello", to.getUri());
rest = context.getRestDefinitions().get(1);
@@ -49,7 +49,7 @@ public class FromRestGetEmbeddedRouteTest extends CamelBlueprintTestSupport {
assertEquals("/say/bye", rest.getUri());
assertEquals(2, rest.getVerbs().size());
assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
- to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(0));
assertEquals("mock:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
index af89205..68f1547 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
@@ -41,7 +41,7 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
assertNotNull(rest);
assertEquals("/say/hello", rest.getUri());
assertEquals(1, rest.getVerbs().size());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
assertEquals("direct:hello", to.getUri());
rest = context.getRestDefinitions().get(1);
@@ -49,7 +49,7 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
assertEquals("/say/bye", rest.getUri());
assertEquals(2, rest.getVerbs().size());
assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
- to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
assertEquals("direct:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
index cf6d7b8..1f22a26 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestUriPrefixTest.java
@@ -44,9 +44,9 @@ public class FromRestUriPrefixTest extends CamelBlueprintTestSupport {
assertEquals("/hello", rest.getVerbs().get(0).getUri());
assertEquals("bye", rest.getVerbs().get(1).getUri());
assertEquals("/bye", rest.getVerbs().get(2).getUri());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getTo());
assertEquals("direct:hello", to.getUri());
- to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getOutputs().get(0));
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(1).getTo());
assertEquals("direct:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
index 9caa545..3a1fb99 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
@@ -27,18 +27,22 @@
<rest uri="/say/hello">
<get>
- <to uri="mock:hello"/>
- <transform>
- <constant>Hello World</constant>
- </transform>
+ <route>
+ <to uri="mock:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </route>
</get>
</rest>
<rest uri="/say/bye">
<get consumes="application/json">
- <to uri="mock:bye"/>
- <transform>
- <constant>Bye World</constant>
- </transform>
+ <route>
+ <to uri="mock:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
</get>
<post>
<to uri="mock:update"/>
http://git-wip-us.apache.org/repos/asf/camel/blob/df7b90c4/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
index b8edb71..4c125f5 100644
--- a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
+++ b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
@@ -29,15 +29,18 @@ public class MySparkRouteBuilder extends RouteBuilder {
// configure we want to use spark-rest as the component for the rest DSL
restConfiguration().component("spark-rest");
- // use the rest DSL to define rest services
+ // use the rest DSL to define rest services, and use embedded routes
rest().uri("hello/:me")
.get().consumes("text/plain")
+ .route()
.to("log:input")
.transform().simple("Hello ${header.me}").endRest()
.get().consumes("application/json")
+ .route()
.to("log:input")
.transform().simple("{ \"message\": \"Hello ${header.me}\" }").endRest()
.get().consumes("text/xml")
+ .route()
.to("log:input")
.transform().simple("<message>Hello ${header.me}</message>");
}
[21/33] git commit: CAMEL-7354: Rest DSL can embed routes.
Posted by da...@apache.org.
CAMEL-7354: Rest DSL can embed routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/89a945bf
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/89a945bf
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/89a945bf
Branch: refs/heads/master
Commit: 89a945bf5c516af26adaa9e95d58980c68f20472
Parents: 96a521d
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 15 14:11:39 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:51 2014 +0200
----------------------------------------------------------------------
.../apache/camel/model/ProcessorDefinition.java | 32 +++++++
.../apache/camel/model/rest/PathDefinition.java | 6 +-
.../apache/camel/model/rest/VerbDefinition.java | 44 +++++----
.../rest/FromRestGetEmbeddedRouteTest.java | 94 ++++++++++++++++++++
.../component/rest/FromRestGetEndPathTest.java | 42 +++++++++
.../camel/component/rest/FromRestGetTest.java | 4 +-
.../SpringFromRestGetEmbeddedRouteTest.java | 44 +--------
.../rest/SpringFromRestGetEmbeddedRouteTest.xml | 3 +
.../component/rest/SpringFromRestGetTest.xml | 1 +
.../rest/FromRestGetEmbeddedRouteTest.java | 74 +++++++++++++++
.../rest/FromRestGetEmbeddedRouteTest.xml | 50 +++++++++++
.../component/rest/FromRestGetTest.xml | 1 +
12 files changed, 330 insertions(+), 65 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index 1503d3c..d2301b6 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -52,6 +52,8 @@ import org.apache.camel.builder.ProcessorBuilder;
import org.apache.camel.model.language.ConstantExpression;
import org.apache.camel.model.language.ExpressionDefinition;
import org.apache.camel.model.language.LanguageExpression;
+import org.apache.camel.model.rest.PathDefinition;
+import org.apache.camel.model.rest.VerbDefinition;
import org.apache.camel.processor.InterceptEndpointProcessor;
import org.apache.camel.processor.Pipeline;
import org.apache.camel.processor.aggregate.AggregationStrategy;
@@ -1317,6 +1319,36 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
}
/**
+ * Ends the current block and returns back to the {@link ChoiceDefinition choice()} DSL.
+ *
+ * @return the builder
+ */
+ public PathDefinition endPath() {
+ ProcessorDefinition<?> def = this;
+ if (def.getParent() instanceof VerbDefinition) {
+ return ((VerbDefinition) def.getParent()).getPath();
+ }
+
+ // are we already a choice?
+ if (def instanceof VerbDefinition) {
+ return ((VerbDefinition) def).getPath();
+ }
+
+ // okay end this and get back to the choice
+ def = end();
+ if (def.getParent() instanceof VerbDefinition) {
+ return ((VerbDefinition) def.getParent()).getPath();
+ }
+
+ // are we already a choice?
+ if (def instanceof VerbDefinition) {
+ return ((VerbDefinition) def).getPath();
+ }
+
+ throw new IllegalArgumentException("Cannot find VerbDefinition to allow endPath");
+ }
+
+ /**
* Ends the current block and returns back to the {@link TryDefinition doTry()} DSL.
*
* @return the builder
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
index c41a610..92b072c 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -69,6 +69,7 @@ public class PathDefinition {
public PathDefinition get(String url) {
GetVerbDefinition answer = new GetVerbDefinition();
+ answer.setPath(this);
getVerbs().add(answer);
if (url != null) {
answer.setUri(url);
@@ -82,6 +83,7 @@ public class PathDefinition {
public PathDefinition post(String url) {
PostVerbDefinition answer = new PostVerbDefinition();
+ answer.setPath(this);
getVerbs().add(answer);
if (url != null) {
answer.setUri(url);
@@ -101,7 +103,7 @@ public class PathDefinition {
return this;
}
- public PathDefinition to(String url) {
+ public VerbDefinition to(String url) {
// add to last verb
if (getVerbs().isEmpty()) {
throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
@@ -110,7 +112,7 @@ public class PathDefinition {
VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
verb.addOutput(new ToDefinition(url));
- return this;
+ return verb;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/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 6dea3de..c4e006e 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
@@ -16,19 +16,17 @@
*/
package org.apache.camel.model.rest;
-import java.util.ArrayList;
-import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
-import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.OutputDefinition;
@XmlRootElement(name = "verb")
@XmlAccessorType(XmlAccessType.FIELD)
-public class VerbDefinition {
+public class VerbDefinition extends OutputDefinition<VerbDefinition> {
@XmlAttribute
private String routeId;
@@ -42,8 +40,16 @@ public class VerbDefinition {
@XmlAttribute
private String accept;
- @XmlElementRef
- private List<ProcessorDefinition<?>> outputs = new ArrayList<ProcessorDefinition<?>>();
+ @XmlTransient
+ private PathDefinition path;
+
+ public PathDefinition getPath() {
+ return path;
+ }
+
+ public void setPath(PathDefinition path) {
+ this.path = path;
+ }
public String getRouteId() {
return routeId;
@@ -77,21 +83,23 @@ public class VerbDefinition {
this.accept = accept;
}
- public List<ProcessorDefinition<?>> getOutputs() {
- return outputs;
+ // Fluent API
+ // -------------------------------------------------------------------------
+
+ public PathDefinition get() {
+ return path.get();
}
- public void setOutputs(List<ProcessorDefinition<?>> outputs) {
- this.outputs = outputs;
+ public PathDefinition get(String url) {
+ return path.get(url);
+ }
- if (outputs != null) {
- for (ProcessorDefinition<?> output : outputs) {
- output.configureChild(output);
- }
- }
+ public PathDefinition post() {
+ return path.post();
}
- public void addOutput(ProcessorDefinition<?> output) {
- outputs.add(output);
+ public PathDefinition post(String url) {
+ return path.post(url);
}
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
new file mode 100644
index 0000000..af5815a
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -0,0 +1,94 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.rest.PathDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+
+public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("dummy-test", new DummyRestConsumerFactory());
+ return jndi;
+ }
+
+ protected int getExpectedNumberOfRoutes() {
+ return 3;
+ }
+
+ public void testFromRestModel() throws Exception {
+ assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+
+ RestDefinition rest = context.getRestDefinitions().get(0);
+ assertNotNull(rest);
+
+ // we should have a hello and bye route
+ assertNotNull(context.getRouteDefinition("hello"));
+ assertNotNull(context.getRouteDefinition("bye"));
+
+ PathDefinition path = rest.getPaths().get(0);
+ assertNotNull(0);
+ assertEquals("/say", path.getUri());
+
+ assertEquals("/hello", path.getVerbs().get(0).getUri());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("mock:hello", to.getUri());
+
+ assertEquals("/bye", path.getVerbs().get(1).getUri());
+ assertEquals("application/json", path.getVerbs().get(1).getAccept());
+ to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
+ assertEquals("mock:bye", to.getUri());
+
+ assertEquals(null, path.getVerbs().get(2).getUri());
+
+ // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
+
+ getMockEndpoint("mock:update").expectedMessageCount(1);
+ template.sendBody("seda:post-say", "I was here");
+ assertMockEndpointsSatisfied();
+
+ String out = template.requestBody("seda:get-say-hello", "Me", String.class);
+ assertEquals("Hello World", out);
+ String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
+ assertEquals("Bye World", out2);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ rest()
+ .path("/say")
+ .get("/hello").routeId("hello")
+ .to("mock:hello")
+ .transform(constant("Hello World"))
+ .get("/bye").accept("application/json").routeId("bye")
+ .to("mock:bye")
+ .transform(constant("Bye World"))
+ .post()
+ .to("mock:update");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
new file mode 100644
index 0000000..4910716
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
@@ -0,0 +1,42 @@
+/**
+ * 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.builder.RouteBuilder;
+
+public class FromRestGetEndPathTest extends FromRestGetTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ rest()
+ .path("/say")
+ .get("/hello").routeId("hello").to("direct:hello").endPath()
+ .get("/bye").accept("application/json").routeId("bye").to("direct:bye").endPath()
+ .post().to("mock:update");
+
+ from("direct:hello")
+ .transform().constant("Hello World");
+
+ from("direct:bye")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index f9076a6..7042051 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -80,8 +80,8 @@ public class FromRestGetTest extends ContextTestSupport {
public void configure() throws Exception {
rest()
.path("/say")
- .get("/hello").routeId("hello").to("direct:hello")
- .get("/bye").accept("application/json").routeId("bye").to("direct:bye")
+ .get("/hello").routeId("hello").to("direct:hello").endPath()
+ .get("/bye").accept("application/json").routeId("bye").to("direct:bye").endPath()
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.java
index daee273..9acb598 100644
--- a/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.java
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.java
@@ -17,52 +17,10 @@
package org.apache.camel.component.rest;
import org.apache.camel.CamelContext;
-import org.apache.camel.model.TransformDefinition;
-import org.apache.camel.model.rest.PathDefinition;
-import org.apache.camel.model.rest.RestDefinition;
import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
-public class SpringFromRestGetEmbeddedRouteTest extends FromRestGetTest {
-
- @Override
- protected int getExpectedNumberOfRoutes() {
- return 3;
- }
-
- public void testFromRestModel() throws Exception {
- assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
-
- RestDefinition rest = context.getRestDefinitions().get(0);
- assertNotNull(rest);
-
- // we should have a hello and bye route
- assertNotNull(context.getRouteDefinition("hello"));
- assertNotNull(context.getRouteDefinition("bye"));
-
- PathDefinition path = rest.getPaths().get(0);
- assertNotNull(0);
- assertEquals("/say", path.getUri());
-
- assertEquals("/hello", path.getVerbs().get(0).getUri());
- assertIsInstanceOf(TransformDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
-
- assertEquals("/bye", path.getVerbs().get(1).getUri());
- assertEquals("application/json", path.getVerbs().get(1).getAccept());
-
- assertEquals(null, path.getVerbs().get(2).getUri());
-
- // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
-
- getMockEndpoint("mock:update").expectedMessageCount(1);
- template.sendBody("seda:post-say", "I was here");
- assertMockEndpointsSatisfied();
-
- String out = template.requestBody("seda:get-say-hello", "Me", String.class);
- assertEquals("Hello World", out);
- String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
- assertEquals("Bye World", out2);
- }
+public class SpringFromRestGetEmbeddedRouteTest extends FromRestGetEmbeddedRouteTest {
protected CamelContext createCamelContext() throws Exception {
return createSpringCamelContext(this, "org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml");
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
index ed9bc34..bd78d08 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
@@ -30,11 +30,13 @@
<rest component="dummy-rest">
<path uri="/say">
<get uri="/hello" routeId="hello">
+ <to uri="mock:hello"/>
<transform>
<constant>Hello World</constant>
</transform>
</get>
<get uri="/bye" accept="application/json" routeId="bye">
+ <to uri="mock:bye"/>
<transform>
<constant>Bye World</constant>
</transform>
@@ -44,6 +46,7 @@
</post>
</path>
</rest>
+
</camelContext>
</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
index 918085f..9bbd736 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
@@ -53,6 +53,7 @@
<constant>Bye World</constant>
</transform>
</route>
+
</camelContext>
</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
new file mode 100644
index 0000000..3671dfc
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -0,0 +1,74 @@
+/**
+ * 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.test.blueprint.component.rest;
+
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.rest.PathDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
+import org.junit.Test;
+
+public class FromRestGetEmbeddedRouteTest extends CamelBlueprintTestSupport {
+
+ @Override
+ protected String getBlueprintDescriptor() {
+ return "org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml";
+ }
+
+ protected int getExpectedNumberOfRoutes() {
+ return 3;
+ }
+
+ @Test
+ public void testFromRestModel() throws Exception {
+ assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+
+ RestDefinition rest = context.getRestDefinitions().get(0);
+ assertNotNull(rest);
+
+ // we should have a hello and bye route
+ assertNotNull(context.getRouteDefinition("hello"));
+ assertNotNull(context.getRouteDefinition("bye"));
+
+ PathDefinition path = rest.getPaths().get(0);
+ assertNotNull(0);
+ assertEquals("/say", path.getUri());
+
+ assertEquals("/hello", path.getVerbs().get(0).getUri());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("mock:hello", to.getUri());
+
+ assertEquals("/bye", path.getVerbs().get(1).getUri());
+ assertEquals("application/json", path.getVerbs().get(1).getAccept());
+ to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
+ assertEquals("mock:bye", to.getUri());
+
+ assertEquals(null, path.getVerbs().get(2).getUri());
+
+ // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
+
+ getMockEndpoint("mock:update").expectedMessageCount(1);
+ template.sendBody("seda:post-say", "I was here");
+ assertMockEndpointsSatisfied();
+
+ String out = template.requestBody("seda:get-say-hello", "Me", String.class);
+ assertEquals("Hello World", out);
+ String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
+ assertEquals("Bye World", out2);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
new file mode 100644
index 0000000..cf415fb
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <!-- use a dummy rest consumer factory for the rest engine -->
+ <bean id="dummy-rest" class="org.apache.camel.test.blueprint.component.rest.DummyRestConsumerFactory"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+ <rest component="dummy-rest">
+ <path uri="/say">
+ <get uri="/hello" routeId="hello">
+ <to uri="mock:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </get>
+ <get uri="/bye" accept="application/json" routeId="bye">
+ <to uri="mock:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </get>
+ <post>
+ <to uri="mock:update"/>
+ </post>
+ </path>
+ </rest>
+
+ </camelContext>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/89a945bf/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
index ff38c7a..55db1fd 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
@@ -51,6 +51,7 @@
<constant>Bye World</constant>
</transform>
</route>
+
</camelContext>
</blueprint>
\ No newline at end of file
[28/33] git commit: CAMEL-7364: Rest DSL allow to configure rest
usign restConfiguration. Added rest DSL support to camel-restlet.
Posted by da...@apache.org.
CAMEL-7364: Rest DSL allow to configure rest usign restConfiguration. Added rest DSL support to camel-restlet.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2f856a6b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2f856a6b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2f856a6b
Branch: refs/heads/master
Commit: 2f856a6bf67ad994e48a950e4f6dc1e859e287b8
Parents: b2f4196
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 17 20:56:36 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:53 2014 +0200
----------------------------------------------------------------------
.../java/org/apache/camel/CamelContext.java | 15 +++
.../org/apache/camel/builder/RouteBuilder.java | 21 +++-
.../camel/component/rest/RestComponent.java | 5 +
.../apache/camel/impl/DefaultCamelContext.java | 21 ++--
.../apache/camel/model/ModelCamelContext.java | 11 --
.../model/rest/RestConfigurationDefinition.java | 51 +++++++++
.../apache/camel/model/rest/RestDefinition.java | 7 +-
.../org/apache/camel/spi/RestConfiguration.java | 104 +++++++++++++++++++
.../org/apache/camel/model/rest/jaxb.index | 3 +
.../rest/FromRestConfigurationTest.java | 54 ++++++++++
.../blueprint/CamelContextFactoryBean.java | 2 +-
.../camel/blueprint/BlueprintJaxbRestTest.java | 4 +
.../src/test/resources/test-rest.xml | 2 +-
.../xml/AbstractCamelContextFactoryBean.java | 3 +-
.../component/restlet/RestletComponent.java | 23 ++--
.../component/sparkrest/SparkComponent.java | 10 ++
.../RestConfigurationCamelSparkTest.java | 75 +++++++++++++
.../camel/spring/CamelContextFactoryBean.java | 2 +-
.../spring/handler/CamelNamespaceHandler.java | 1 +
.../rest/SpringFromRestConfigurationTest.java | 29 ++++++
.../rest/SpringFromRestConfigurationTest.xml | 61 +++++++++++
.../rest/FromRestConfigurationTest.java | 37 +++++++
.../rest/FromRestConfigurationTest.xml | 59 +++++++++++
23 files changed, 555 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index d1156fd..96f6374 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -51,6 +51,7 @@ import org.apache.camel.spi.NodeIdFactory;
import org.apache.camel.spi.PackageScanClassResolver;
import org.apache.camel.spi.ProcessorFactory;
import org.apache.camel.spi.Registry;
+import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RouteStartupOrder;
import org.apache.camel.spi.RuntimeEndpointRegistry;
import org.apache.camel.spi.ServicePool;
@@ -406,6 +407,20 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
void addRestDefinitions(Collection<RestDefinition> restDefinitions) throws Exception;
/**
+ * Sets a custom {@link org.apache.camel.spi.RestConfiguration}
+ *
+ * @param restConfiguration the REST configuration
+ */
+ void setRestConfiguration(RestConfiguration restConfiguration);
+
+ /**
+ * Gets the current REST configuration
+ *
+ * @return the configuration, or <tt>null</tt> if none has been configured.
+ */
+ RestConfiguration getRestConfiguration();
+
+ /**
* Returns the order in which the route inputs was started.
* <p/>
* The order may not be according to the startupOrder defined on the route.
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index 903ad41..c53979e 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -33,6 +33,7 @@ import org.apache.camel.model.RoutesDefinition;
import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.model.rest.RestsDefinition;
+import org.apache.camel.spi.RestConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -46,6 +47,7 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
protected Logger log = LoggerFactory.getLogger(getClass());
private AtomicBoolean initialized = new AtomicBoolean(false);
private RestsDefinition restCollection = new RestsDefinition();
+ private RestConfigurationDefinition restConfiguration;
private RoutesDefinition routeCollection = new RoutesDefinition();
public RouteBuilder() {
@@ -72,16 +74,15 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
public abstract void configure() throws Exception;
/**
- * Creates a new REST service
+ * Configures the REST services
*
* @return the builder
*/
public RestConfigurationDefinition restConfiguration() {
- if (getContext().getRestConfigurationDefinition() == null) {
- RestConfigurationDefinition config = new RestConfigurationDefinition();
- getContext().setRestConfigurationDefinition(config);
+ if (restConfiguration == null) {
+ restConfiguration = new RestConfigurationDefinition();
}
- return getContext().getRestConfigurationDefinition();
+ return restConfiguration;
}
/**
@@ -401,6 +402,12 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
throw new IllegalArgumentException("CamelContext has not been injected!");
}
getRestCollection().setCamelContext(camelContext);
+
+ // setup rest configuration before adding the rests
+ if (getRestConfiguration() != null) {
+ RestConfiguration config = getRestConfiguration().asRestConfiguration(getContext());
+ camelContext.setRestConfiguration(config);
+ }
camelContext.addRestDefinitions(getRestCollection().getRests());
}
@@ -408,6 +415,10 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
return restCollection;
}
+ public RestConfigurationDefinition getRestConfiguration() {
+ return restConfiguration;
+ }
+
public void setRestCollection(RestsDefinition restCollection) {
this.restCollection = restCollection;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
index efa2990..d595de6 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
@@ -44,6 +44,11 @@ public class RestComponent extends UriEndpointComponent {
answer.setVerb(verb);
answer.setPath(path);
+ // if no explicit component name was given, then fallback and use default configured component name
+ if (answer.getComponentName() == null && getCamelContext().getRestConfiguration() != null) {
+ answer.setComponentName(getCamelContext().getRestConfiguration().getComponent());
+ }
+
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 09884cf..5e75018 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -82,7 +82,6 @@ import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RouteDefinitionHelper;
import org.apache.camel.model.RoutesDefinition;
-import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.processor.interceptor.BacklogDebugger;
import org.apache.camel.processor.interceptor.BacklogTracer;
@@ -116,6 +115,7 @@ import org.apache.camel.spi.NodeIdFactory;
import org.apache.camel.spi.PackageScanClassResolver;
import org.apache.camel.spi.ProcessorFactory;
import org.apache.camel.spi.Registry;
+import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RouteContext;
import org.apache.camel.spi.RouteStartupOrder;
import org.apache.camel.spi.RuntimeEndpointRegistry;
@@ -174,7 +174,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
private ManagementMBeanAssembler managementMBeanAssembler;
private final List<RouteDefinition> routeDefinitions = new ArrayList<RouteDefinition>();
private final List<RestDefinition> restDefinitions = new ArrayList<RestDefinition>();
- private RestConfigurationDefinition restConfigurationDefinition = new RestConfigurationDefinition();
+ private RestConfiguration restConfiguration;
private List<InterceptStrategy> interceptStrategies = new ArrayList<InterceptStrategy>();
// special flags to control the first startup which can are special
@@ -713,6 +713,9 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
}
public synchronized void addRouteDefinitions(Collection<RouteDefinition> routeDefinitions) throws Exception {
+ if (routeDefinitions == null || routeDefinitions.isEmpty()) {
+ return;
+ }
for (RouteDefinition routeDefinition : routeDefinitions) {
removeRouteDefinition(routeDefinition);
}
@@ -1416,22 +1419,26 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
}
public void addRestDefinitions(Collection<RestDefinition> restDefinitions) throws Exception {
+ if (restDefinitions == null || restDefinitions.isEmpty()) {
+ return;
+ }
+
this.restDefinitions.addAll(restDefinitions);
// convert rests into routes so we reuse routes for runtime
List<RouteDefinition> routes = new ArrayList<RouteDefinition>();
for (RestDefinition rest : restDefinitions) {
- routes.addAll(rest.asRouteDefinition(this, restConfigurationDefinition));
+ routes.addAll(rest.asRouteDefinition(this));
}
addRouteDefinitions(routes);
}
- public RestConfigurationDefinition getRestConfigurationDefinition() {
- return restConfigurationDefinition;
+ public RestConfiguration getRestConfiguration() {
+ return restConfiguration;
}
- public void setRestConfigurationDefinition(RestConfigurationDefinition restConfigurationDefinition) {
- this.restConfigurationDefinition = restConfigurationDefinition;
+ public void setRestConfiguration(RestConfiguration restConfiguration) {
+ this.restConfiguration = restConfiguration;
}
public List<InterceptStrategy> getInterceptStrategies() {
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java b/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
index 7682a28..912aa62 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
@@ -22,7 +22,6 @@ import java.util.List;
import java.util.Map;
import org.apache.camel.CamelContext;
-import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestDefinition;
/**
@@ -104,16 +103,6 @@ public interface ModelCamelContext extends CamelContext {
List<RestDefinition> getRestDefinitions();
/**
- * Sets the REST configuration
- */
- void setRestConfigurationDefinition(RestConfigurationDefinition restConfigurationDefinition);
-
- /**
- * Returns the REST configuration
- */
- RestConfigurationDefinition getRestConfigurationDefinition();
-
- /**
* Adds a collection of rest definitions to the context
*
* @param restDefinitions the rest(s) definition to add
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
index 2f1375a..0e8c170 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
@@ -21,6 +21,10 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.camel.CamelContext;
+import org.apache.camel.spi.RestConfiguration;
+import org.apache.camel.util.CamelContextHelper;
+
/**
* Represents an XML <restConfiguration/> element
*/
@@ -37,6 +41,11 @@ public class RestConfigurationDefinition {
@XmlAttribute
private String port;
+ // TODO: get properties to work with JAXB in the XSD model
+
+// @XmlElementRef
+// private List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
+
public String getComponent() {
return component;
}
@@ -87,4 +96,46 @@ public class RestConfigurationDefinition {
return this;
}
+ public RestConfigurationDefinition property(String key, String value) {
+ /*PropertyDefinition prop = new PropertyDefinition();
+ prop.setKey(key);
+ prop.setValue(value);
+ getProperties().add(prop);*/
+ return this;
+ }
+
+ // Implementation
+ //-------------------------------------------------------------------------
+
+ /**
+ * Creates a {@link org.apache.camel.spi.RestConfiguration} instance based on the definition
+ *
+ * @param context the camel context
+ * @return the configuration
+ * @throws Exception is thrown if error creating the configuration
+ */
+ public RestConfiguration asRestConfiguration(CamelContext context) throws Exception {
+ RestConfiguration answer = new RestConfiguration();
+ if (getComponent() != null) {
+ answer.setComponent(CamelContextHelper.parseText(context, getComponent()));
+ }
+ if (getHost() != null) {
+ answer.setHost(CamelContextHelper.parseText(context, getHost()));
+ }
+ if (getPort() != null) {
+ answer.setPort(CamelContextHelper.parseInteger(context, getPort()));
+ }
+ /*if (!properties.isEmpty()) {
+ Map<String, Object> props = new HashMap<String, Object>();
+ for (PropertyDefinition prop : properties) {
+ String key = prop.getKey();
+ String value = CamelContextHelper.parseText(context, prop.getValue());
+ props.put(key, value);
+ }
+ answer.setProperties(props);
+ }*/
+ return answer;
+
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/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 333ed00..9301ef9 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
@@ -27,7 +27,6 @@ import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.camel.CamelContext;
-import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ToDefinition;
import org.apache.camel.util.FileUtil;
@@ -177,20 +176,16 @@ public class RestDefinition {
* Camel routing engine can add and run. This allows us to define REST services using this
* REST DSL and turn those into regular Camel routes.
*/
- public List<RouteDefinition> asRouteDefinition(CamelContext camelContext, RestConfigurationDefinition configuration) throws Exception {
+ public List<RouteDefinition> asRouteDefinition(CamelContext camelContext) throws Exception {
List<RouteDefinition> answer = new ArrayList<RouteDefinition>();
for (VerbDefinition verb : getVerbs()) {
String from = "rest:" + verb.asVerb() + ":" + buildUri(verb);
// append options
Map<String, Object> options = new HashMap<String, Object>();
- if (configuration.getComponent() != null) {
- options.put("componentName", configuration.getComponent());
- }
if (verb.getConsumes() != null) {
options.put("consumes", verb.getConsumes());
}
- // TODO: add more options here
if (!options.isEmpty()) {
String query = URISupport.createQueryString(options);
from = from + "?" + query;
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java b/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
new file mode 100644
index 0000000..ab796b2
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/spi/RestConfiguration.java
@@ -0,0 +1,104 @@
+/**
+ * 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.spi;
+
+import java.util.Map;
+
+/**
+ * Configuration use by {@link org.apache.camel.spi.RestConsumerFactory} for Camel components to support
+ * the Camel {@link org.apache.camel.model.rest.RestDefinition rest} DSL.
+ */
+public class RestConfiguration {
+
+ private String component;
+ private String host;
+ private int port;
+ private Map<String, Object> properties;
+
+ /**
+ * Gets the name of the Camel component to use as the REST consumer
+ *
+ * @return the component name, or <tt>null</tt> to let Camel search the {@link Registry} to find suitable implementation
+ */
+ public String getComponent() {
+ return component;
+ }
+
+ /**
+ * Sets the name of the Camel component to use as the REST consumer
+ *
+ * @param componentName the name of the component (such as restlet, spark-rest, etc.)
+ */
+ public void setComponent(String componentName) {
+ this.component = componentName;
+ }
+
+ /**
+ * Gets the hostname to use by the REST consumer
+ *
+ * @return the hostname, or <tt>null</tt> to use default hostname
+ */
+ public String getHost() {
+ return host;
+ }
+
+ /**
+ * Sets the hostname to use by the REST consumer
+ *
+ * @param host the hostname
+ */
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ /**
+ * Gets the port to use by the REST consumer
+ *
+ * @return the port, or <tt>0</tt> or <tt>-1</tt> to use default port
+ */
+ public int getPort() {
+ return port;
+ }
+
+ /**
+ * Gets the port to use by the REST consumer
+ *
+ * @param port the port number
+ */
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ /**
+ * Gets additional options to use to configure the REST consumer
+ *
+ * @return additional options
+ */
+ public Map<String, Object> getProperties() {
+ return properties;
+ }
+
+ /**
+ * Sets additional options to use to configure the REST consumer
+ *
+ * @param properties the options
+ */
+ public void setProperties(Map<String, Object> properties) {
+ this.properties = properties;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
index 7dfc3b8..1c50df5 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
@@ -14,8 +14,11 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ------------------------------------------------------------------------
+DeleteVerbDefinition
GetVerbDefinition
+HeadVerbDefinition
PostVerbDefinition
+PutVerbDefinition
RestConfigurationDefinition
RestDefinition
RestsDefinition
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
new file mode 100644
index 0000000..73992cc
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.builder.RouteBuilder;
+
+public class FromRestConfigurationTest extends FromRestGetTest {
+
+ @Override
+ public void testFromRestModel() throws Exception {
+ super.testFromRestModel();
+
+ assertEquals("dummy-rest", context.getRestConfiguration().getComponent());
+ assertEquals("localhost", context.getRestConfiguration().getHost());
+ assertEquals(9090, context.getRestConfiguration().getPort());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().component("dummy-rest").host("localhost").port(9090);
+
+ rest("/say/hello")
+ .get().to("direct:hello");
+
+ rest("/say/bye")
+ .get().consumes("application/json").to("direct:bye").endRest()
+ .post().to("mock:update");
+
+ from("direct:hello")
+ .transform().constant("Hello World");
+
+ from("direct:bye")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
index 313b61a..d40ef6f 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
@@ -637,7 +637,7 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu
return restConfiguration;
}
- public void setRestConfigurationDefinition(RestConfigurationDefinition restConfiguration) {
+ public void setRestConfiguration(RestConfigurationDefinition restConfiguration) {
this.restConfiguration = restConfiguration;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
index 6b2ffb2..00e4ae4 100644
--- a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
+++ b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
@@ -77,5 +77,9 @@ public class BlueprintJaxbRestTest extends TestSupport {
assertEquals("get", cfb.getRests().get(0).getVerbs().get(0).asVerb());
assertEquals("get", cfb.getRests().get(1).getVerbs().get(0).asVerb());
assertEquals("post", cfb.getRests().get(1).getVerbs().get(1).asVerb());
+
+ assertEquals("dummy-rest", cfb.getRestConfiguration().getComponent());
+ assertEquals("localhost", cfb.getRestConfiguration().getHost());
+ assertEquals("9090", cfb.getRestConfiguration().getPort());
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-blueprint/src/test/resources/test-rest.xml
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/resources/test-rest.xml b/components/camel-blueprint/src/test/resources/test-rest.xml
index 50075fe..f2a4598 100644
--- a/components/camel-blueprint/src/test/resources/test-rest.xml
+++ b/components/camel-blueprint/src/test/resources/test-rest.xml
@@ -21,7 +21,7 @@
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
- <restConfiguration component="dummy-rest"/>
+ <restConfiguration component="dummy-rest" host="localhost" port="9090"/>
<rest uri="/say/hello">
<get>
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index b89485d..6d6b9ce 100644
--- a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -84,6 +84,7 @@ import org.apache.camel.spi.NodeIdFactory;
import org.apache.camel.spi.PackageScanClassResolver;
import org.apache.camel.spi.PackageScanFilter;
import org.apache.camel.spi.ProcessorFactory;
+import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RuntimeEndpointRegistry;
import org.apache.camel.spi.ShutdownStrategy;
import org.apache.camel.spi.StreamCachingStrategy;
@@ -687,7 +688,7 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
ctx.setTypeConverterStatisticsEnabled(getTypeConverterStatisticsEnabled());
}
if (getRestConfiguration() != null) {
- ctx.setRestConfigurationDefinition(getRestConfiguration());
+ ctx.setRestConfiguration(getRestConfiguration().asRestConfiguration(ctx));
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
index 0862dfb..176032c 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
@@ -27,9 +27,8 @@ import org.apache.camel.Consumer;
import org.apache.camel.Endpoint;
import org.apache.camel.Processor;
import org.apache.camel.impl.HeaderFilterStrategyComponent;
-import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RestConsumerFactory;
-import org.apache.camel.util.CamelContextHelper;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.URISupport;
import org.apache.camel.util.UnsafeUriCharactersEncoder;
@@ -476,18 +475,18 @@ public class RestletComponent extends HeaderFilterStrategyComponent implements R
path = FileUtil.stripLeadingSeparator(path);
- ModelCamelContext model = (ModelCamelContext) getCamelContext();
-
- String host = "0.0.0.0";
int port = 0;
- if (model.getRestConfigurationDefinition() != null) {
- String value = model.getRestConfigurationDefinition().getPort();
- if (value != null) {
- port = CamelContextHelper.parseInteger(model, value);
+ String host = "0.0.0.0";
+
+ // if no explicit port/host configured, then use port from rest configuration
+ RestConfiguration config = getCamelContext().getRestConfiguration();
+ if (config != null && (config.getComponent() == null || config.getComponent().equals("restlet"))) {
+ int num = config.getPort();
+ if (num > 0) {
+ port = num;
}
- value = model.getRestConfigurationDefinition().getHost();
- if (value != null) {
- host = CamelContextHelper.parseText(model, value);
+ if (config.getHost() != null) {
+ host = config.getHost();
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
index d055ce0..c14e3fe 100644
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
+++ b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
@@ -25,6 +25,7 @@ import org.apache.camel.Consumer;
import org.apache.camel.Endpoint;
import org.apache.camel.Processor;
import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RestConsumerFactory;
import org.apache.camel.util.ObjectHelper;
import spark.Spark;
@@ -92,6 +93,15 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
if (getPort() != SparkBase.SPARK_DEFAULT_PORT) {
Spark.setPort(getPort());
+ } else {
+ // if no explicit port configured, then use port from rest configuration
+ RestConfiguration config = getCamelContext().getRestConfiguration();
+ if (config != null && (config.getComponent() == null || config.getComponent().equals("spark-rest"))) {
+ int port = config.getPort();
+ if (port > 0) {
+ Spark.setPort(port);
+ }
+ }
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestConfigurationCamelSparkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestConfigurationCamelSparkTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestConfigurationCamelSparkTest.java
new file mode 100644
index 0000000..b6811af
--- /dev/null
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestConfigurationCamelSparkTest.java
@@ -0,0 +1,75 @@
+/**
+ * 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.sparkrest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.AvailablePortFinder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class RestConfigurationCamelSparkTest extends CamelTestSupport {
+
+ private int port;
+
+ @Test
+ public void testSparkHello() throws Exception {
+ String out = template.requestBody("http://0.0.0.0:" + port + "/spark/hello", null, String.class);
+ assertEquals("Hello World", out);
+ }
+
+ @Test
+ public void testSparkBye() throws Exception {
+ String out = template.requestBody("http://0.0.0.0:" + port + "/spark/bye", null, String.class);
+ assertEquals("Bye World", out);
+ }
+
+ @Test
+ public void testSparkPost() throws Exception {
+ getMockEndpoint("mock:update").expectedBodiesReceived("I did this");
+
+ template.requestBody("http://0.0.0.0:" + port + "/spark/bye", "I did this", String.class);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ port = AvailablePortFinder.getNextAvailable(24500);
+
+ // configure port on rest configuration which spark-rest will pickup and use
+ restConfiguration().component("spark-rest").port(port);
+
+ // will automatic find the spark component to use, as we setup that component in the BaseSparkTest
+ rest("/spark/hello")
+ .get().to("direct:hello");
+
+ rest("/spark/bye")
+ .get().to("direct:bye")
+ .post().to("mock:update");
+
+ from("direct:hello")
+ .transform().constant("Hello World");
+
+ from("direct:bye")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
index e436dbb..478c4f1 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
@@ -410,7 +410,7 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
return restConfiguration;
}
- public void setRestConfigurationDefinition(RestConfigurationDefinition restConfiguration) {
+ public void setRestConfiguration(RestConfigurationDefinition restConfiguration) {
this.restConfiguration = restConfiguration;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
index 66efd34..1c256bd 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
@@ -313,6 +313,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport {
CamelContextFactoryBean factoryBean = (CamelContextFactoryBean) value;
builder.addPropertyValue("id", contextId);
builder.addPropertyValue("implicitId", implicitId);
+ builder.addPropertyValue("restConfiguration", factoryBean.getRestConfiguration());
builder.addPropertyValue("rests", factoryBean.getRests());
builder.addPropertyValue("routes", factoryBean.getRoutes());
builder.addPropertyValue("intercepts", factoryBean.getIntercepts());
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestConfigurationTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestConfigurationTest.java
new file mode 100644
index 0000000..4139633
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestConfigurationTest.java
@@ -0,0 +1,29 @@
+/**
+ * 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.CamelContext;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringFromRestConfigurationTest extends FromRestConfigurationTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml
new file mode 100644
index 0000000..79c84e5
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- use a dummy rest consumer factory for the rest engine -->
+ <bean id="dummy-rest" class="org.apache.camel.component.rest.DummyRestConsumerFactory"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <restConfiguration component="dummy-rest" host="localhost" port="9090"/>
+
+ <rest uri="/say/hello">
+ <get>
+ <to uri="direct:hello"/>
+ </get>
+ </rest>
+ <rest uri="/say/bye">
+ <get consumes="application/json">
+ <to uri="direct:bye"/>
+ </get>
+ <post>
+ <to uri="mock:update"/>
+ </post>
+ </rest>
+
+ <route>
+ <from uri="direct:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </route>
+ <route>
+ <from uri="direct:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+
+ </camelContext>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.java
new file mode 100644
index 0000000..b2e6f91
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.java
@@ -0,0 +1,37 @@
+/**
+ * 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.test.blueprint.component.rest;
+
+import org.junit.Test;
+
+public class FromRestConfigurationTest extends FromRestGetTest {
+
+ @Override
+ protected String getBlueprintDescriptor() {
+ return "org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml";
+ }
+
+ @Test
+ public void testFromRestModel() throws Exception {
+ super.testFromRestModel();
+
+ assertEquals("dummy-rest", context.getRestConfiguration().getComponent());
+ assertEquals("localhost", context.getRestConfiguration().getHost());
+ assertEquals(9090, context.getRestConfiguration().getPort());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f856a6b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml
new file mode 100644
index 0000000..9fa70e0
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <!-- use a dummy rest consumer factory for the rest engine -->
+ <bean id="dummy-rest" class="org.apache.camel.test.blueprint.component.rest.DummyRestConsumerFactory"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+ <restConfiguration component="dummy-rest" host="localhost" port="9090"/>
+
+ <rest uri="/say/hello">
+ <get>
+ <to uri="direct:hello"/>
+ </get>
+ </rest>
+ <rest uri="/say/bye">
+ <get consumes="application/json">
+ <to uri="direct:bye"/>
+ </get>
+ <post>
+ <to uri="mock:update"/>
+ </post>
+ </rest>
+
+ <route>
+ <from uri="direct:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </route>
+ <route>
+ <from uri="direct:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+
+ </camelContext>
+
+</blueprint>
\ No newline at end of file
[25/33] git commit: CAMEL-7354: migrated spark example to use Rest DSL
Posted by da...@apache.org.
CAMEL-7354: migrated spark example to use Rest DSL
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1a315668
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1a315668
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1a315668
Branch: refs/heads/master
Commit: 1a31566816418d4b1e574a0533905a27aad7f82d
Parents: 6d40039
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 17 08:48:20 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:52 2014 +0200
----------------------------------------------------------------------
.../camel/component/rest/RestEndpoint.java | 18 ++++++++++--
.../camel-example-spark-rest-tomcat/README.txt | 2 +-
.../example/spark/MySparkRouteBuilder.java | 29 ++++++++++----------
3 files changed, 31 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1a315668/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
index b0f546e..9f05502 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -21,6 +21,7 @@ import java.util.Set;
import org.apache.camel.Component;
import org.apache.camel.Consumer;
+import org.apache.camel.NoSuchBeanException;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultEndpoint;
@@ -101,11 +102,22 @@ public class RestEndpoint extends DefaultEndpoint {
RestConsumerFactory factory = null;
if (getComponentName() != null) {
- Component comp = getCamelContext().getComponent(getComponentName());
+ Object comp = getCamelContext().getRegistry().lookupByName(getComponentName());
if (comp != null && comp instanceof RestConsumerFactory) {
factory = (RestConsumerFactory) comp;
- } else if (comp != null) {
- throw new IllegalArgumentException("Component " + getComponentName() + " is not a RestConsumerFactory");
+ } else {
+ comp = getCamelContext().getComponent(getComponentName());
+ if (comp != null && comp instanceof RestConsumerFactory) {
+ factory = (RestConsumerFactory) comp;
+ }
+ }
+
+ if (factory == null) {
+ if (comp != null) {
+ throw new IllegalArgumentException("Component " + getComponentName() + " is not a RestConsumerFactory");
+ } else {
+ throw new NoSuchBeanException(getComponentName(), RestConsumerFactory.class.getName());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/1a315668/examples/camel-example-spark-rest-tomcat/README.txt
----------------------------------------------------------------------
diff --git a/examples/camel-example-spark-rest-tomcat/README.txt b/examples/camel-example-spark-rest-tomcat/README.txt
index 809c2ab..70a2ce6 100644
--- a/examples/camel-example-spark-rest-tomcat/README.txt
+++ b/examples/camel-example-spark-rest-tomcat/README.txt
@@ -1,7 +1,7 @@
Camel Spark REST and Apache Tomcat example
=======================================
-This example shows how to use Spark REST to define REST endpoints in Camel routes using the CamelSparkRouteBuilder DSL
+This example shows how to use Spark REST to define REST endpoints in Camel routes using the Rest DSL
You will need to package this example first:
mvn package
http://git-wip-us.apache.org/repos/asf/camel/blob/1a315668/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
index ce7b137..7d9a849 100644
--- a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
+++ b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
@@ -16,29 +16,30 @@
*/
package org.apache.camel.example.spark;
-import org.apache.camel.component.sparkrest.SparkRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
/**
- * Define REST services using {@link SparkRouteBuilder}.
+ * Define REST services using the Camel REST DSL
*/
-public class MySparkRouteBuilder extends SparkRouteBuilder {
+public class MySparkRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
- // this is a very simple Camel route, but we can do more routing
- // as SparkRouteBuilder extends the regular RouteBuilder from camel-core
- // which means we can do any kind of Camel Java DSL routing here
// we only have a GET service, but we have PUT, POST, and all the other REST verbs we can use
- get("hello/:me", "text/plain")
- .transform().simple("Hello ${header.me}");
-
- get("hello/:me", "application/json")
- .transform().simple("{ \"message\": \"Hello ${header.me}\" }");
-
- get("hello/:me", "text/xml")
- .transform().simple("<message>Hello ${header.me}</message>");
+ rest().component("spark-rest")
+ .path("hello/:me").get().consumes("text/plain")
+ .to("log:input")
+ .transform().simple("Hello ${header.me}")
+ .endPath()
+ .path("hello/:me").get().consumes("application/json")
+ .to("log:input")
+ .transform().simple("{ \"message\": \"Hello ${header.me}\" }")
+ .endPath()
+ .path("hello/:me").get().consumes("text/xml")
+ .to("log:input")
+ .transform().simple("<message>Hello ${header.me}</message>");
}
}
[22/33] git commit: CAMEL-7364: Rest DSL made simpler by removing
path as we define the uri in rest instead.
Posted by da...@apache.org.
CAMEL-7364: Rest DSL made simpler by removing path as we define the uri in rest instead.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3c52555f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3c52555f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3c52555f
Branch: refs/heads/master
Commit: 3c52555f11daead08033a6981a59bebd86525432
Parents: 1a31566
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 17 10:25:48 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:52 2014 +0200
----------------------------------------------------------------------
.../org/apache/camel/builder/RouteBuilder.java | 5 +-
.../apache/camel/model/ProcessorDefinition.java | 16 +-
.../apache/camel/model/rest/PathDefinition.java | 145 -------------------
.../apache/camel/model/rest/RestDefinition.java | 140 +++++++++++++-----
.../camel/model/rest/RestsDefinition.java | 3 +-
.../apache/camel/model/rest/VerbDefinition.java | 39 +++--
.../org/apache/camel/model/rest/jaxb.index | 1 -
.../rest/FromRestGetEmbeddedRouteTest.java | 43 +++---
.../component/rest/FromRestGetEndPathTest.java | 10 +-
.../camel/component/rest/FromRestGetTest.java | 32 ++--
.../management/ManagedFromRestGetTest.java | 22 +--
.../camel/blueprint/BlueprintJaxbRestTest.java | 17 +--
.../src/test/resources/test-rest.xml | 32 ++--
.../sparkrest/RestCamelSparkAcceptTest.java | 7 +-
.../sparkrest/RestCamelSparkComponentTest.java | 16 +-
.../sparkrest/RestCamelSparkParamTest.java | 2 +-
.../RestCamelSparkRequestBeanTest.java | 2 +-
.../sparkrest/RestCamelSparkSplatTest.java | 2 +-
.../component/sparkrest/RestCamelSparkTest.java | 14 +-
.../rest/SpringFromRestGetEmbeddedRouteTest.xml | 38 +++--
.../component/rest/SpringFromRestGetTest.xml | 26 ++--
.../rest/FromRestGetEmbeddedRouteTest.java | 20 +--
.../component/rest/FromRestGetTest.java | 20 +--
.../rest/FromRestGetEmbeddedRouteTest.xml | 38 +++--
.../component/rest/FromRestGetTest.xml | 26 ++--
.../example/spark/MySparkRouteBuilder.java | 14 +-
26 files changed, 322 insertions(+), 408 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index 3659a84..0fb2a52 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -74,11 +74,12 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
/**
* Creates a new REST service
*
+ * @param uri the path
* @return the builder
*/
- public RestDefinition rest() {
+ public RestDefinition rest(String uri) {
getRestCollection().setCamelContext(getContext());
- RestDefinition answer = getRestCollection().rest();
+ RestDefinition answer = getRestCollection().rest(uri);
configureRest(answer);
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index e5140f2..b7095fc 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -52,7 +52,7 @@ import org.apache.camel.builder.ProcessorBuilder;
import org.apache.camel.model.language.ConstantExpression;
import org.apache.camel.model.language.ExpressionDefinition;
import org.apache.camel.model.language.LanguageExpression;
-import org.apache.camel.model.rest.PathDefinition;
+import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.model.rest.VerbDefinition;
import org.apache.camel.processor.InterceptEndpointProcessor;
import org.apache.camel.processor.Pipeline;
@@ -1319,33 +1319,33 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
}
/**
- * Ends the current block and returns back to the {@link PathDefinition path()} DSL.
+ * Ends the current block and returns back to the {@link org.apache.camel.model.rest.RestDefinition rest()} DSL.
*
* @return the builder
*/
- public PathDefinition endPath() {
+ public RestDefinition endRest() {
ProcessorDefinition<?> def = this;
if (def.getParent() instanceof VerbDefinition) {
- return ((VerbDefinition) def.getParent()).getPath();
+ return ((VerbDefinition) def.getParent()).getRest();
}
// are we already a choice?
if (def instanceof VerbDefinition) {
- return ((VerbDefinition) def).getPath();
+ return ((VerbDefinition) def).getRest();
}
// okay end this and get back to the choice
def = end();
if (def.getParent() instanceof VerbDefinition) {
- return ((VerbDefinition) def.getParent()).getPath();
+ return ((VerbDefinition) def.getParent()).getRest();
}
// are we already a choice?
if (def instanceof VerbDefinition) {
- return ((VerbDefinition) def).getPath();
+ return ((VerbDefinition) def).getRest();
}
- throw new IllegalArgumentException("Cannot find VerbDefinition to allow endPath");
+ throw new IllegalArgumentException("Cannot find VerbDefinition to allow endRest");
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
deleted file mode 100644
index dd811d6..0000000
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ /dev/null
@@ -1,145 +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.model.rest;
-
-import java.util.ArrayList;
-import java.util.List;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlElementRef;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-
-import org.apache.camel.model.ToDefinition;
-
-@XmlRootElement(name = "path")
-@XmlAccessorType(XmlAccessType.FIELD)
-public class PathDefinition {
-
- @XmlAttribute(required = true)
- private String uri;
- @XmlElementRef
- private List<VerbDefinition> verbs = new ArrayList<VerbDefinition>();
- @XmlTransient
- private RestDefinition rest;
-
- public String getUri() {
- return uri;
- }
-
- public void setUri(String uri) {
- this.uri = uri;
- }
-
- public List<VerbDefinition> getVerbs() {
- return verbs;
- }
-
- public void setVerbs(List<VerbDefinition> verbs) {
- this.verbs = verbs;
- }
-
- public RestDefinition getRest() {
- return rest;
- }
-
- public void setRest(RestDefinition rest) {
- this.rest = rest;
- }
-
- // Fluent API
- //-------------------------------------------------------------------------
-
- public PathDefinition path(String uri) {
- // add a new path on the rest
- return rest.path(uri);
- }
-
- public PathDefinition get() {
- return addVerb("get", null);
- }
-
- public PathDefinition post() {
- return addVerb("post", null);
- }
-
- public PathDefinition put() {
- return addVerb("put", null);
- }
-
- public PathDefinition delete() {
- return addVerb("delete", null);
- }
-
- public PathDefinition head() {
- return addVerb("head", null);
- }
-
- public PathDefinition verb(String verb) {
- return addVerb(verb, null);
- }
-
- public PathDefinition consumes(String accept) {
- // add to last verb
- if (getVerbs().isEmpty()) {
- throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
- }
-
- VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
- verb.setConsumes(accept);
-
- return this;
- }
-
- @Deprecated
- public VerbDefinition to(String url) {
- // add to last verb
- if (getVerbs().isEmpty()) {
- throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
- }
-
- VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
- verb.addOutput(new ToDefinition(url));
-
- return verb;
- }
-
- private PathDefinition addVerb(String verb, String url) {
- VerbDefinition answer;
-
- if ("get".equals(verb)) {
- answer = new GetVerbDefinition();
- } else if ("post".equals(verb)) {
- answer = new PostVerbDefinition();
- } else if ("delete".equals(verb)) {
- answer = new DeleteVerbDefinition();
- } else if ("head".equals(verb)) {
- answer = new HeadVerbDefinition();
- } else if ("put".equals(verb)) {
- answer = new PutVerbDefinition();
- } else {
- answer = new VerbDefinition();
- answer.setMethod(verb);
- }
-
- answer.setPath(this);
- getVerbs().add(answer);
- return this;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/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 6c3bb5f..460e081 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
@@ -28,6 +28,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.ToDefinition;
import org.apache.camel.util.URISupport;
/**
@@ -38,9 +39,19 @@ import org.apache.camel.util.URISupport;
public class RestDefinition {
@XmlAttribute
+ private String uri;
+ @XmlAttribute
private String component;
@XmlElementRef
- private List<PathDefinition> paths = new ArrayList<PathDefinition>();
+ private List<VerbDefinition> verbs = new ArrayList<VerbDefinition>();
+
+ public String getUri() {
+ return uri;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
public String getComponent() {
return component;
@@ -50,12 +61,12 @@ public class RestDefinition {
this.component = component;
}
- public List<PathDefinition> getPaths() {
- return paths;
+ public List<VerbDefinition> getVerbs() {
+ return verbs;
}
- public void setPaths(List<PathDefinition> paths) {
- this.paths = paths;
+ public void setVerbs(List<VerbDefinition> verbs) {
+ this.verbs = verbs;
}
// Fluent API
@@ -69,15 +80,79 @@ public class RestDefinition {
return this;
}
- /**
- * Defines the rest path to use
- */
- public PathDefinition path(String uri) {
- PathDefinition answer = new PathDefinition();
+ public RestDefinition get() {
+ return addVerb("get", null);
+ }
+
+ public RestDefinition post() {
+ return addVerb("post", null);
+ }
+
+ public RestDefinition put() {
+ return addVerb("put", null);
+ }
+
+ public RestDefinition delete() {
+ return addVerb("delete", null);
+ }
+
+ public RestDefinition head() {
+ return addVerb("head", null);
+ }
+
+ public RestDefinition verb(String verb) {
+ return addVerb(verb, null);
+ }
+
+ public RestDefinition consumes(String accept) {
+ // add to last verb
+ if (getVerbs().isEmpty()) {
+ throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
+ }
+
+ VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
+ verb.setConsumes(accept);
+
+ return this;
+ }
+
+ @Deprecated
+ public VerbDefinition to(String url) {
+ // add to last verb
+ if (getVerbs().isEmpty()) {
+ throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
+ }
+
+ VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
+ verb.addOutput(new ToDefinition(url));
+
+ return verb;
+ }
+
+ // Implementation
+ //-------------------------------------------------------------------------
+
+ private RestDefinition addVerb(String verb, String url) {
+ VerbDefinition answer;
+
+ if ("get".equals(verb)) {
+ answer = new GetVerbDefinition();
+ } else if ("post".equals(verb)) {
+ answer = new PostVerbDefinition();
+ } else if ("delete".equals(verb)) {
+ answer = new DeleteVerbDefinition();
+ } else if ("head".equals(verb)) {
+ answer = new HeadVerbDefinition();
+ } else if ("put".equals(verb)) {
+ answer = new PutVerbDefinition();
+ } else {
+ answer = new VerbDefinition();
+ answer.setMethod(verb);
+ }
+
answer.setRest(this);
- getPaths().add(answer);
- answer.setUri(uri);
- return answer;
+ getVerbs().add(answer);
+ return this;
}
/**
@@ -88,28 +163,25 @@ public class RestDefinition {
public List<RouteDefinition> asRouteDefinition(ModelCamelContext camelContext) throws Exception {
List<RouteDefinition> answer = new ArrayList<RouteDefinition>();
- for (PathDefinition path : getPaths()) {
- String uri = path.getUri();
- for (VerbDefinition verb : path.getVerbs()) {
- String from = "rest:" + verb.asVerb() + ":" + uri;
- // append options
- Map<String, Object> options = new HashMap<String, Object>();
- if (getComponent() != null) {
- options.put("componentName", getComponent());
- }
- if (verb.getConsumes() != null) {
- options.put("consumes", verb.getConsumes());
- }
- if (!options.isEmpty()) {
- String query = URISupport.createQueryString(options);
- from = from + "?" + query;
- }
-
- RouteDefinition route = new RouteDefinition();
- route.fromRest(from);
- answer.add(route);
- route.getOutputs().addAll(verb.getOutputs());
+ for (VerbDefinition verb : getVerbs()) {
+ String from = "rest:" + verb.asVerb() + ":" + uri;
+ // append options
+ Map<String, Object> options = new HashMap<String, Object>();
+ if (getComponent() != null) {
+ options.put("componentName", getComponent());
+ }
+ if (verb.getConsumes() != null) {
+ options.put("consumes", verb.getConsumes());
}
+ if (!options.isEmpty()) {
+ String query = URISupport.createQueryString(options);
+ from = from + "?" + query;
+ }
+
+ RouteDefinition route = new RouteDefinition();
+ route.fromRest(from);
+ answer.add(route);
+ route.getOutputs().addAll(verb.getOutputs());
}
return answer;
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
index 2a0ff25..ebc3057 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
@@ -77,8 +77,9 @@ public class RestsDefinition extends OptionalIdentifiedDefinition<RestsDefinitio
// Fluent API
//-------------------------------------------------------------------------
- public RestDefinition rest() {
+ public RestDefinition rest(String uri) {
RestDefinition rest = createRest();
+ rest.setUri(uri);
return rest(rest);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/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 ce1482e..282e562 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
@@ -35,14 +35,14 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
private String consumes;
@XmlTransient
- private PathDefinition path;
+ private RestDefinition rest;
- public PathDefinition getPath() {
- return path;
+ public RestDefinition getRest() {
+ return rest;
}
- public void setPath(PathDefinition path) {
- this.path = path;
+ public void setRest(RestDefinition rest) {
+ this.rest = rest;
}
public String getMethod() {
@@ -64,33 +64,28 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
// Fluent API
// -------------------------------------------------------------------------
- public PathDefinition path(String uri) {
- PathDefinition parent = endPath();
- return parent.path(uri);
+ public RestDefinition get() {
+ return rest.get();
}
- public PathDefinition get() {
- return path.get();
+ public RestDefinition post() {
+ return rest.post();
}
- public PathDefinition post() {
- return path.post();
+ public RestDefinition put() {
+ return rest.put();
}
- public PathDefinition put() {
- return path.put();
+ public RestDefinition delete() {
+ return rest.delete();
}
- public PathDefinition delete() {
- return path.delete();
+ public RestDefinition head() {
+ return rest.head();
}
- public PathDefinition head() {
- return path.head();
- }
-
- public PathDefinition verb(String verb) {
- return path.verb(verb);
+ public RestDefinition verb(String verb) {
+ return rest.verb(verb);
}
public String asVerb() {
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
index 77197e8..1816ffc 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
@@ -16,7 +16,6 @@
## ------------------------------------------------------------------------
GetVerbDefinition
PostVerbDefinition
-PathDefinition
RestDefinition
RestsDefinition
VerbDefinition
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
index ebb9847..088085d 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -20,7 +20,6 @@ import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.model.ToDefinition;
-import org.apache.camel.model.rest.PathDefinition;
import org.apache.camel.model.rest.RestDefinition;
public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
@@ -39,19 +38,20 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
public void testFromRestModel() throws Exception {
assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+ assertEquals(2, context.getRestDefinitions().size());
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
-
- assertEquals(2, rest.getPaths().size());
- PathDefinition path = rest.getPaths().get(0);
- assertEquals("/say/hello", path.getUri());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("/say/hello", rest.getUri());
+ assertEquals(1, rest.getVerbs().size());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
assertEquals("mock:hello", to.getUri());
- path = rest.getPaths().get(1);
- assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(0).getConsumes());
- to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ rest = context.getRestDefinitions().get(1);
+ assertNotNull(rest);
+ assertEquals("/say/bye", rest.getUri());
+ assertEquals(2, rest.getVerbs().size());
+ assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
assertEquals("mock:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
@@ -70,18 +70,17 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- rest()
- .path("/say/hello")
- .get()
- .to("mock:hello")
- .transform(constant("Hello World"))
- .endPath()
- .path("/say/bye")
- .get().consumes("application/json")
- .to("mock:bye")
- .transform(constant("Bye World"))
- .post()
- .to("mock:update");
+ rest("/say/hello")
+ .get()
+ .to("mock:hello")
+ .transform(constant("Hello World"));
+
+ rest("/say/bye")
+ .get().consumes("application/json")
+ .to("mock:bye")
+ .transform(constant("Bye World"))
+ .post()
+ .to("mock:update");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
index 7d60a09..9a09a7d 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
@@ -25,11 +25,11 @@ public class FromRestGetEndPathTest extends FromRestGetTest {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- rest()
- .path("/say/hello")
- .get().to("direct:hello").endPath()
- .path("/say/bye")
- .get().consumes("application/json").to("direct:bye").endPath()
+ rest("/say/hello")
+ .get().to("direct:hello");
+
+ rest("/say/bye")
+ .get().consumes("application/json").to("direct:bye").endRest()
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index 34fd0bb..fdbe60a 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -20,7 +20,6 @@ import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.JndiRegistry;
import org.apache.camel.model.ToDefinition;
-import org.apache.camel.model.rest.PathDefinition;
import org.apache.camel.model.rest.RestDefinition;
public class FromRestGetTest extends ContextTestSupport {
@@ -39,19 +38,20 @@ public class FromRestGetTest extends ContextTestSupport {
public void testFromRestModel() throws Exception {
assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+ assertEquals(2, context.getRestDefinitions().size());
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
-
- assertEquals(2, rest.getPaths().size());
- PathDefinition path = rest.getPaths().get(0);
- assertEquals("/say/hello", path.getUri());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("/say/hello", rest.getUri());
+ assertEquals(1, rest.getVerbs().size());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
assertEquals("direct:hello", to.getUri());
- path = rest.getPaths().get(1);
- assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(0).getConsumes());
- to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ rest = context.getRestDefinitions().get(1);
+ assertNotNull(rest);
+ assertEquals("/say/bye", rest.getUri());
+ assertEquals(2, rest.getVerbs().size());
+ assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
assertEquals("direct:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
@@ -70,12 +70,12 @@ public class FromRestGetTest extends ContextTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- rest()
- .path("/say/hello")
- .get().to("direct:hello")
- .path("/say/bye")
- .get().consumes("application/json").to("direct:bye")
- .post().to("mock:update");
+ rest("/say/hello")
+ .get().to("direct:hello");
+
+ rest("/say/bye")
+ .get().consumes("application/json").to("direct:bye")
+ .post().to("mock:update");
from("direct:hello")
.transform().constant("Hello World");
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
index 64d237c..47a307e 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
@@ -48,12 +48,14 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
assertNotNull(xml);
log.info(xml);
- assertTrue(xml.contains("rests"));
- assertTrue(xml.contains("rest"));
- assertTrue(xml.contains("<path uri=\"/say/hello\">"));
- assertTrue(xml.contains("<path uri=\"/say/bye\">"));
+ assertTrue(xml.contains("<rests"));
+ assertTrue(xml.contains("<rest uri=\"/say/hello\">"));
+ assertTrue(xml.contains("<rest uri=\"/say/bye\">"));
+ assertTrue(xml.contains("</rest>"));
assertTrue(xml.contains("<get>"));
assertTrue(xml.contains("<post>"));
+ assertTrue(xml.contains("application/json"));
+ assertTrue(xml.contains("</rests>"));
String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
log.info(xml2);
@@ -66,12 +68,12 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- rest()
- .path("/say/hello")
- .get().to("direct:hello")
- .path("/say/bye")
- .get().consumes("application/json").to("direct:bye")
- .post().to("mock:update");
+ rest("/say/hello")
+ .get().to("direct:hello");
+
+ rest("/say/bye")
+ .get().consumes("application/json").to("direct:bye")
+ .post().to("mock:update");
from("direct:hello")
.transform().constant("Hello World");
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
index a7e6d07..6b2ffb2 100644
--- a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
+++ b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
@@ -68,15 +68,14 @@ public class BlueprintJaxbRestTest extends TestSupport {
assertEquals(0, ((CamelContextFactoryBean) object).getRoutes().size());
CamelContextFactoryBean cfb = (CamelContextFactoryBean) object;
- assertEquals(1, cfb.getRests().size());
- assertEquals(2, cfb.getRests().get(0).getPaths().size());
- assertEquals("/say/hello", cfb.getRests().get(0).getPaths().get(0).getUri());
- assertEquals("/say/bye", cfb.getRests().get(0).getPaths().get(1).getUri());
+ assertEquals(2, cfb.getRests().size());
+ assertEquals("/say/hello", cfb.getRests().get(0).getUri());
+ assertEquals("/say/bye", cfb.getRests().get(1).getUri());
- assertEquals(1, cfb.getRests().get(0).getPaths().get(0).getVerbs().size());
- assertEquals(2, cfb.getRests().get(0).getPaths().get(1).getVerbs().size());
- assertEquals("get", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(0).asVerb());
- assertEquals("get", cfb.getRests().get(0).getPaths().get(1).getVerbs().get(0).asVerb());
- assertEquals("post", cfb.getRests().get(0).getPaths().get(1).getVerbs().get(1).asVerb());
+ assertEquals(1, cfb.getRests().get(0).getVerbs().size());
+ assertEquals(2, cfb.getRests().get(1).getVerbs().size());
+ assertEquals("get", cfb.getRests().get(0).getVerbs().get(0).asVerb());
+ assertEquals("get", cfb.getRests().get(1).getVerbs().get(0).asVerb());
+ assertEquals("post", cfb.getRests().get(1).getVerbs().get(1).asVerb());
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-blueprint/src/test/resources/test-rest.xml
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/resources/test-rest.xml b/components/camel-blueprint/src/test/resources/test-rest.xml
index 194eb4d..909496e 100644
--- a/components/camel-blueprint/src/test/resources/test-rest.xml
+++ b/components/camel-blueprint/src/test/resources/test-rest.xml
@@ -19,22 +19,20 @@
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
- <camelContext xmlns="http://camel.apache.org/schema/blueprint">
- <rest component="dummy-rest">
- <path uri="/say/hello">
- <get>
- <to uri="direct:hello"/>
- </get>
- </path>
- <path uri="/say/bye">
- <get>
- <to uri="direct:bye"/>
- </get>
- <post>
- <to uri="seda:update"/>
- </post>
- </path>
- </rest>
- </camelContext>
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+ <rest component="dummy-rest" uri="/say/hello">
+ <get>
+ <to uri="direct:hello"/>
+ </get>
+ </rest>
+ <rest component="dummy-rest" uri="/say/bye">
+ <get>
+ <to uri="direct:bye"/>
+ </get>
+ <post>
+ <to uri="seda:update"/>
+ </post>
+ </rest>
+ </camelContext>
</blueprint>
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
index 70b7636..92ebbcf 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkAcceptTest.java
@@ -25,9 +25,10 @@ public class RestCamelSparkAcceptTest extends CamelSparkAcceptTest {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- rest().path("/hello").get().consumes("application/json")
- .to("mock:foo")
- .transform().constant("{ \"reply\": \"Bye World\" }");
+ rest("/hello")
+ .get().consumes("application/json")
+ .to("mock:foo")
+ .transform().constant("{ \"reply\": \"Bye World\" }");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
index 216ffcb..01ce1c0 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
@@ -26,18 +26,18 @@ public class RestCamelSparkComponentTest extends RestCamelSparkTest {
@Override
public void configure() throws Exception {
// explicit configure that we want to use spark-rest component
- rest().component("spark-rest")
- .path("/spark/hello")
- .get().to("direct:hello")
- .path("/spark/bye")
- .get().to("direct:bye")
- .post().to("mock:update");
+ rest("/spark/hello").component("spark-rest")
+ .get().to("direct:hello");
+
+ rest("/spark/bye").component("spark-rest")
+ .get().to("direct:bye")
+ .post().to("mock:update");
from("direct:hello")
- .transform().constant("Hello World");
+ .transform().constant("Hello World");
from("direct:bye")
- .transform().constant("Bye World");
+ .transform().constant("Bye World");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
index 4133704..c9d014f 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkParamTest.java
@@ -26,7 +26,7 @@ public class RestCamelSparkParamTest extends CamelSparkParamTest {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- rest().path("/hello/{name}").get()
+ rest("/hello/{name}").get()
.to("mock:foo")
.transform().simple("Bye ${header.name}");
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
index f881f53..eb7da29 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkRequestBeanTest.java
@@ -25,7 +25,7 @@ public class RestCamelSparkRequestBeanTest extends CamelSparkRequestBeanTest {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- rest().path("/hello/*/to/*").get()
+ rest("/hello/*/to/*").get()
.to("mock:foo")
.bean(RestCamelSparkRequestBeanTest.class, "doSomething");
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
index fefb211..08f0b83 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkSplatTest.java
@@ -25,7 +25,7 @@ public class RestCamelSparkSplatTest extends CamelSparkSplatTest {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- rest().path("/hello/*/to/*").get()
+ rest("/hello/*/to/*").get()
.to("mock:foo")
.transform().simple("Bye big ${header.splat[1]} from ${header.splat[0]}");
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
index b6473e9..83137b0 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
@@ -48,16 +48,18 @@ public class RestCamelSparkTest extends BaseSparkTest {
@Override
public void configure() throws Exception {
// will automatic find the spark component to use, as we setup that component in the BaseSparkTest
- rest()
- .path("/spark/hello").get().to("direct:hello")
- .path("/spark/bye").get().to("direct:bye")
- .path("/spark/bye").post().to("mock:update");
+ rest("/spark/hello")
+ .get().to("direct:hello");
+
+ rest("/spark/bye")
+ .get().to("direct:bye")
+ .post().to("mock:update");
from("direct:hello")
- .transform().constant("Hello World");
+ .transform().constant("Hello World");
from("direct:bye")
- .transform().constant("Bye World");
+ .transform().constant("Bye World");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
index be3ff54..1b26601 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
@@ -27,26 +27,24 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
- <rest component="dummy-rest">
- <path uri="/say/hello">
- <get>
- <to uri="mock:hello"/>
- <transform>
- <constant>Hello World</constant>
- </transform>
- </get>
- </path>
- <path uri="/say/bye">
- <get consumes="application/json">
- <to uri="mock:bye"/>
- <transform>
- <constant>Bye World</constant>
- </transform>
- </get>
- <post>
- <to uri="mock:update"/>
- </post>
- </path>
+ <rest uri="/say/hello">
+ <get>
+ <to uri="mock:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </get>
+ </rest>
+ <rest uri="/say/bye">
+ <get consumes="application/json">
+ <to uri="mock:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </get>
+ <post>
+ <to uri="mock:update"/>
+ </post>
</rest>
</camelContext>
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
index c8681f7..4fa30ec 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
@@ -27,20 +27,18 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
- <rest component="dummy-rest">
- <path uri="/say/hello">
- <get>
- <to uri="direct:hello"/>
- </get>
- </path>
- <path uri="/say/bye">
- <get consumes="application/json">
- <to uri="direct:bye"/>
- </get>
- <post>
- <to uri="mock:update"/>
- </post>
- </path>
+ <rest uri="/say/hello">
+ <get>
+ <to uri="direct:hello"/>
+ </get>
+ </rest>
+ <rest uri="/say/bye">
+ <get consumes="application/json">
+ <to uri="direct:bye"/>
+ </get>
+ <post>
+ <to uri="mock:update"/>
+ </post>
</rest>
<route>
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
index 2ffb96c..9074f40 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -17,7 +17,6 @@
package org.apache.camel.test.blueprint.component.rest;
import org.apache.camel.model.ToDefinition;
-import org.apache.camel.model.rest.PathDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.junit.Test;
@@ -37,19 +36,20 @@ public class FromRestGetEmbeddedRouteTest extends CamelBlueprintTestSupport {
public void testFromRestModel() throws Exception {
assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+ assertEquals(2, context.getRestDefinitions().size());
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
-
- assertEquals(2, rest.getPaths().size());
- PathDefinition path = rest.getPaths().get(0);
- assertEquals("/say/hello", path.getUri());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("/say/hello", rest.getUri());
+ assertEquals(1, rest.getVerbs().size());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
assertEquals("mock:hello", to.getUri());
- path = rest.getPaths().get(1);
- assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(0).getConsumes());
- to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ rest = context.getRestDefinitions().get(1);
+ assertNotNull(rest);
+ assertEquals("/say/bye", rest.getUri());
+ assertEquals(2, rest.getVerbs().size());
+ assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
assertEquals("mock:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
index 6d51ffc..af89205 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
@@ -17,7 +17,6 @@
package org.apache.camel.test.blueprint.component.rest;
import org.apache.camel.model.ToDefinition;
-import org.apache.camel.model.rest.PathDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
import org.junit.Test;
@@ -37,19 +36,20 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
public void testFromRestModel() throws Exception {
assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
+ assertEquals(2, context.getRestDefinitions().size());
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
-
- assertEquals(2, rest.getPaths().size());
- PathDefinition path = rest.getPaths().get(0);
- assertEquals("/say/hello", path.getUri());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("/say/hello", rest.getUri());
+ assertEquals(1, rest.getVerbs().size());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
assertEquals("direct:hello", to.getUri());
- path = rest.getPaths().get(1);
- assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(0).getConsumes());
- to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ rest = context.getRestDefinitions().get(1);
+ assertNotNull(rest);
+ assertEquals("/say/bye", rest.getUri());
+ assertEquals(2, rest.getVerbs().size());
+ assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
+ to = assertIsInstanceOf(ToDefinition.class, rest.getVerbs().get(0).getOutputs().get(0));
assertEquals("direct:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
index f20fe8f..9caa545 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
@@ -25,26 +25,24 @@
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
- <rest component="dummy-rest">
- <path uri="/say/hello">
- <get>
- <to uri="mock:hello"/>
- <transform>
- <constant>Hello World</constant>
- </transform>
- </get>
- </path>
- <path uri="/say/bye">
- <get consumes="application/json">
- <to uri="mock:bye"/>
- <transform>
- <constant>Bye World</constant>
- </transform>
- </get>
- <post>
- <to uri="mock:update"/>
- </post>
- </path>
+ <rest uri="/say/hello">
+ <get>
+ <to uri="mock:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </get>
+ </rest>
+ <rest uri="/say/bye">
+ <get consumes="application/json">
+ <to uri="mock:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </get>
+ <post>
+ <to uri="mock:update"/>
+ </post>
</rest>
</camelContext>
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
index f3876a2..578ed92 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
@@ -25,20 +25,18 @@
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
- <rest component="dummy-rest">
- <path uri="/say/hello">
- <get>
- <to uri="direct:hello"/>
- </get>
- </path>
- <path uri="/say/bye">
- <get accept="application/json">
- <to uri="direct:bye"/>
- </get>
- <post>
- <to uri="mock:update"/>
- </post>
- </path>
+ <rest uri="/say/hello">
+ <get>
+ <to uri="direct:hello"/>
+ </get>
+ </rest>
+ <rest uri="/say/bye">
+ <get consumes="application/json">
+ <to uri="direct:bye"/>
+ </get>
+ <post>
+ <to uri="mock:update"/>
+ </post>
</rest>
<route>
http://git-wip-us.apache.org/repos/asf/camel/blob/3c52555f/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
index 7d9a849..891746a 100644
--- a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
+++ b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
@@ -28,16 +28,14 @@ public class MySparkRouteBuilder extends RouteBuilder {
// we only have a GET service, but we have PUT, POST, and all the other REST verbs we can use
- rest().component("spark-rest")
- .path("hello/:me").get().consumes("text/plain")
+ rest("hello/:me").component("spark-rest")
+ .get().consumes("text/plain")
.to("log:input")
- .transform().simple("Hello ${header.me}")
- .endPath()
- .path("hello/:me").get().consumes("application/json")
+ .transform().simple("Hello ${header.me}").endRest()
+ .get().consumes("application/json")
.to("log:input")
- .transform().simple("{ \"message\": \"Hello ${header.me}\" }")
- .endPath()
- .path("hello/:me").get().consumes("text/xml")
+ .transform().simple("{ \"message\": \"Hello ${header.me}\" }").endRest()
+ .get().consumes("text/xml")
.to("log:input")
.transform().simple("<message>Hello ${header.me}</message>");
}
[27/33] git commit: CAMEL-7364: Rest DSL allow to configure rest
usign restConfiguration. Added rest DSL support to camel-restlet.
Posted by da...@apache.org.
CAMEL-7364: Rest DSL allow to configure rest usign restConfiguration. Added rest DSL support to camel-restlet.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b2f41966
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b2f41966
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b2f41966
Branch: refs/heads/master
Commit: b2f419661479b879efe796ebac6e985d1b44c6fa
Parents: b3a717f
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jul 17 15:27:44 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:53 2014 +0200
----------------------------------------------------------------------
.../org/apache/camel/builder/RouteBuilder.java | 15 +++-
.../apache/camel/impl/DefaultCamelContext.java | 12 ++-
.../apache/camel/model/ModelCamelContext.java | 11 +++
.../model/rest/RestConfigurationDefinition.java | 90 ++++++++++++++++++++
.../apache/camel/model/rest/RestDefinition.java | 26 ++----
.../org/apache/camel/model/rest/jaxb.index | 1 +
.../rest/FromRestExplicitComponentTest.java | 7 +-
.../blueprint/CamelContextFactoryBean.java | 11 +++
.../src/test/resources/test-rest.xml | 8 +-
.../xml/AbstractCamelContextFactoryBean.java | 6 ++
.../component/restlet/RestletComponent.java | 38 ++++++++-
.../component/restlet/RestRestletGetTest.java | 56 ++++++++++++
.../sparkrest/RestCamelSparkComponentTest.java | 6 +-
.../camel/spring/CamelContextFactoryBean.java | 11 +++
.../example/spark/MySparkRouteBuilder.java | 24 +++---
15 files changed, 281 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index e5d36bf..903ad41 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -30,7 +30,7 @@ import org.apache.camel.model.OnCompletionDefinition;
import org.apache.camel.model.OnExceptionDefinition;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RoutesDefinition;
-
+import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.model.rest.RestsDefinition;
import org.slf4j.Logger;
@@ -76,6 +76,19 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
*
* @return the builder
*/
+ public RestConfigurationDefinition restConfiguration() {
+ if (getContext().getRestConfigurationDefinition() == null) {
+ RestConfigurationDefinition config = new RestConfigurationDefinition();
+ getContext().setRestConfigurationDefinition(config);
+ }
+ return getContext().getRestConfigurationDefinition();
+ }
+
+ /**
+ * Creates a new REST service
+ *
+ * @return the builder
+ */
public RestDefinition rest() {
getRestCollection().setCamelContext(getContext());
RestDefinition answer = getRestCollection().rest();
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index eca6e89..09884cf 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -82,6 +82,7 @@ import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RouteDefinitionHelper;
import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.processor.interceptor.BacklogDebugger;
import org.apache.camel.processor.interceptor.BacklogTracer;
@@ -173,6 +174,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
private ManagementMBeanAssembler managementMBeanAssembler;
private final List<RouteDefinition> routeDefinitions = new ArrayList<RouteDefinition>();
private final List<RestDefinition> restDefinitions = new ArrayList<RestDefinition>();
+ private RestConfigurationDefinition restConfigurationDefinition = new RestConfigurationDefinition();
private List<InterceptStrategy> interceptStrategies = new ArrayList<InterceptStrategy>();
// special flags to control the first startup which can are special
@@ -1419,11 +1421,19 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
// convert rests into routes so we reuse routes for runtime
List<RouteDefinition> routes = new ArrayList<RouteDefinition>();
for (RestDefinition rest : restDefinitions) {
- routes.addAll(rest.asRouteDefinition(this));
+ routes.addAll(rest.asRouteDefinition(this, restConfigurationDefinition));
}
addRouteDefinitions(routes);
}
+ public RestConfigurationDefinition getRestConfigurationDefinition() {
+ return restConfigurationDefinition;
+ }
+
+ public void setRestConfigurationDefinition(RestConfigurationDefinition restConfigurationDefinition) {
+ this.restConfigurationDefinition = restConfigurationDefinition;
+ }
+
public List<InterceptStrategy> getInterceptStrategies() {
return interceptStrategies;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java b/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
index 912aa62..7682a28 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import org.apache.camel.CamelContext;
+import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestDefinition;
/**
@@ -103,6 +104,16 @@ public interface ModelCamelContext extends CamelContext {
List<RestDefinition> getRestDefinitions();
/**
+ * Sets the REST configuration
+ */
+ void setRestConfigurationDefinition(RestConfigurationDefinition restConfigurationDefinition);
+
+ /**
+ * Returns the REST configuration
+ */
+ RestConfigurationDefinition getRestConfigurationDefinition();
+
+ /**
* Adds a collection of rest definitions to the context
*
* @param restDefinitions the rest(s) definition to add
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
new file mode 100644
index 0000000..2f1375a
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
@@ -0,0 +1,90 @@
+/**
+ * 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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Represents an XML <restConfiguration/> element
+ */
+@XmlRootElement(name = "restConfiguration")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class RestConfigurationDefinition {
+
+ @XmlAttribute
+ private String component;
+
+ @XmlAttribute
+ private String host;
+
+ @XmlAttribute
+ private String port;
+
+ public String getComponent() {
+ return component;
+ }
+
+ public void setComponent(String component) {
+ this.component = component;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public String getPort() {
+ return port;
+ }
+
+ public void setPort(String port) {
+ this.port = port;
+ }
+
+ // Fluent API
+ //-------------------------------------------------------------------------
+
+ /**
+ * To use a specific Camel rest component
+ */
+ public RestConfigurationDefinition component(String componentId) {
+ setComponent(componentId);
+ return this;
+ }
+
+ public RestConfigurationDefinition host(String host) {
+ setHost(host);
+ return this;
+ }
+
+ public RestConfigurationDefinition port(int port) {
+ setPort("" + port);
+ return this;
+ }
+
+ public RestConfigurationDefinition port(String port) {
+ setPort(port);
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/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 7257d37..333ed00 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
@@ -26,6 +26,7 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.camel.CamelContext;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ToDefinition;
@@ -41,8 +42,6 @@ public class RestDefinition {
@XmlAttribute
private String uri;
- @XmlAttribute
- private String component;
@XmlElementRef
private List<VerbDefinition> verbs = new ArrayList<VerbDefinition>();
@@ -54,14 +53,6 @@ public class RestDefinition {
this.uri = uri;
}
- public String getComponent() {
- return component;
- }
-
- public void setComponent(String component) {
- this.component = component;
- }
-
public List<VerbDefinition> getVerbs() {
return verbs;
}
@@ -81,14 +72,6 @@ public class RestDefinition {
return this;
}
- /**
- * To use a specific Camel rest component
- */
- public RestDefinition component(String componentId) {
- setComponent(componentId);
- return this;
- }
-
public RestDefinition get() {
return addVerb("get", null);
}
@@ -194,19 +177,20 @@ public class RestDefinition {
* Camel routing engine can add and run. This allows us to define REST services using this
* REST DSL and turn those into regular Camel routes.
*/
- public List<RouteDefinition> asRouteDefinition(ModelCamelContext camelContext) throws Exception {
+ public List<RouteDefinition> asRouteDefinition(CamelContext camelContext, RestConfigurationDefinition configuration) throws Exception {
List<RouteDefinition> answer = new ArrayList<RouteDefinition>();
for (VerbDefinition verb : getVerbs()) {
String from = "rest:" + verb.asVerb() + ":" + buildUri(verb);
// append options
Map<String, Object> options = new HashMap<String, Object>();
- if (getComponent() != null) {
- options.put("componentName", getComponent());
+ if (configuration.getComponent() != null) {
+ options.put("componentName", configuration.getComponent());
}
if (verb.getConsumes() != null) {
options.put("consumes", verb.getConsumes());
}
+ // TODO: add more options here
if (!options.isEmpty()) {
String query = URISupport.createQueryString(options);
from = from + "?" + query;
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
index 1816ffc..7dfc3b8 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
@@ -16,6 +16,7 @@
## ------------------------------------------------------------------------
GetVerbDefinition
PostVerbDefinition
+RestConfigurationDefinition
RestDefinition
RestsDefinition
VerbDefinition
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
index 63a1e48..9e6d44c 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestExplicitComponentTest.java
@@ -25,10 +25,13 @@ public class FromRestExplicitComponentTest extends FromRestGetTest {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- rest("/say/hello").component("dummy-rest")
+ // configure to use dummy-rest
+ restConfiguration().component("dummy-rest");
+
+ rest("/say/hello")
.get().to("direct:hello");
- rest().component("dummy-rest").uri("/say/bye")
+ rest("dummy-rest").uri("/say/bye")
.get().consumes("application/json").to("direct:bye").endRest()
.post().to("mock:update");
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
index f9cbaa0..313b61a 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
@@ -54,6 +54,7 @@ import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ThreadPoolProfileDefinition;
import org.apache.camel.model.config.PropertiesDefinition;
import org.apache.camel.model.dataformat.DataFormatsDefinition;
+import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.spi.PackageScanFilter;
import org.apache.camel.spi.Registry;
@@ -161,6 +162,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu
private List<InterceptFromDefinition> interceptFroms = new ArrayList<InterceptFromDefinition>();
@XmlElement(name = "interceptSendToEndpoint", required = false)
private List<InterceptSendToEndpointDefinition> interceptSendToEndpoints = new ArrayList<InterceptSendToEndpointDefinition>();
+ @XmlElement(name = "restConfiguration", required = false)
+ private RestConfigurationDefinition restConfiguration;
@XmlElement(name = "rest", required = false)
private List<RestDefinition> rests = new ArrayList<RestDefinition>();
@XmlElement(name = "route", required = false)
@@ -630,6 +633,14 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu
this.rests = rests;
}
+ public RestConfigurationDefinition getRestConfiguration() {
+ return restConfiguration;
+ }
+
+ public void setRestConfigurationDefinition(RestConfigurationDefinition restConfiguration) {
+ this.restConfiguration = restConfiguration;
+ }
+
public boolean isImplicitId() {
return implicitId;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/components/camel-blueprint/src/test/resources/test-rest.xml
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/resources/test-rest.xml b/components/camel-blueprint/src/test/resources/test-rest.xml
index 909496e..50075fe 100644
--- a/components/camel-blueprint/src/test/resources/test-rest.xml
+++ b/components/camel-blueprint/src/test/resources/test-rest.xml
@@ -20,12 +20,15 @@
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
- <rest component="dummy-rest" uri="/say/hello">
+
+ <restConfiguration component="dummy-rest"/>
+
+ <rest uri="/say/hello">
<get>
<to uri="direct:hello"/>
</get>
</rest>
- <rest component="dummy-rest" uri="/say/bye">
+ <rest uri="/say/bye">
<get>
<to uri="direct:bye"/>
</get>
@@ -33,6 +36,7 @@
<to uri="seda:update"/>
</post>
</rest>
+
</camelContext>
</blueprint>
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index b80fb6f..b89485d 100644
--- a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -60,6 +60,7 @@ import org.apache.camel.model.RouteDefinitionHelper;
import org.apache.camel.model.ThreadPoolProfileDefinition;
import org.apache.camel.model.config.PropertiesDefinition;
import org.apache.camel.model.dataformat.DataFormatsDefinition;
+import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestContainer;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.processor.interceptor.BacklogTracer;
@@ -542,6 +543,8 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
public abstract List<RestDefinition> getRests();
+ public abstract RestConfigurationDefinition getRestConfiguration();
+
public abstract List<? extends AbstractCamelEndpointFactoryBean> getEndpoints();
public abstract List<? extends AbstractCamelRedeliveryPolicyFactoryBean> getRedeliveryPolicies();
@@ -683,6 +686,9 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
if (getTypeConverterStatisticsEnabled() != null) {
ctx.setTypeConverterStatisticsEnabled(getTypeConverterStatisticsEnabled());
}
+ if (getRestConfiguration() != null) {
+ ctx.setRestConfigurationDefinition(getRestConfiguration());
+ }
}
protected void initThreadPoolProfiles(T context) throws Exception {
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
index 429c318..0862dfb 100644
--- a/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
+++ b/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
@@ -22,8 +22,15 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
import org.apache.camel.impl.HeaderFilterStrategyComponent;
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.spi.RestConsumerFactory;
+import org.apache.camel.util.CamelContextHelper;
+import org.apache.camel.util.FileUtil;
import org.apache.camel.util.URISupport;
import org.apache.camel.util.UnsafeUriCharactersEncoder;
import org.restlet.Component;
@@ -44,7 +51,7 @@ import org.slf4j.LoggerFactory;
*
* @version
*/
-public class RestletComponent extends HeaderFilterStrategyComponent {
+public class RestletComponent extends HeaderFilterStrategyComponent implements RestConsumerFactory {
private static final Logger LOG = LoggerFactory.getLogger(RestletComponent.class);
private final Map<String, Server> servers = new HashMap<String, Server>();
@@ -462,4 +469,33 @@ public class RestletComponent extends HeaderFilterStrategyComponent {
public void setMaxQueued(Integer maxQueued) {
this.maxQueued = maxQueued;
}
+
+ @Override
+ public Consumer createConsumer(CamelContext camelContext, Processor processor,
+ String verb, String path, String consumes, Map<String, Object> parameters) throws Exception {
+
+ path = FileUtil.stripLeadingSeparator(path);
+
+ ModelCamelContext model = (ModelCamelContext) getCamelContext();
+
+ String host = "0.0.0.0";
+ int port = 0;
+ if (model.getRestConfigurationDefinition() != null) {
+ String value = model.getRestConfigurationDefinition().getPort();
+ if (value != null) {
+ port = CamelContextHelper.parseInteger(model, value);
+ }
+ value = model.getRestConfigurationDefinition().getHost();
+ if (value != null) {
+ host = CamelContextHelper.parseText(model, value);
+ }
+ }
+
+ // get the endpoint
+ String url = String.format("restlet:http://%s:%s/%s?restletMethod=%s", host, port, path, verb);
+ RestletEndpoint endpoint = camelContext.getEndpoint(url, RestletEndpoint.class);
+ setProperties(endpoint, parameters);
+
+ return endpoint.createConsumer(processor);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
new file mode 100644
index 0000000..409a401
--- /dev/null
+++ b/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestRestletGetTest.java
@@ -0,0 +1,56 @@
+/**
+ * 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.restlet;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version
+ */
+public class RestRestletGetTest extends RestletTestSupport {
+
+ @Test
+ public void testRestletProducerGet() throws Exception {
+ String out = template.requestBody("http://localhost:" + portNum + "/users/123/basic", null, String.class);
+ assertEquals("123;Donald Duck", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use restlet on localhost with the given port
+ restConfiguration().component("restlet").host("localhost").port(portNum);
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .get("{id}/basic")
+ .to("mock:input")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String id = exchange.getIn().getHeader("id", String.class);
+ exchange.getOut().setBody(id + ";Donald Duck");
+ }
+ });
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
index 01ce1c0..bae4b69 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
@@ -26,10 +26,12 @@ public class RestCamelSparkComponentTest extends RestCamelSparkTest {
@Override
public void configure() throws Exception {
// explicit configure that we want to use spark-rest component
- rest("/spark/hello").component("spark-rest")
+ restConfiguration().component("spark-rest");
+
+ rest("/spark/hello")
.get().to("direct:hello");
- rest("/spark/bye").component("spark-rest")
+ rest("/spark/bye")
.get().to("direct:bye")
.post().to("mock:update");
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
index ba19118..e436dbb 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
@@ -52,6 +52,7 @@ import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ThreadPoolProfileDefinition;
import org.apache.camel.model.config.PropertiesDefinition;
import org.apache.camel.model.dataformat.DataFormatsDefinition;
+import org.apache.camel.model.rest.RestConfigurationDefinition;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.spi.PackageScanFilter;
import org.apache.camel.spi.Registry;
@@ -169,6 +170,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
private List<InterceptFromDefinition> interceptFroms = new ArrayList<InterceptFromDefinition>();
@XmlElement(name = "interceptSendToEndpoint", required = false)
private List<InterceptSendToEndpointDefinition> interceptSendToEndpoints = new ArrayList<InterceptSendToEndpointDefinition>();
+ @XmlElement(name = "restConfiguration", required = false)
+ private RestConfigurationDefinition restConfiguration;
@XmlElement(name = "rest", required = false)
private List<RestDefinition> rests = new ArrayList<RestDefinition>();
@XmlElement(name = "route", required = false)
@@ -403,6 +406,14 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
this.rests = rests;
}
+ public RestConfigurationDefinition getRestConfiguration() {
+ return restConfiguration;
+ }
+
+ public void setRestConfigurationDefinition(RestConfigurationDefinition restConfiguration) {
+ this.restConfiguration = restConfiguration;
+ }
+
public List<CamelEndpointFactoryBean> getEndpoints() {
return endpoints;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/b2f41966/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
index 504a9a6..b8edb71 100644
--- a/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
+++ b/examples/camel-example-spark-rest-tomcat/src/main/java/org/apache/camel/example/spark/MySparkRouteBuilder.java
@@ -26,18 +26,20 @@ public class MySparkRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
- // we only have a GET service, but we have PUT, POST, and all the other REST verbs we can use
+ // configure we want to use spark-rest as the component for the rest DSL
+ restConfiguration().component("spark-rest");
- rest().component("spark-rest").uri("hello/:me")
- .get().consumes("text/plain")
- .to("log:input")
- .transform().simple("Hello ${header.me}").endRest()
- .get().consumes("application/json")
- .to("log:input")
- .transform().simple("{ \"message\": \"Hello ${header.me}\" }").endRest()
- .get().consumes("text/xml")
- .to("log:input")
- .transform().simple("<message>Hello ${header.me}</message>");
+ // use the rest DSL to define rest services
+ rest().uri("hello/:me")
+ .get().consumes("text/plain")
+ .to("log:input")
+ .transform().simple("Hello ${header.me}").endRest()
+ .get().consumes("application/json")
+ .to("log:input")
+ .transform().simple("{ \"message\": \"Hello ${header.me}\" }").endRest()
+ .get().consumes("text/xml")
+ .to("log:input")
+ .transform().simple("<message>Hello ${header.me}</message>");
}
}
[02/33] git commit: CAMEL-7354: Migrating rest DSL to be separated
from regular Camel routes.
Posted by da...@apache.org.
CAMEL-7354: Migrating rest DSL to be separated from regular Camel routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/fe0f3f71
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/fe0f3f71
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/fe0f3f71
Branch: refs/heads/master
Commit: fe0f3f713dd54a4e84eefc7ac56139ed6556a9d0
Parents: 71eaf52
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 1 17:11:03 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:47 2014 +0200
----------------------------------------------------------------------
.../org/apache/camel/builder/RouteBuilder.java | 10 ---
.../java/org/apache/camel/model/Constants.java | 3 +-
.../apache/camel/model/FromRestDefinition.java | 93 --------------------
.../org/apache/camel/model/RouteDefinition.java | 10 ---
.../apache/camel/model/RoutesDefinition.java | 11 ---
.../camel/model/rest/GetVerbDefinition.java | 27 ++++++
.../apache/camel/model/rest/PathDefinition.java | 52 +++++++++++
.../camel/model/rest/PostVerbDefinition.java | 27 ++++++
.../apache/camel/model/rest/RestContainer.java | 41 +++++++++
.../apache/camel/model/rest/RestDefinition.java | 48 ++++++++++
.../camel/model/rest/RestsDefinition.java | 81 +++++++++++++++++
.../apache/camel/model/rest/VerbDefinition.java | 50 +++++++++++
.../apache/camel/model/rest/package-info.java | 23 +++++
.../resources/org/apache/camel/model/jaxb.index | 1 -
.../org/apache/camel/model/rest/jaxb.index | 21 +++++
.../component/restbinding/FromRestGetTest.java | 12 ++-
.../blueprint/CamelContextFactoryBean.java | 11 +++
.../xml/AbstractCamelContextFactoryBean.java | 6 +-
.../camel/spring/CamelContextFactoryBean.java | 11 +++
.../restbinding/SpringFromRestGetTest.xml | 31 +++++--
20 files changed, 429 insertions(+), 140 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index 4392d1b..e17dace 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -69,16 +69,6 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
public abstract void configure() throws Exception;
/**
- * Creates a new REST route
- */
- public RouteDefinition fromRest(String verb, String path) {
- getRouteCollection().setCamelContext(getContext());
- RouteDefinition answer = getRouteCollection().fromRest(verb, path);
- configureRoute(answer);
- return answer;
- }
-
- /**
* Creates a new route from the given URI input
*
* @param uri the from uri
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/java/org/apache/camel/model/Constants.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/Constants.java b/camel-core/src/main/java/org/apache/camel/model/Constants.java
index dab5a95..b33eef7 100644
--- a/camel-core/src/main/java/org/apache/camel/model/Constants.java
+++ b/camel-core/src/main/java/org/apache/camel/model/Constants.java
@@ -29,7 +29,8 @@ public final class Constants {
+ "org.apache.camel.model.config:"
+ "org.apache.camel.model.dataformat:"
+ "org.apache.camel.model.language:"
- + "org.apache.camel.model.loadbalancer";
+ + "org.apache.camel.model.loadbalancer:"
+ + "org.apache.camel.model.rest";
public static final String PLACEHOLDER_QNAME = "http://camel.apache.org/schema/placeholder";
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/java/org/apache/camel/model/FromRestDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/FromRestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/FromRestDefinition.java
deleted file mode 100644
index dca9ce4..0000000
--- a/camel-core/src/main/java/org/apache/camel/model/FromRestDefinition.java
+++ /dev/null
@@ -1,93 +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.model;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlAttribute;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlTransient;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.spi.RouteContext;
-
-@XmlRootElement(name = "fromRest")
-@XmlAccessorType(XmlAccessType.FIELD)
-public class FromRestDefinition extends FromDefinition {
-
- // TODO: verb should be an enum
-
- @XmlAttribute
- private String verb;
- @XmlAttribute
- private String path;
- @XmlAttribute
- private String accept;
- @XmlTransient
- private Endpoint endpoint;
-
- public FromRestDefinition() {
- }
-
- public FromRestDefinition(String verb, String path) {
- this(verb, path, null);
- }
-
- public FromRestDefinition(String verb, String path, String accept) {
- this.verb = verb;
- this.path = path;
- this.accept = accept;
- }
-
- public Endpoint resolveEndpoint(RouteContext context) {
- if (endpoint == null) {
- if (accept != null) {
- return context.resolveEndpoint("rest-binding:" + verb + ":" + path + "?accept=" + accept);
- } else {
- return context.resolveEndpoint("rest-binding:" + verb + ":" + path);
- }
- } else {
- return endpoint;
- }
- }
-
- @Override
- public String toString() {
- return "fromRest[" + getLabel() + "]";
- }
-
- @Override
- public String getShortName() {
- return "fromRest";
- }
-
- public String getLabel() {
- return verb + "(" + "/" + path + ")";
- }
-
- public String getVerb() {
- return verb;
- }
-
- public String getPath() {
- return path;
- }
-
- public String getAccept() {
- return accept;
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
index 3caade6..05a5b5f 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -284,16 +284,6 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
// -----------------------------------------------------------------------
/**
- * Creates an REST input to the route
- *
- * @return the builder
- */
- public RouteDefinition fromRest(String verb, String path) {
- getInputs().add(new FromRestDefinition(verb, path));
- return this;
- }
-
- /**
* Creates an input to the route
*
* @param uri the from uri
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java
index b5929ec..ab99fe0 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java
@@ -149,17 +149,6 @@ public class RoutesDefinition extends OptionalIdentifiedDefinition<RoutesDefinit
}
/**
- * Creates a new REST route
- *
- * @return the builder
- */
- public RouteDefinition fromRest(String verb, String path) {
- RouteDefinition route = createRoute();
- route.fromRest(verb, path);
- return route(route);
- }
-
- /**
* Creates a new route from the given URI input
*
* @param uri the from uri
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java
new file mode 100644
index 0000000..f3e398e
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java
@@ -0,0 +1,27 @@
+/**
+ * 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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "get")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class GetVerbDefinition extends VerbDefinition {
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
new file mode 100644
index 0000000..e9c526b
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -0,0 +1,52 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "path")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class PathDefinition {
+
+ @XmlAttribute
+ private String uri;
+
+ @XmlElementRef
+ private List<VerbDefinition> verbs = new ArrayList<VerbDefinition>();
+
+ public String getUri() {
+ return uri;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ public List<VerbDefinition> getVerbs() {
+ return verbs;
+ }
+
+ public void setVerbs(List<VerbDefinition> verbs) {
+ this.verbs = verbs;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java
new file mode 100644
index 0000000..a5d2fb0
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java
@@ -0,0 +1,27 @@
+/**
+ * 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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "post")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class PostVerbDefinition extends VerbDefinition {
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/java/org/apache/camel/model/rest/RestContainer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestContainer.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestContainer.java
new file mode 100644
index 0000000..05dbdfb
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestContainer.java
@@ -0,0 +1,41 @@
+/**
+ * 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 java.util.List;
+import javax.xml.bind.annotation.XmlElementRef;
+
+/**
+ * Container to hold {@link RestDefinition Rest}.
+ */
+public interface RestContainer {
+
+ /**
+ * Returns the RESTs
+ *
+ * @return the RESTs
+ */
+ @XmlElementRef
+ List<RestDefinition> getRests();
+
+ /**
+ * Sets the RESTs to use
+ *
+ * @param rests the RESTs
+ */
+ void setRests(List<RestDefinition> rests);
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/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
new file mode 100644
index 0000000..a44b181
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
@@ -0,0 +1,48 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Represents an XML <rest/> element
+ */
+@XmlRootElement(name = "rest")
+@XmlAccessorType(XmlAccessType.PROPERTY)
+public class RestDefinition {
+
+ @XmlAttribute
+ private String component;
+
+ private List<PathDefinition> paths = new ArrayList<PathDefinition>();
+
+ public List<PathDefinition> getPaths() {
+ return paths;
+ }
+
+ @XmlElementRef
+ public void setPaths(List<PathDefinition> paths) {
+ this.paths = paths;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
new file mode 100644
index 0000000..8361c17
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
@@ -0,0 +1,81 @@
+/**
+ * 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 java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.model.ModelCamelContext;
+import org.apache.camel.model.OptionalIdentifiedDefinition;
+
+/**
+ * Represents a collection of RESTs
+ */
+@XmlRootElement(name = "rests")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class RestsDefinition extends OptionalIdentifiedDefinition<RestsDefinition> implements RestContainer {
+ @XmlElementRef
+ private List<RestDefinition> rests = new ArrayList<RestDefinition>();
+ @XmlTransient
+ private ModelCamelContext camelContext;
+
+ public RestsDefinition() {
+ }
+
+ @Override
+ public String toString() {
+ return "Rests: " + rests;
+ }
+
+ @Override
+ public String getShortName() {
+ return "rests";
+ }
+
+ public String getLabel() {
+ return "Rest " + getId();
+ }
+
+ // Properties
+ //-----------------------------------------------------------------------
+
+ public List<RestDefinition> getRests() {
+ return rests;
+ }
+
+ public void setRests(List<RestDefinition> rests) {
+ this.rests = rests;
+ }
+
+ public ModelCamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ public void setCamelContext(ModelCamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ // Fluent API
+ //-------------------------------------------------------------------------
+
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/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
new file mode 100644
index 0000000..b0f5050
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
@@ -0,0 +1,50 @@
+/**
+ * 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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElementRef;
+
+import org.apache.camel.model.ToDefinition;
+
+@XmlAccessorType(XmlAccessType.FIELD)
+public abstract class VerbDefinition {
+
+ @XmlAttribute
+ private String uri;
+
+ @XmlElementRef(required = true)
+ private ToDefinition to;
+
+ public String getUri() {
+ return uri;
+ }
+
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ public ToDefinition getTo() {
+ return to;
+ }
+
+ public void setTo(ToDefinition to) {
+ this.to = to;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/java/org/apache/camel/model/rest/package-info.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/package-info.java b/camel-core/src/main/java/org/apache/camel/model/rest/package-info.java
new file mode 100644
index 0000000..d765338
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/package-info.java
@@ -0,0 +1,23 @@
+/**
+ * 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.
+ */
+
+
+/**
+ * The JAXB POJOs for the REST DSL
+ */
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://camel.apache.org/schema/spring", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+package org.apache.camel.model.rest;
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
index 61991d5..1e32f42 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
@@ -30,7 +30,6 @@ ExpressionSubElementDefinition
FilterDefinition
FinallyDefinition
FromDefinition
-FromRestDefinition
IdempotentConsumerDefinition
InOnlyDefinition
InOutDefinition
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
new file mode 100644
index 0000000..98ae8de
--- /dev/null
+++ b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
@@ -0,0 +1,21 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+GetVerbDefinition
+PostVerbDefinition
+PathDefinition
+RestDefinition
+RestsDefinition
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
index 69141c4..5b11cb5 100644
--- a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
@@ -19,7 +19,6 @@ package org.apache.camel.component.restbinding;
import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.model.FromRestDefinition;
import org.apache.camel.model.RouteDefinition;
public class FromRestGetTest extends ContextTestSupport {
@@ -34,7 +33,7 @@ public class FromRestGetTest extends ContextTestSupport {
return context;
}
- public void testFromRestModel() {
+/* public void testFromRestModel() {
assertEquals(1, context.getRoutes().size());
RouteDefinition route = context.getRouteDefinition("foo");
@@ -53,17 +52,16 @@ public class FromRestGetTest extends ContextTestSupport {
template.sendBody("seda:get-hello", "Hello World");
assertMockEndpointsSatisfied();
- }
+ }*/
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- // fromRest().get("/hello")
- fromRest("get", "/hello").routeId("foo")
- .to("mock:foo")
- .transform().constant("Bye World");
+// rest()
+// .get("/hello").to("mock:foo")
+// .get("/bye").to("mock:bar");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
index 0ead959..f9cbaa0 100644
--- a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
+++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
@@ -54,6 +54,7 @@ import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ThreadPoolProfileDefinition;
import org.apache.camel.model.config.PropertiesDefinition;
import org.apache.camel.model.dataformat.DataFormatsDefinition;
+import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.spi.PackageScanFilter;
import org.apache.camel.spi.Registry;
import org.osgi.framework.BundleContext;
@@ -160,6 +161,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu
private List<InterceptFromDefinition> interceptFroms = new ArrayList<InterceptFromDefinition>();
@XmlElement(name = "interceptSendToEndpoint", required = false)
private List<InterceptSendToEndpointDefinition> interceptSendToEndpoints = new ArrayList<InterceptSendToEndpointDefinition>();
+ @XmlElement(name = "rest", required = false)
+ private List<RestDefinition> rests = new ArrayList<RestDefinition>();
@XmlElement(name = "route", required = false)
private List<RouteDefinition> routes = new ArrayList<RouteDefinition>();
@XmlTransient
@@ -619,6 +622,14 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu
this.routes = routes;
}
+ public List<RestDefinition> getRests() {
+ return rests;
+ }
+
+ public void setRests(List<RestDefinition> rests) {
+ this.rests = rests;
+ }
+
public boolean isImplicitId() {
return implicitId;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
index ead2bf0..d411edd 100644
--- a/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
+++ b/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelContextFactoryBean.java
@@ -60,6 +60,8 @@ import org.apache.camel.model.RouteDefinitionHelper;
import org.apache.camel.model.ThreadPoolProfileDefinition;
import org.apache.camel.model.config.PropertiesDefinition;
import org.apache.camel.model.dataformat.DataFormatsDefinition;
+import org.apache.camel.model.rest.RestContainer;
+import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.processor.interceptor.BacklogTracer;
import org.apache.camel.processor.interceptor.Delayer;
import org.apache.camel.processor.interceptor.HandleFault;
@@ -102,7 +104,7 @@ import org.slf4j.LoggerFactory;
* @version
*/
@XmlAccessorType(XmlAccessType.FIELD)
-public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContext> extends IdentifiedType implements RouteContainer {
+public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContext> extends IdentifiedType implements RouteContainer, RestContainer {
/**
* JVM system property to control lazy loading of type converters.
@@ -535,6 +537,8 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex
public abstract List<RouteDefinition> getRoutes();
+ public abstract List<RestDefinition> getRests();
+
public abstract List<? extends AbstractCamelEndpointFactoryBean> getEndpoints();
public abstract List<? extends AbstractCamelRedeliveryPolicyFactoryBean> getRedeliveryPolicies();
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
index 7f89623..ba19118 100644
--- a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
+++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
@@ -52,6 +52,7 @@ import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.ThreadPoolProfileDefinition;
import org.apache.camel.model.config.PropertiesDefinition;
import org.apache.camel.model.dataformat.DataFormatsDefinition;
+import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.spi.PackageScanFilter;
import org.apache.camel.spi.Registry;
import org.apache.camel.spring.spi.BridgePropertyPlaceholderConfigurer;
@@ -168,6 +169,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
private List<InterceptFromDefinition> interceptFroms = new ArrayList<InterceptFromDefinition>();
@XmlElement(name = "interceptSendToEndpoint", required = false)
private List<InterceptSendToEndpointDefinition> interceptSendToEndpoints = new ArrayList<InterceptSendToEndpointDefinition>();
+ @XmlElement(name = "rest", required = false)
+ private List<RestDefinition> rests = new ArrayList<RestDefinition>();
@XmlElement(name = "route", required = false)
private List<RouteDefinition> routes = new ArrayList<RouteDefinition>();
@XmlTransient
@@ -392,6 +395,14 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr
this.routes = routes;
}
+ public List<RestDefinition> getRests() {
+ return rests;
+ }
+
+ public void setRests(List<RestDefinition> rests) {
+ this.rests = rests;
+ }
+
public List<CamelEndpointFactoryBean> getEndpoints() {
return endpoints;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/fe0f3f71/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
index 0626079..7a9242d 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
@@ -22,14 +22,33 @@
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
">
- <!-- use a dummy rest component and enlist it in the CamelContext -->
- <bean id="dummy-rest" class="org.apache.camel.component.restbinding.DummyRestBindingCapableComponent"
- init-method="enlist"/>
+ <!-- use a dummy rest component for the rest engine -->
+ <bean id="dummy-rest" class="org.apache.camel.component.restbinding.DummyRestBindingCapableComponent"/>
<camelContext xmlns="http://camel.apache.org/schema/spring">
- <route id="foo">
- <fromRest verb="get" path="/hello"/>
- <to uri="mock:foo"/>
+
+ <rest component="dummy-rest">
+ <path uri="/say">
+ <get uri="/hello">
+ <to uri="direct:hello"/>
+ </get>
+ <get uri="/bye">
+ <to uri="direct:bye"/>
+ </get>
+ <post>
+ <to uri="seda:update"/>
+ </post>
+ </path>
+ </rest>
+
+ <route>
+ <to uri="direct:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </route>
+ <route>
+ <to uri="direct:bye"/>
<transform>
<constant>Bye World</constant>
</transform>
[04/33] git commit: CAMEL-7354: Migrating rest DSL to be separated
from regular Camel routes.
Posted by da...@apache.org.
CAMEL-7354: Migrating rest DSL to be separated from regular Camel routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a9856bb6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a9856bb6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a9856bb6
Branch: refs/heads/master
Commit: a9856bb6bcfb2f324a4682d165d7448a6456f718
Parents: fe0f3f7
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 2 11:52:24 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:47 2014 +0200
----------------------------------------------------------------------
.../org/apache/camel/builder/RouteBuilder.java | 27 ++++++++++
.../apache/camel/model/rest/PathDefinition.java | 54 ++++++++++++++++++--
.../apache/camel/model/rest/RestDefinition.java | 31 ++++++++++-
.../camel/model/rest/RestsDefinition.java | 17 ++++++
.../component/restbinding/FromRestGetTest.java | 14 +++--
.../restbinding/SpringFromRestGetTest.xml | 10 ++--
6 files changed, 138 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/a9856bb6/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index e17dace..db96fea 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -31,6 +31,8 @@ import org.apache.camel.model.OnExceptionDefinition;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.model.rest.RestsDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -43,6 +45,7 @@ import org.slf4j.LoggerFactory;
public abstract class RouteBuilder extends BuilderSupport implements RoutesBuilder {
protected Logger log = LoggerFactory.getLogger(getClass());
private AtomicBoolean initialized = new AtomicBoolean(false);
+ private RestsDefinition restCollection = new RestsDefinition();
private RoutesDefinition routeCollection = new RoutesDefinition();
public RouteBuilder() {
@@ -69,6 +72,18 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
public abstract void configure() throws Exception;
/**
+ * Creates a new REST service
+ *
+ * @return the builder
+ */
+ public RestDefinition rest() {
+ getRestCollection().setCamelContext(getContext());
+ RestDefinition answer = getRestCollection().rest();
+ configureRest(answer);
+ return answer;
+ }
+
+ /**
* Creates a new route from the given URI input
*
* @param uri the from uri
@@ -337,6 +352,14 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
camelContext.addRouteDefinitions(getRouteCollection().getRoutes());
}
+ public RestsDefinition getRestCollection() {
+ return restCollection;
+ }
+
+ public void setRestCollection(RestsDefinition restCollection) {
+ this.restCollection = restCollection;
+ }
+
public void setRouteCollection(RoutesDefinition routeCollection) {
this.routeCollection = routeCollection;
}
@@ -354,6 +377,10 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
return new DefaultCamelContext();
}
+ protected void configureRest(RestDefinition rest) {
+ // noop
+ }
+
protected void configureRoute(RouteDefinition route) {
route.setGroup(getClass().getName());
}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9856bb6/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
index e9c526b..39741cb 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -24,22 +24,24 @@ import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
+import org.apache.camel.model.ToDefinition;
+
@XmlRootElement(name = "path")
@XmlAccessorType(XmlAccessType.FIELD)
public class PathDefinition {
@XmlAttribute
- private String uri;
+ private String url;
@XmlElementRef
private List<VerbDefinition> verbs = new ArrayList<VerbDefinition>();
- public String getUri() {
- return uri;
+ public String getUrl() {
+ return url;
}
- public void setUri(String uri) {
- this.uri = uri;
+ public void setUrl(String url) {
+ this.url = url;
}
public List<VerbDefinition> getVerbs() {
@@ -49,4 +51,46 @@ public class PathDefinition {
public void setVerbs(List<VerbDefinition> verbs) {
this.verbs = verbs;
}
+
+ // Fluent API
+ //-------------------------------------------------------------------------
+
+ public PathDefinition get() {
+ return get(null);
+ }
+
+ public PathDefinition get(String url) {
+ GetVerbDefinition answer = new GetVerbDefinition();
+ getVerbs().add(answer);
+ if (url != null) {
+ answer.setUri(url);
+ }
+ return this;
+ }
+
+ public PathDefinition post() {
+ return post(null);
+ }
+
+ public PathDefinition post(String url) {
+ PostVerbDefinition answer = new PostVerbDefinition();
+ getVerbs().add(answer);
+ if (url != null) {
+ answer.setUri(url);
+ }
+ return this;
+ }
+
+ public PathDefinition to(String url) {
+ // add to last verb
+ if (getVerbs().isEmpty()) {
+ throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
+ }
+
+ VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
+ verb.setTo(new ToDefinition(url));
+
+ return this;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9856bb6/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 a44b181..3cbb67a 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
@@ -31,11 +31,28 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.PROPERTY)
public class RestDefinition {
- @XmlAttribute
private String component;
-
+ private String routeId;
private List<PathDefinition> paths = new ArrayList<PathDefinition>();
+ public String getComponent() {
+ return component;
+ }
+
+ @XmlAttribute
+ public void setComponent(String component) {
+ this.component = component;
+ }
+
+ public String getRouteId() {
+ return routeId;
+ }
+
+ @XmlAttribute
+ public void setRouteId(String routeId) {
+ this.routeId = routeId;
+ }
+
public List<PathDefinition> getPaths() {
return paths;
}
@@ -45,4 +62,14 @@ public class RestDefinition {
this.paths = paths;
}
+ // Fluent API
+ //-------------------------------------------------------------------------
+
+ public PathDefinition path(String url) {
+ PathDefinition answer = new PathDefinition();
+ getPaths().add(answer);
+ answer.setUrl(url);
+ return answer;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9856bb6/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
index 8361c17..11aad02 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
@@ -77,5 +77,22 @@ public class RestsDefinition extends OptionalIdentifiedDefinition<RestsDefinitio
// Fluent API
//-------------------------------------------------------------------------
+ public RestDefinition rest() {
+ RestDefinition rest = createRest();
+ return rest(rest);
+
+ }
+
+ public RestDefinition rest(RestDefinition rest) {
+ getRests().add(rest);
+ return rest;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected RestDefinition createRest() {
+ RestDefinition rest = new RestDefinition();
+ return rest;
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9856bb6/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
index 5b11cb5..b9baeb8 100644
--- a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
@@ -59,9 +59,17 @@ public class FromRestGetTest extends ContextTestSupport {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
-// rest()
-// .get("/hello").to("mock:foo")
-// .get("/bye").to("mock:bar");
+ rest()
+ .path("/say")
+ .get("/hello").to("direct:hello")
+ .get("/bye").to("direct:bye")
+ .post().to("seda:update");
+
+ from("direct:hello")
+ .transform().constant("Hello World");
+
+ from("direct:bye")
+ .transform().constant("Bye World");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/a9856bb6/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
index 7a9242d..d238f43 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
@@ -27,7 +27,7 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
- <rest component="dummy-rest">
+ <rest component="dummy-rest" routeId="myRestRoute">
<path uri="/say">
<get uri="/hello">
<to uri="direct:hello"/>
@@ -41,14 +41,14 @@
</path>
</rest>
- <route>
- <to uri="direct:hello"/>
+ <route id="helloRoute">
+ <from uri="direct:hello"/>
<transform>
<constant>Hello World</constant>
</transform>
</route>
- <route>
- <to uri="direct:bye"/>
+ <route id="byeRoute">
+ <from uri="direct:bye"/>
<transform>
<constant>Bye World</constant>
</transform>
[31/33] git commit: Fixed CS
Posted by da...@apache.org.
Fixed CS
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ee558f0c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ee558f0c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ee558f0c
Branch: refs/heads/master
Commit: ee558f0cf1c2b95624db6b28407dba8136b54d61
Parents: df7b90c
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Jul 19 09:36:27 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:54 2014 +0200
----------------------------------------------------------------------
...ponentConfigurationAndDocumentationTest.java | 2 -
.../camel/blueprint/BlueprintJaxbRestTest.java | 7 +--
.../camel/component/box/BoxConverter.java | 12 ++---
.../component/box/AbstractBoxTestSupport.java | 30 ++++++-----
...BoxCollaborationsManagerIntegrationTest.java | 20 ++++----
.../box/IBoxCommentsManagerIntegrationTest.java | 16 +++---
.../box/IBoxEventsManagerIntegrationTest.java | 6 +--
.../box/IBoxFilesManagerIntegrationTest.java | 52 ++++++++++----------
.../box/IBoxFoldersManagerIntegrationTest.java | 22 ++++-----
.../box/IBoxGroupsManagerIntegrationTest.java | 38 +++++++-------
.../box/IBoxSearchManagerIntegrationTest.java | 2 +-
.../IBoxSharedItemsManagerIntegrationTest.java | 2 +-
.../box/IBoxUsersManagerIntegrationTest.java | 32 ++++++------
...LongPollingEventsManagerIntegrationTest.java | 33 ++++++++++---
...ponentConfigurationAndDocumentationTest.java | 4 +-
...ponentConfigurationAndDocumentationTest.java | 4 +-
.../camel-linkedin/camel-linkedin-api/pom.xml | 4 +-
.../camel-linkedin-component/pom.xml | 2 +-
components/camel-linkedin/pom.xml | 2 +-
.../component/sparkrest/SparkConverter.java | 3 ++
20 files changed, 153 insertions(+), 140 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/wsservlet/WebsocketComponentConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/wsservlet/WebsocketComponentConfigurationAndDocumentationTest.java b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/wsservlet/WebsocketComponentConfigurationAndDocumentationTest.java
index f1e123b..8b74d43 100644
--- a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/wsservlet/WebsocketComponentConfigurationAndDocumentationTest.java
+++ b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/wsservlet/WebsocketComponentConfigurationAndDocumentationTest.java
@@ -24,8 +24,6 @@ import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
-import java.util.List;
-
public class WebsocketComponentConfigurationAndDocumentationTest extends CamelTestSupport {
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
index 00e4ae4..a8fd5cf 100644
--- a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
+++ b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
@@ -21,14 +21,15 @@ import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
-import org.apache.camel.blueprint.handler.CamelNamespaceHandler;
-import org.apache.camel.test.junit4.TestSupport;
-import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
+import org.apache.camel.blueprint.handler.CamelNamespaceHandler;
+import org.apache.camel.test.junit4.TestSupport;
+import org.junit.Test;
+
public class BlueprintJaxbRestTest extends TestSupport {
@Test
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConverter.java b/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConverter.java
index be88e06..142b725 100644
--- a/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConverter.java
+++ b/components/camel-box/src/main/java/org/apache/camel/component/box/BoxConverter.java
@@ -16,19 +16,15 @@
*/
package org.apache.camel.component.box;
-import com.box.boxjavalibv2.exceptions.BoxJSONException;
-import com.box.restclientv2.exceptions.BoxRestException;
+import java.io.File;
+import java.io.InputStream;
+
import com.box.restclientv2.requestsbase.BoxFileUploadRequestObject;
import org.apache.camel.Converter;
import org.apache.camel.Exchange;
-import org.apache.camel.NoTypeConversionAvailableException;
import org.apache.camel.component.box.internal.BoxConstants;
import org.apache.camel.component.file.GenericFile;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-
@Converter
public final class BoxConverter {
@@ -37,7 +33,7 @@ public final class BoxConverter {
}
@Converter
- public static BoxFileUploadRequestObject genericFileToBoxFileUploadRequestObject(GenericFile<?> file, Exchange exchange) throws IOException, NoTypeConversionAvailableException, BoxRestException, BoxJSONException {
+ public static BoxFileUploadRequestObject genericFileToBoxFileUploadRequestObject(GenericFile<?> file, Exchange exchange) throws Exception {
String folderId = "0";
if (exchange != null) {
folderId = exchange.getProperty(BoxConstants.PROPERTY_PREFIX + "folderId", "0", String.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/test/java/org/apache/camel/component/box/AbstractBoxTestSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/AbstractBoxTestSupport.java b/components/camel-box/src/test/java/org/apache/camel/component/box/AbstractBoxTestSupport.java
index edcb70c..7bcf809 100644
--- a/components/camel-box/src/test/java/org/apache/camel/component/box/AbstractBoxTestSupport.java
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/AbstractBoxTestSupport.java
@@ -33,7 +33,6 @@ import com.box.boxjavalibv2.authorization.OAuthRefreshListener;
import com.box.boxjavalibv2.dao.BoxOAuthToken;
import com.box.boxjavalibv2.dao.IAuthData;
import com.box.boxjavalibv2.requests.requestobjects.BoxPagingRequestObject;
-import com.box.restclientv2.requestsbase.BoxDefaultRequestObject;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.test.junit4.CamelTestSupport;
@@ -45,18 +44,19 @@ public abstract class AbstractBoxTestSupport extends CamelTestSupport {
protected static final String CAMEL_TEST_TAG = "camel_was_here";
protected static final String CAMEL_TEST_FILE = "CamelTestFile";
+ protected static final BoxPagingRequestObject BOX_PAGING_REQUEST_OBJECT = BoxPagingRequestObject.pagingRequestObject(100, 0);
+
+ protected static String testUserId;
+ protected static String testFolderId;
+ protected static String testFileId;
+
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
private static final String TEST_OPTIONS_PROPERTIES = "/test-options.properties";
private static final String REFRESH_TOKEN_PROPERTY = "refreshToken";
- protected static final BoxPagingRequestObject BOX_PAGING_REQUEST_OBJECT = BoxPagingRequestObject.pagingRequestObject(100, 0);
- protected static String testUserId;
private static String refreshToken;
private static String propertyText;
- protected static String testFolderId;
- protected static String testFileId;
-
@Override
protected CamelContext createCamelContext() throws Exception {
@@ -68,7 +68,7 @@ public abstract class AbstractBoxTestSupport extends CamelTestSupport {
final StringBuilder builder = new StringBuilder();
final BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
String line;
- while((line = reader.readLine()) != null) {
+ while ((line = reader.readLine()) != null) {
builder.append(line).append(LINE_SEPARATOR);
}
propertyText = builder.toString();
@@ -77,17 +77,16 @@ public abstract class AbstractBoxTestSupport extends CamelTestSupport {
try {
properties.load(new StringReader(propertyText));
} catch (IOException e) {
- throw new IOException(String.format("%s could not be loaded: %s", TEST_OPTIONS_PROPERTIES, e.getMessage()),
- e);
+ throw new IOException(String.format("%s could not be loaded: %s", TEST_OPTIONS_PROPERTIES, e.getMessage()), e);
}
- addSystemProperty("camel.box.userName", "userName", properties);
+ addSystemProperty("camel.box.userName", "userName", properties);
addSystemProperty("camel.box.userPassword", "userPassword", properties);
- addSystemProperty("camel.box.clientId", "clientId", properties);
+ addSystemProperty("camel.box.clientId", "clientId", properties);
addSystemProperty("camel.box.clientSecret", "clientSecret", properties);
addSystemProperty("camel.box.refreshToken", "refreshToken", properties);
addSystemProperty("camel.box.testFolderId", "testFolderId", properties);
- addSystemProperty("camel.box.testFileId", "testFileId", properties);
+ addSystemProperty("camel.box.testFileId", "testFileId", properties);
addSystemProperty("camel.box.testUserId", "testUserId", properties);
// cache test properties
@@ -146,7 +145,7 @@ public abstract class AbstractBoxTestSupport extends CamelTestSupport {
private void addSystemProperty(String sourceName, String targetName, Properties properties) {
String value = System.getProperty(sourceName);
- if( value!=null && !value.trim().isEmpty() ) {
+ if (value != null && !value.trim().isEmpty()) {
properties.put(targetName, value);
}
}
@@ -159,7 +158,7 @@ public abstract class AbstractBoxTestSupport extends CamelTestSupport {
final URL resource = AbstractBoxTestSupport.class.getResource(TEST_OPTIONS_PROPERTIES);
final FileOutputStream out = new FileOutputStream(new File(resource.getPath()));
propertyText = propertyText.replaceAll(REFRESH_TOKEN_PROPERTY + "=\\S*",
- REFRESH_TOKEN_PROPERTY + "=" + refreshToken);
+ REFRESH_TOKEN_PROPERTY + "=" + refreshToken);
out.write(propertyText.getBytes("UTF-8"));
out.close();
}
@@ -170,8 +169,7 @@ public abstract class AbstractBoxTestSupport extends CamelTestSupport {
return true;
}
- protected <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers)
- throws CamelExecutionException {
+ protected <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers) throws CamelExecutionException {
return (T) template().requestBodyAndHeaders(endpointUri, body, headers);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxCollaborationsManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxCollaborationsManagerIntegrationTest.java b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxCollaborationsManagerIntegrationTest.java
index 0931481..c57a669 100644
--- a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxCollaborationsManagerIntegrationTest.java
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxCollaborationsManagerIntegrationTest.java
@@ -51,11 +51,11 @@ public class IBoxCollaborationsManagerIntegrationTest extends AbstractBoxTestSup
headers.put("CamelBox.folderId", testFolderId);
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxCollabRequestObject
final BoxCollabRequestObject collabObject = BoxCollabRequestObject.createCollabObject(testFolderId, null,
- "camel.test@localhost.com", BoxCollaborationRole.VIEWER);
+ "camel.test@localhost.com", BoxCollaborationRole.VIEWER);
headers.put("CamelBox.collabRequest", collabObject);
BoxCollaboration result = requestBodyAndHeaders("direct://CREATECOLLABORATION",
- null, headers);
+ null, headers);
assertNotNull("createCollaboration result", result);
// wait a moment for collaboration to register
Thread.sleep(2000);
@@ -76,7 +76,7 @@ public class IBoxCollaborationsManagerIntegrationTest extends AbstractBoxTestSup
public void testGetAllCollaborations() throws Exception {
// using com.box.boxjavalibv2.requests.requestobjects.BoxGetAllCollabsRequestObject message body for single parameter "getAllCollabsRequest"
final BoxGetAllCollabsRequestObject collabRequest =
- BoxGetAllCollabsRequestObject.getAllCollaborationsRequestObject(BoxCollaboration.STATUS_PENDING);
+ BoxGetAllCollabsRequestObject.getAllCollaborationsRequestObject(BoxCollaboration.STATUS_PENDING);
List result = requestBody("direct://GETALLCOLLABORATIONS", collabRequest);
assertNotNull("getAllCollaborations: " + result);
@@ -93,7 +93,7 @@ public class IBoxCollaborationsManagerIntegrationTest extends AbstractBoxTestSup
headers.put("CamelBox.collabId", collaboration.getId());
// parameter type is com.box.restclientv2.requestsbase.BoxDefaultRequestObject
headers.put("CamelBox.defaultRequest", null);
-
+
BoxCollaboration result = requestBodyAndHeaders("direct://GETCOLLABORATION", null, headers);
assertNotNull("getCollaboration result", result);
LOG.debug("getCollaboration: " + result);
@@ -113,7 +113,7 @@ public class IBoxCollaborationsManagerIntegrationTest extends AbstractBoxTestSup
headers.put("CamelBox.collabId", collaboration.getId());
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxCollabRequestObject
final BoxCollabRequestObject requestObject = BoxCollabRequestObject.updateCollabObjects(
- BoxCollaborationRole.EDITOR);
+ BoxCollaborationRole.EDITOR);
headers.put("CamelBox.collabRequest", requestObject);
BoxCollaboration result = requestBodyAndHeaders("direct://UPDATECOLLABORATION", null, headers);
@@ -130,23 +130,23 @@ public class IBoxCollaborationsManagerIntegrationTest extends AbstractBoxTestSup
public void configure() {
// test route for createCollaboration
from("direct://CREATECOLLABORATION")
- .to("box://" + PATH_PREFIX + "/createCollaboration");
+ .to("box://" + PATH_PREFIX + "/createCollaboration");
// test route for deleteCollaboration
from("direct://DELETECOLLABORATION")
- .to("box://" + PATH_PREFIX + "/deleteCollaboration");
+ .to("box://" + PATH_PREFIX + "/deleteCollaboration");
// test route for getAllCollaborations
from("direct://GETALLCOLLABORATIONS")
- .to("box://" + PATH_PREFIX + "/getAllCollaborations?inBody=getAllCollabsRequest");
+ .to("box://" + PATH_PREFIX + "/getAllCollaborations?inBody=getAllCollabsRequest");
// test route for getCollaboration
from("direct://GETCOLLABORATION")
- .to("box://" + PATH_PREFIX + "/getCollaboration");
+ .to("box://" + PATH_PREFIX + "/getCollaboration");
// test route for updateCollaboration
from("direct://UPDATECOLLABORATION")
- .to("box://" + PATH_PREFIX + "/updateCollaboration");
+ .to("box://" + PATH_PREFIX + "/updateCollaboration");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxCommentsManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxCommentsManagerIntegrationTest.java b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxCommentsManagerIntegrationTest.java
index eec01ce..2b48517 100644
--- a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxCommentsManagerIntegrationTest.java
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxCommentsManagerIntegrationTest.java
@@ -43,7 +43,7 @@ public class IBoxCommentsManagerIntegrationTest extends AbstractBoxTestSupport {
private BoxComment addComment() throws InterruptedException {
final BoxCommentRequestObject requestObject =
- BoxCommentRequestObject.addCommentRequestObject(BoxResourceType.FILE, testFileId, "Camel was here!");
+ BoxCommentRequestObject.addCommentRequestObject(BoxResourceType.FILE, testFileId, "Camel was here!");
BoxComment result = requestBody("direct://ADDCOMMENT", requestObject);
assertNotNull("addComment result", result);
@@ -52,7 +52,7 @@ public class IBoxCommentsManagerIntegrationTest extends AbstractBoxTestSupport {
}
@Test
- public void testAddComment_1() throws Exception {
+ public void testAddComment1() throws Exception {
final Map<String, Object> headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelBox.commentedItemId", testFileId);
@@ -103,7 +103,7 @@ public class IBoxCommentsManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.commentId", comment.getId());
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxCommentRequestObject
final BoxCommentRequestObject requestObject =
- BoxCommentRequestObject.updateCommentRequestObject("Camel was here, again!");
+ BoxCommentRequestObject.updateCommentRequestObject("Camel was here, again!");
headers.put("CamelBox.commentRequest", requestObject);
BoxComment result = requestBodyAndHeaders("direct://UPDATECOMMENT", null, headers);
@@ -119,23 +119,23 @@ public class IBoxCommentsManagerIntegrationTest extends AbstractBoxTestSupport {
public void configure() {
// test route for addComment
from("direct://ADDCOMMENT")
- .to("box://" + PATH_PREFIX + "/addComment?inBody=commentRequest");
+ .to("box://" + PATH_PREFIX + "/addComment?inBody=commentRequest");
// test route for addComment
from("direct://ADDCOMMENT_1")
- .to("box://" + PATH_PREFIX + "/addComment");
+ .to("box://" + PATH_PREFIX + "/addComment");
// test route for deleteComment
from("direct://DELETECOMMENT")
- .to("box://" + PATH_PREFIX + "/deleteComment");
+ .to("box://" + PATH_PREFIX + "/deleteComment");
// test route for getComment
from("direct://GETCOMMENT")
- .to("box://" + PATH_PREFIX + "/getComment");
+ .to("box://" + PATH_PREFIX + "/getComment");
// test route for updateComment
from("direct://UPDATECOMMENT")
- .to("box://" + PATH_PREFIX + "/updateComment");
+ .to("box://" + PATH_PREFIX + "/updateComment");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxEventsManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxEventsManagerIntegrationTest.java b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxEventsManagerIntegrationTest.java
index b771d67..8096fc1 100644
--- a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxEventsManagerIntegrationTest.java
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxEventsManagerIntegrationTest.java
@@ -52,7 +52,7 @@ public class IBoxEventsManagerIntegrationTest extends AbstractBoxTestSupport {
public void testGetEvents() throws Exception {
// using com.box.boxjavalibv2.requests.requestobjects.BoxEventRequestObject message body for single parameter "eventRequest"
final BoxEventRequestObject requestObject =
- BoxEventRequestObject.getEventsRequestObject(BoxEventRequestObject.STREAM_POSITION_NOW);
+ BoxEventRequestObject.getEventsRequestObject(BoxEventRequestObject.STREAM_POSITION_NOW);
BoxEventCollection result = requestBody("direct://GETEVENTS", requestObject);
assertNotNull("getEvents result", result);
@@ -65,11 +65,11 @@ public class IBoxEventsManagerIntegrationTest extends AbstractBoxTestSupport {
public void configure() {
// test route for getEventOptions
from("direct://GETEVENTOPTIONS")
- .to("box://" + PATH_PREFIX + "/getEventOptions?inBody=defaultRequest");
+ .to("box://" + PATH_PREFIX + "/getEventOptions?inBody=defaultRequest");
// test route for getEvents
from("direct://GETEVENTS")
- .to("box://" + PATH_PREFIX + "/getEvents?inBody=eventRequest");
+ .to("box://" + PATH_PREFIX + "/getEvents?inBody=eventRequest");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxFilesManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxFilesManagerIntegrationTest.java b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxFilesManagerIntegrationTest.java
index 00ac056..44e4a7a 100644
--- a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxFilesManagerIntegrationTest.java
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxFilesManagerIntegrationTest.java
@@ -65,7 +65,7 @@ public class IBoxFilesManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.fileId", testFileId);
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxItemCopyRequestObject
final BoxItemCopyRequestObject requestObject =
- BoxItemCopyRequestObject.copyItemRequestObject("0");
+ BoxItemCopyRequestObject.copyItemRequestObject("0");
requestObject.setName(CAMEL_TEST_FILE);
headers.put("CamelBox.itemCopyRequest", requestObject);
BoxFile result = requestBodyAndHeaders("direct://COPYFILE", null, headers);
@@ -87,7 +87,7 @@ public class IBoxFilesManagerIntegrationTest extends AbstractBoxTestSupport {
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxSharedLinkRequestObject
final BoxSharedLinkRequestEntity sharedLink = new BoxSharedLinkRequestEntity(BoxSharedLinkAccess.OPEN);
final BoxSharedLinkRequestObject requestObject =
- BoxSharedLinkRequestObject.createSharedLinkRequestObject(sharedLink);
+ BoxSharedLinkRequestObject.createSharedLinkRequestObject(sharedLink);
headers.put("CamelBox.sharedLinkRequest", requestObject);
BoxFile result = requestBodyAndHeaders("direct://CREATESHAREDLINK", null, headers);
@@ -123,7 +123,7 @@ public class IBoxFilesManagerIntegrationTest extends AbstractBoxTestSupport {
}
@Test
- public void testDownloadFile_1() throws Exception {
+ public void testDownloadFile1() throws Exception {
final Map<String, Object> headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelBox.fileId", testFileId);
@@ -147,18 +147,18 @@ public class IBoxFilesManagerIntegrationTest extends AbstractBoxTestSupport {
do {
bytesTransferred = fileTransferListener.getBytesTransferred();
Thread.sleep(2000);
- } while(fileTransferListener.getBytesTransferred() != bytesTransferred);
+ } while (fileTransferListener.getBytesTransferred() != bytesTransferred);
// assertEquals("downloadFile status", "success", fileTransferListener.getStatus());
assertNull("downloadFile exception", fileTransferListener.getException());
}
@Test
- public void testDownloadFile_2() throws Exception {
+ public void testDownloadFile2() throws Exception {
final Map<String, Object> headers = new HashMap<String, Object>();
// parameter type is String
headers.put("CamelBox.fileId", testFileId);
// parameter type is java.io.OutputStream[]
- final OutputStream[] outputStreams = new OutputStream[] { new ByteArrayOutputStream() } ;
+ final OutputStream[] outputStreams = new OutputStream[]{new ByteArrayOutputStream()};
headers.put("CamelBox.outputStreams", outputStreams);
// parameter type is com.box.boxjavalibv2.filetransfer.IFileTransferListener
final FileTransferListener fileTransferListener = new FileTransferListener();
@@ -283,7 +283,7 @@ public class IBoxFilesManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.fileId", testFileId);
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxFileRequestObject
final BoxFileRequestObject requestObject = BoxFileRequestObject.getRequestObject();
- requestObject.setTags(new String[] { CAMEL_TEST_TAG });
+ requestObject.setTags(new String[]{CAMEL_TEST_TAG});
headers.put("CamelBox.fileRequest", requestObject);
BoxFile result = requestBodyAndHeaders("direct://UPDATEFILEINFO", null, headers);
@@ -294,8 +294,8 @@ public class IBoxFilesManagerIntegrationTest extends AbstractBoxTestSupport {
public BoxFile uploadFile() throws Exception {
// using com.box.restclientv2.requestsbase.BoxFileUploadRequestObject message body for single parameter "fileUploadRequest"
final BoxFileUploadRequestObject requestObject =
- BoxFileUploadRequestObject.uploadFileRequestObject("0", CAMEL_TEST_FILE,
- getClass().getResourceAsStream(TEST_UPLOAD_FILE));
+ BoxFileUploadRequestObject.uploadFileRequestObject("0", CAMEL_TEST_FILE,
+ getClass().getResourceAsStream(TEST_UPLOAD_FILE));
final FileTransferListener fileTransferListener = new FileTransferListener();
requestObject.setListener(fileTransferListener);
@@ -320,8 +320,8 @@ public class IBoxFilesManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.fileId", boxFile.getId());
// parameter type is com.box.restclientv2.requestsbase.BoxFileUploadRequestObject
final BoxFileUploadRequestObject requestObject =
- BoxFileUploadRequestObject.uploadNewVersionRequestObject(CAMEL_TEST_FILE,
- getClass().getResourceAsStream(TEST_UPLOAD_FILE));
+ BoxFileUploadRequestObject.uploadNewVersionRequestObject(CAMEL_TEST_FILE,
+ getClass().getResourceAsStream(TEST_UPLOAD_FILE));
final FileTransferListener fileTransferListener = new FileTransferListener();
requestObject.setListener(fileTransferListener);
@@ -342,63 +342,63 @@ public class IBoxFilesManagerIntegrationTest extends AbstractBoxTestSupport {
public void configure() {
// test route for copyFile
from("direct://COPYFILE")
- .to("box://" + PATH_PREFIX + "/copyFile");
+ .to("box://" + PATH_PREFIX + "/copyFile");
// test route for createSharedLink
from("direct://CREATESHAREDLINK")
- .to("box://" + PATH_PREFIX + "/createSharedLink");
+ .to("box://" + PATH_PREFIX + "/createSharedLink");
// test route for deleteFile
from("direct://DELETEFILE")
- .to("box://" + PATH_PREFIX + "/deleteFile");
+ .to("box://" + PATH_PREFIX + "/deleteFile");
// test route for downloadFile
from("direct://DOWNLOADFILE")
- .to("box://" + PATH_PREFIX + "/downloadFile");
+ .to("box://" + PATH_PREFIX + "/downloadFile");
// test route for downloadFile
from("direct://DOWNLOADFILE_1")
- .to("box://" + PATH_PREFIX + "/downloadFile");
+ .to("box://" + PATH_PREFIX + "/downloadFile");
// test route for downloadFile
from("direct://DOWNLOADFILE_2")
- .to("box://" + PATH_PREFIX + "/downloadFile");
+ .to("box://" + PATH_PREFIX + "/downloadFile");
// test route for downloadThumbnail
from("direct://DOWNLOADTHUMBNAIL")
- .to("box://" + PATH_PREFIX + "/downloadThumbnail");
+ .to("box://" + PATH_PREFIX + "/downloadThumbnail");
// test route for getFile
from("direct://GETFILE")
- .to("box://" + PATH_PREFIX + "/getFile");
+ .to("box://" + PATH_PREFIX + "/getFile");
// test route for getFileComments
from("direct://GETFILECOMMENTS")
- .to("box://" + PATH_PREFIX + "/getFileComments");
+ .to("box://" + PATH_PREFIX + "/getFileComments");
// test route for getFileVersions
from("direct://GETFILEVERSIONS")
- .to("box://" + PATH_PREFIX + "/getFileVersions");
+ .to("box://" + PATH_PREFIX + "/getFileVersions");
// test route for getPreview
from("direct://GETPREVIEW")
- .to("box://" + PATH_PREFIX + "/getPreview");
+ .to("box://" + PATH_PREFIX + "/getPreview");
// test route for getThumbnail
from("direct://GETTHUMBNAIL")
- .to("box://" + PATH_PREFIX + "/getThumbnail");
+ .to("box://" + PATH_PREFIX + "/getThumbnail");
// test route for updateFileInfo
from("direct://UPDATEFILEINFO")
- .to("box://" + PATH_PREFIX + "/updateFileInfo");
+ .to("box://" + PATH_PREFIX + "/updateFileInfo");
// test route for uploadFile
from("direct://UPLOADFILE")
- .to("box://" + PATH_PREFIX + "/uploadFile?inBody=fileUploadRequest");
+ .to("box://" + PATH_PREFIX + "/uploadFile?inBody=fileUploadRequest");
// test route for uploadNewVersion
from("direct://UPLOADNEWVERSION")
- .to("box://" + PATH_PREFIX + "/uploadNewVersion");
+ .to("box://" + PATH_PREFIX + "/uploadNewVersion");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxFoldersManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxFoldersManagerIntegrationTest.java b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxFoldersManagerIntegrationTest.java
index 3fb018b..898bc4c 100644
--- a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxFoldersManagerIntegrationTest.java
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxFoldersManagerIntegrationTest.java
@@ -96,9 +96,9 @@ public class IBoxFoldersManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.folderId", testFolder.getId());
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxSharedLinkRequestObject
final BoxSharedLinkRequestEntity sharedLink = new BoxSharedLinkRequestEntity(
- BoxSharedLinkAccess.COLLABORATORS);
+ BoxSharedLinkAccess.COLLABORATORS);
headers.put("CamelBox.sharedLinkRequest",
- BoxSharedLinkRequestObject.createSharedLinkRequestObject(sharedLink));
+ BoxSharedLinkRequestObject.createSharedLinkRequestObject(sharedLink));
BoxFolder result = requestBodyAndHeaders("direct://CREATESHAREDLINK", null, headers);
assertNotNull("createSharedLink result", result);
@@ -180,7 +180,7 @@ public class IBoxFoldersManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.folderId", testFolder.getId());
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxFolderRequestObject
final BoxFolderRequestObject folderRequestObject = BoxFolderRequestObject.getRequestObject();
- folderRequestObject.setTags(new String[] {CAMEL_TEST_TAG} );
+ folderRequestObject.setTags(new String[]{CAMEL_TEST_TAG});
folderRequestObject.setName(CAMEL_TEST_COPY_FOLDER);
headers.put("CamelBox.folderRequest", folderRequestObject);
@@ -200,35 +200,35 @@ public class IBoxFoldersManagerIntegrationTest extends AbstractBoxTestSupport {
public void configure() {
// test route for copyFolder
from("direct://COPYFOLDER")
- .to("box://" + PATH_PREFIX + "/copyFolder");
+ .to("box://" + PATH_PREFIX + "/copyFolder");
// test route for createFolder
from("direct://CREATEFOLDER")
- .to("box://" + PATH_PREFIX + "/createFolder?inBody=folderRequest");
+ .to("box://" + PATH_PREFIX + "/createFolder?inBody=folderRequest");
// test route for createSharedLink
from("direct://CREATESHAREDLINK")
- .to("box://" + PATH_PREFIX + "/createSharedLink");
+ .to("box://" + PATH_PREFIX + "/createSharedLink");
// test route for deleteFolder
from("direct://DELETEFOLDER")
- .to("box://" + PATH_PREFIX + "/deleteFolder");
+ .to("box://" + PATH_PREFIX + "/deleteFolder");
// test route for getFolder
from("direct://GETFOLDER")
- .to("box://" + PATH_PREFIX + "/getFolder");
+ .to("box://" + PATH_PREFIX + "/getFolder");
// test route for getFolderCollaborations
from("direct://GETFOLDERCOLLABORATIONS")
- .to("box://" + PATH_PREFIX + "/getFolderCollaborations");
+ .to("box://" + PATH_PREFIX + "/getFolderCollaborations");
// test route for getFolderItems
from("direct://GETFOLDERITEMS")
- .to("box://" + PATH_PREFIX + "/getFolderItems");
+ .to("box://" + PATH_PREFIX + "/getFolderItems");
// test route for updateFolderInfo
from("direct://UPDATEFOLDERINFO")
- .to("box://" + PATH_PREFIX + "/updateFolderInfo");
+ .to("box://" + PATH_PREFIX + "/updateFolderInfo");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxGroupsManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxGroupsManagerIntegrationTest.java b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxGroupsManagerIntegrationTest.java
index 7207e50..decd6ec 100644
--- a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxGroupsManagerIntegrationTest.java
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxGroupsManagerIntegrationTest.java
@@ -56,7 +56,7 @@ public class IBoxGroupsManagerIntegrationTest extends AbstractBoxTestSupport {
}
@Test
- public void testCreateGroup_1() throws Exception {
+ public void testCreateGroup1() throws Exception {
// using String message body for single parameter "name"
BoxGroup result = requestBody("direct://CREATEGROUP_1", CAMEL_TEST_GROUP);
@@ -69,7 +69,7 @@ public class IBoxGroupsManagerIntegrationTest extends AbstractBoxTestSupport {
public BoxGroupMembership createMembership(String groupId) throws Exception {
// using com.box.boxjavalibv2.requests.requestobjects.BoxGroupMembershipRequestObject message body for single parameter "groupMembershipRequest"
final BoxGroupMembershipRequestObject requestObject =
- BoxGroupMembershipRequestObject.addMembershipRequestObject(groupId, testUserId, BoxGroupMembership.ROLE_MEMBER);
+ BoxGroupMembershipRequestObject.addMembershipRequestObject(groupId, testUserId, BoxGroupMembership.ROLE_MEMBER);
BoxGroupMembership result = requestBody("direct://CREATEMEMBERSHIP", requestObject);
assertNotNull("createMembership result", result);
@@ -77,7 +77,7 @@ public class IBoxGroupsManagerIntegrationTest extends AbstractBoxTestSupport {
}
@Test
- public void testCreateMembership_1() throws Exception {
+ public void testCreateMembership1() throws Exception {
final BoxGroup group = createGroup();
try {
@@ -206,7 +206,7 @@ public class IBoxGroupsManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.groupId", group.getId());
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxGroupRequestObject
final BoxGroupRequestObject requestObject =
- BoxGroupRequestObject.updateGroupRequestObject(CAMEL_TEST_GROUP + "_Updated");
+ BoxGroupRequestObject.updateGroupRequestObject(CAMEL_TEST_GROUP + "_Updated");
headers.put("CamelBox.groupRequest", requestObject);
BoxGroup result = requestBodyAndHeaders("direct://UPDATEGROUP", null, headers);
@@ -230,7 +230,7 @@ public class IBoxGroupsManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.membershipId", membership.getId());
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxGroupMembershipRequestObject
final BoxGroupMembershipRequestObject requestObject =
- BoxGroupMembershipRequestObject.updateMembershipRequestObject(BoxGroupMembership.ROLE_ADMIN);
+ BoxGroupMembershipRequestObject.updateMembershipRequestObject(BoxGroupMembership.ROLE_ADMIN);
headers.put("CamelBox.groupMembershipRequest", requestObject);
BoxGroupMembership result = requestBodyAndHeaders("direct://UPDATEMEMBERSHIP", null, headers);
@@ -243,7 +243,7 @@ public class IBoxGroupsManagerIntegrationTest extends AbstractBoxTestSupport {
}
@Test
- public void testUpdateMembership_1() throws Exception {
+ public void testUpdateMembership1() throws Exception {
final BoxGroup group = createGroup();
try {
@@ -270,55 +270,55 @@ public class IBoxGroupsManagerIntegrationTest extends AbstractBoxTestSupport {
public void configure() {
// test route for createGroup
from("direct://CREATEGROUP")
- .to("box://" + PATH_PREFIX + "/createGroup?inBody=groupRequest");
+ .to("box://" + PATH_PREFIX + "/createGroup?inBody=groupRequest");
// test route for createGroup
from("direct://CREATEGROUP_1")
- .to("box://" + PATH_PREFIX + "/createGroup?inBody=name");
+ .to("box://" + PATH_PREFIX + "/createGroup?inBody=name");
// test route for createMembership
from("direct://CREATEMEMBERSHIP")
- .to("box://" + PATH_PREFIX + "/createMembership?inBody=groupMembershipRequest");
+ .to("box://" + PATH_PREFIX + "/createMembership?inBody=groupMembershipRequest");
// test route for createMembership
from("direct://CREATEMEMBERSHIP_1")
- .to("box://" + PATH_PREFIX + "/createMembership");
+ .to("box://" + PATH_PREFIX + "/createMembership");
// test route for deleteGroup
from("direct://DELETEGROUP")
- .to("box://" + PATH_PREFIX + "/deleteGroup");
+ .to("box://" + PATH_PREFIX + "/deleteGroup");
// test route for deleteMembership
from("direct://DELETEMEMBERSHIP")
- .to("box://" + PATH_PREFIX + "/deleteMembership");
+ .to("box://" + PATH_PREFIX + "/deleteMembership");
// test route for getAllCollaborations
from("direct://GETALLCOLLABORATIONS")
- .to("box://" + PATH_PREFIX + "/getAllCollaborations");
+ .to("box://" + PATH_PREFIX + "/getAllCollaborations");
// test route for getAllGroups
from("direct://GETALLGROUPS")
- .to("box://" + PATH_PREFIX + "/getAllGroups?inBody=defaultRequest");
+ .to("box://" + PATH_PREFIX + "/getAllGroups?inBody=defaultRequest");
// test route for getMembership
from("direct://GETMEMBERSHIP")
- .to("box://" + PATH_PREFIX + "/getMembership");
+ .to("box://" + PATH_PREFIX + "/getMembership");
// test route for getMemberships
from("direct://GETMEMBERSHIPS")
- .to("box://" + PATH_PREFIX + "/getMemberships");
+ .to("box://" + PATH_PREFIX + "/getMemberships");
// test route for updateGroup
from("direct://UPDATEGROUP")
- .to("box://" + PATH_PREFIX + "/updateGroup");
+ .to("box://" + PATH_PREFIX + "/updateGroup");
// test route for updateMembership
from("direct://UPDATEMEMBERSHIP")
- .to("box://" + PATH_PREFIX + "/updateMembership");
+ .to("box://" + PATH_PREFIX + "/updateMembership");
// test route for updateMembership
from("direct://UPDATEMEMBERSHIP_1")
- .to("box://" + PATH_PREFIX + "/updateMembership");
+ .to("box://" + PATH_PREFIX + "/updateMembership");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxSearchManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxSearchManagerIntegrationTest.java b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxSearchManagerIntegrationTest.java
index 5423076..09650cb 100644
--- a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxSearchManagerIntegrationTest.java
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxSearchManagerIntegrationTest.java
@@ -58,7 +58,7 @@ public class IBoxSearchManagerIntegrationTest extends AbstractBoxTestSupport {
public void configure() {
// test route for search
from("direct://SEARCH")
- .to("box://" + PATH_PREFIX + "/search");
+ .to("box://" + PATH_PREFIX + "/search");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxSharedItemsManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxSharedItemsManagerIntegrationTest.java b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxSharedItemsManagerIntegrationTest.java
index 5017953..24bd890 100644
--- a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxSharedItemsManagerIntegrationTest.java
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxSharedItemsManagerIntegrationTest.java
@@ -47,7 +47,7 @@ public class IBoxSharedItemsManagerIntegrationTest extends AbstractBoxTestSuppor
public void configure() {
// test route for getSharedItem
from("direct://GETSHAREDITEM")
- .to("box://" + PATH_PREFIX + "/getSharedItem?inBody=defaultRequest");
+ .to("box://" + PATH_PREFIX + "/getSharedItem?inBody=defaultRequest");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxUsersManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxUsersManagerIntegrationTest.java b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxUsersManagerIntegrationTest.java
index 11a77db..a264178 100644
--- a/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxUsersManagerIntegrationTest.java
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/IBoxUsersManagerIntegrationTest.java
@@ -61,7 +61,7 @@ public class IBoxUsersManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.userId", testUserId);
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxEmailAliasRequestObject
final BoxEmailAliasRequestObject requestObject =
- BoxEmailAliasRequestObject.addEmailAliasRequestObject(CAMEL_EMAIL_ALIAS);
+ BoxEmailAliasRequestObject.addEmailAliasRequestObject(CAMEL_EMAIL_ALIAS);
headers.put("CamelBox.emailAliasRequest", requestObject);
BoxEmailAlias result = requestBodyAndHeaders("direct://ADDEMAILALIAS", null, headers);
@@ -75,7 +75,7 @@ public class IBoxUsersManagerIntegrationTest extends AbstractBoxTestSupport {
public BoxUser createEnterpriseUser() throws Exception {
// using com.box.boxjavalibv2.requests.requestobjects.BoxUserRequestObject message body for single parameter "userRequest"
final BoxUserRequestObject enterpriseUserRequestObject =
- BoxUserRequestObject.createEnterpriseUserRequestObject(CAMEL_EMAIL_ALIAS, CAMEL_USER_NAME);
+ BoxUserRequestObject.createEnterpriseUserRequestObject(CAMEL_EMAIL_ALIAS, CAMEL_USER_NAME);
BoxUser result = requestBody("direct://CREATEENTERPRISEUSER", enterpriseUserRequestObject);
assertNotNull("createEnterpriseUser result", result);
@@ -100,7 +100,7 @@ public class IBoxUsersManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.userId", userId);
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxUserDeleteRequestObject
final BoxUserDeleteRequestObject requestObject =
- BoxUserDeleteRequestObject.deleteEnterpriseUserRequestObject(false, true);
+ BoxUserDeleteRequestObject.deleteEnterpriseUserRequestObject(false, true);
headers.put("CamelBox.userDeleteRequest", requestObject);
requestBodyAndHeaders("direct://DELETEENTERPRISEUSER", null, headers);
@@ -173,7 +173,7 @@ public class IBoxUsersManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.folderId", testFolderId);
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxSimpleUserRequestObject
final BoxSimpleUserRequestObject requestObject =
- BoxSimpleUserRequestObject.moveFolderToAnotherUserRequestEntity(toUserId, false);
+ BoxSimpleUserRequestObject.moveFolderToAnotherUserRequestEntity(toUserId, false);
headers.put("CamelBox.simpleUserRequest", requestObject);
BoxFolder result = requestBodyAndHeaders("direct://MOVEFOLDERTOANOTHERUSER", null, headers);
@@ -192,7 +192,7 @@ public class IBoxUsersManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.userId", enterpriseUser.getId());
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxUserRequestObject
final BoxUserRequestObject requestObject =
- BoxUserRequestObject.updateUserInfoRequestObject(false);
+ BoxUserRequestObject.updateUserInfoRequestObject(false);
requestObject.setJobTitle(CAMEL_JOB_TITLE);
headers.put("CamelBox.userRequest", requestObject);
@@ -217,7 +217,7 @@ public class IBoxUsersManagerIntegrationTest extends AbstractBoxTestSupport {
headers.put("CamelBox.userId", enterpriseUser.getId());
// parameter type is com.box.boxjavalibv2.requests.requestobjects.BoxUserUpdateLoginRequestObject
final BoxUserUpdateLoginRequestObject requestObject =
- BoxUserUpdateLoginRequestObject.updateUserPrimaryLoginRequestObject(UPDATED_EMAIL_ALIAS);
+ BoxUserUpdateLoginRequestObject.updateUserPrimaryLoginRequestObject(UPDATED_EMAIL_ALIAS);
headers.put("CamelBox.userUpdateLoginRequest", requestObject);
BoxUser result = requestBodyAndHeaders("direct://UPDATEUSERPRIMARYLOGIN", null, headers);
@@ -236,43 +236,43 @@ public class IBoxUsersManagerIntegrationTest extends AbstractBoxTestSupport {
public void configure() {
// test route for addEmailAlias
from("direct://ADDEMAILALIAS")
- .to("box://" + PATH_PREFIX + "/addEmailAlias");
+ .to("box://" + PATH_PREFIX + "/addEmailAlias");
// test route for createEnterpriseUser
from("direct://CREATEENTERPRISEUSER")
- .to("box://" + PATH_PREFIX + "/createEnterpriseUser?inBody=userRequest");
+ .to("box://" + PATH_PREFIX + "/createEnterpriseUser?inBody=userRequest");
// test route for deleteEmailAlias
from("direct://DELETEEMAILALIAS")
- .to("box://" + PATH_PREFIX + "/deleteEmailAlias");
+ .to("box://" + PATH_PREFIX + "/deleteEmailAlias");
// test route for deleteEnterpriseUser
from("direct://DELETEENTERPRISEUSER")
- .to("box://" + PATH_PREFIX + "/deleteEnterpriseUser");
+ .to("box://" + PATH_PREFIX + "/deleteEnterpriseUser");
// test route for getAllEnterpriseUser
from("direct://GETALLENTERPRISEUSER")
- .to("box://" + PATH_PREFIX + "/getAllEnterpriseUser");
+ .to("box://" + PATH_PREFIX + "/getAllEnterpriseUser");
// test route for getCurrentUser
from("direct://GETCURRENTUSER")
- .to("box://" + PATH_PREFIX + "/getCurrentUser?inBody=defaultRequest");
+ .to("box://" + PATH_PREFIX + "/getCurrentUser?inBody=defaultRequest");
// test route for getEmailAliases
from("direct://GETEMAILALIASES")
- .to("box://" + PATH_PREFIX + "/getEmailAliases");
+ .to("box://" + PATH_PREFIX + "/getEmailAliases");
// test route for moveFolderToAnotherUser
from("direct://MOVEFOLDERTOANOTHERUSER")
- .to("box://" + PATH_PREFIX + "/moveFolderToAnotherUser");
+ .to("box://" + PATH_PREFIX + "/moveFolderToAnotherUser");
// test route for updateUserInformaiton
from("direct://UPDATEUSERINFORMAITON")
- .to("box://" + PATH_PREFIX + "/updateUserInformaiton");
+ .to("box://" + PATH_PREFIX + "/updateUserInformaiton");
// test route for updateUserPrimaryLogin
from("direct://UPDATEUSERPRIMARYLOGIN")
- .to("box://" + PATH_PREFIX + "/updateUserPrimaryLogin");
+ .to("box://" + PATH_PREFIX + "/updateUserPrimaryLogin");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-box/src/test/java/org/apache/camel/component/box/LongPollingEventsManagerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-box/src/test/java/org/apache/camel/component/box/LongPollingEventsManagerIntegrationTest.java b/components/camel-box/src/test/java/org/apache/camel/component/box/LongPollingEventsManagerIntegrationTest.java
index 9502152..ecef86a 100644
--- a/components/camel-box/src/test/java/org/apache/camel/component/box/LongPollingEventsManagerIntegrationTest.java
+++ b/components/camel-box/src/test/java/org/apache/camel/component/box/LongPollingEventsManagerIntegrationTest.java
@@ -1,6 +1,23 @@
+/**
+ * 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.
+ */
+
/*
* Camel Api Route test generated by camel-component-util-maven-plugin
- * Generated on: Mon Jun 30 14:29:45 PDT 2014
+ * Generated on: Tue Jun 24 22:42:08 PDT 2014
*/
package org.apache.camel.component.box;
@@ -63,17 +80,17 @@ public class LongPollingEventsManagerIntegrationTest extends AbstractBoxTestSupp
for (Exchange exchange : exchanges) {
assertNotNull("poll result " + BoxConstants.CHUNK_SIZE_PROPERTY,
- exchange.getIn().getHeader(BoxConstants.CHUNK_SIZE_PROPERTY));
+ exchange.getIn().getHeader(BoxConstants.CHUNK_SIZE_PROPERTY));
assertNotNull("poll result " + BoxConstants.NEXT_STREAM_POSITION_PROPERTY,
- exchange.getIn().getHeader(BoxConstants.NEXT_STREAM_POSITION_PROPERTY));
+ exchange.getIn().getHeader(BoxConstants.NEXT_STREAM_POSITION_PROPERTY));
final Object body = exchange.getIn().getBody();
assertNotNull("poll result body", body);
assertEquals("poll result body type", BoxEvent.class, body.getClass());
- final String eventType = ((BoxEvent)body).getEventType();
+ final String eventType = ((BoxEvent) body).getEventType();
assertTrue("poll result type",
- BoxEvent.EVENT_TYPE_ITEM_COPY.equals(eventType) || BoxEvent.EVENT_TYPE_ITEM_TRASH.equals(eventType));
+ BoxEvent.EVENT_TYPE_ITEM_COPY.equals(eventType) || BoxEvent.EVENT_TYPE_ITEM_TRASH.equals(eventType));
}
}
@@ -83,15 +100,15 @@ public class LongPollingEventsManagerIntegrationTest extends AbstractBoxTestSupp
public void configure() {
// test route for copyFile
from("direct://COPYFILE")
- .to("box://" + BoxApiName.FILES.getName() + "/copyFile");
+ .to("box://" + BoxApiName.FILES.getName() + "/copyFile");
// test route for deleteFile
from("direct://DELETEFILE")
- .to("box://" + BoxApiName.FILES.getName() + "/deleteFile");
+ .to("box://" + BoxApiName.FILES.getName() + "/deleteFile");
// test route for poll
from("box://" + BoxApiName.POLL_EVENTS.getName() + "/poll?streamPosition=-1&streamType=all&limit=100")
- .to("mock:boxEvents");
+ .to("mock:boxEvents");
}
};
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-gae/src/test/java/org/apache/camel/component/gae/http/GHttpComponentConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-gae/src/test/java/org/apache/camel/component/gae/http/GHttpComponentConfigurationAndDocumentationTest.java b/components/camel-gae/src/test/java/org/apache/camel/component/gae/http/GHttpComponentConfigurationAndDocumentationTest.java
index b903ceb..013c736 100644
--- a/components/camel-gae/src/test/java/org/apache/camel/component/gae/http/GHttpComponentConfigurationAndDocumentationTest.java
+++ b/components/camel-gae/src/test/java/org/apache/camel/component/gae/http/GHttpComponentConfigurationAndDocumentationTest.java
@@ -34,8 +34,8 @@ public class GHttpComponentConfigurationAndDocumentationTest extends CamelTestSu
@Test
public void testComponentConfiguration() throws Exception {
GHttpComponent comp = context.getComponent("ghttp", GHttpComponent.class);
- EndpointConfiguration conf = comp.createConfiguration("ghttp://somewhere.com:9090/path?" +
- "bridgeEndpoint=false&throwExceptionOnFailure=false");
+ EndpointConfiguration conf = comp.createConfiguration("ghttp://somewhere.com:9090/path?"
+ + "bridgeEndpoint=false&throwExceptionOnFailure=false");
assertEquals("false", conf.getParameter("bridgeEndpoint"));
assertEquals("false", conf.getParameter("throwExceptionOnFailure"));
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpComponentConfigurationAndDocumentationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpComponentConfigurationAndDocumentationTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpComponentConfigurationAndDocumentationTest.java
index 976700d..098c04e 100644
--- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpComponentConfigurationAndDocumentationTest.java
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/JettyHttpComponentConfigurationAndDocumentationTest.java
@@ -34,8 +34,8 @@ public class JettyHttpComponentConfigurationAndDocumentationTest extends CamelTe
@Test
public void testComponentConfiguration() throws Exception {
JettyHttpComponent comp = context.getComponent("jetty", JettyHttpComponent.class);
- EndpointConfiguration conf = comp.createConfiguration("jetty://http://localhost:8080/myapp?" +
- "httpClientMinThreads=4&httpClientMaxThreads=8");
+ EndpointConfiguration conf = comp.createConfiguration("jetty://http://localhost:8080/myapp?"
+ + "httpClientMinThreads=4&httpClientMaxThreads=8");
assertEquals("4", conf.getParameter("httpClientMinThreads"));
assertEquals("8", conf.getParameter("httpClientMaxThreads"));
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-linkedin/camel-linkedin-api/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-linkedin/camel-linkedin-api/pom.xml b/components/camel-linkedin/camel-linkedin-api/pom.xml
index 012d04f..647bea8 100644
--- a/components/camel-linkedin/camel-linkedin-api/pom.xml
+++ b/components/camel-linkedin/camel-linkedin-api/pom.xml
@@ -26,8 +26,8 @@
</parent>
<artifactId>camel-linkedin-api</artifactId>
- <name>Camel LinkedIn Component API</name>
- <description>API for Camel LinkedIn Component</description>
+ <name>Camel :: LinkedIn Component API</name>
+ <description>Camel API for LinkedIn</description>
<packaging>bundle</packaging>
<properties>
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-linkedin/camel-linkedin-component/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-linkedin/camel-linkedin-component/pom.xml b/components/camel-linkedin/camel-linkedin-component/pom.xml
index 42311e2..569dcfa 100644
--- a/components/camel-linkedin/camel-linkedin-component/pom.xml
+++ b/components/camel-linkedin/camel-linkedin-component/pom.xml
@@ -27,7 +27,7 @@
<artifactId>camel-linkedin</artifactId>
<packaging>bundle</packaging>
- <name>Camel LinkedIn Component</name>
+ <name>Camel :: LinkedIn Component</name>
<description>Camel Component for LinkedIn</description>
<properties>
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-linkedin/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-linkedin/pom.xml b/components/camel-linkedin/pom.xml
index 7398fb7..1e0a984 100644
--- a/components/camel-linkedin/pom.xml
+++ b/components/camel-linkedin/pom.xml
@@ -30,7 +30,7 @@
<packaging>pom</packaging>
<version>2.14-SNAPSHOT</version>
- <name>Camel LinkedIn Component Parent</name>
+ <name>Camel :: LinkedIn Component Parent</name>
<description>Parent project for Camel {LinkedIn} Component</description>
<modules>
http://git-wip-us.apache.org/repos/asf/camel/blob/ee558f0c/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkConverter.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkConverter.java
index 1d977a0..fb95f0d 100644
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkConverter.java
+++ b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkConverter.java
@@ -26,6 +26,9 @@ import spark.Response;
@Converter
public final class SparkConverter {
+ private SparkConverter() {
+ }
+
/**
* A fallback converter that allows us to easily call Java beans and use the raw Spark {@link Request} as parameter types.
*/
[32/33] git commit: camel-testng must use spring 3 as there is NPEs
when using spring 4
Posted by da...@apache.org.
camel-testng must use spring 3 as there is NPEs when using spring 4
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/ea23613b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/ea23613b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/ea23613b
Branch: refs/heads/master
Commit: ea23613b6f5356e62994e947154fb911cffcc3ea
Parents: ee558f0
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Jul 19 11:45:01 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 11:45:01 2014 +0200
----------------------------------------------------------------------
components/camel-testng/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/ea23613b/components/camel-testng/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-testng/pom.xml b/components/camel-testng/pom.xml
index 74a881e..a27eb17 100644
--- a/components/camel-testng/pom.xml
+++ b/components/camel-testng/pom.xml
@@ -45,7 +45,7 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-test-spring</artifactId>
+ <artifactId>camel-test-spring3</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
[23/33] git commit: CAMEL-7354: Rest DSL accept renamed as consumes
to be aligned with JAX-RS
Posted by da...@apache.org.
CAMEL-7354: Rest DSL accept renamed as consumes to be aligned with JAX-RS
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/81928f22
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/81928f22
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/81928f22
Branch: refs/heads/master
Commit: 81928f220c24d6a4f5d54b4b26b4dcd0ed17c49e
Parents: 571b134
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 16 15:17:39 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:52 2014 +0200
----------------------------------------------------------------------
.../apache/camel/component/rest/RestEndpoint.java | 12 ++++++------
.../apache/camel/model/rest/PathDefinition.java | 4 ++--
.../apache/camel/model/rest/RestDefinition.java | 18 +++++++++++++++++-
.../apache/camel/model/rest/VerbDefinition.java | 10 +++++-----
.../org/apache/camel/spi/RestConsumerFactory.java | 4 ++--
.../component/rest/DummyRestConsumerFactory.java | 2 +-
.../rest/FromRestGetEmbeddedRouteTest.java | 4 ++--
.../component/rest/FromRestGetEndPathTest.java | 2 +-
.../camel/component/rest/FromRestGetTest.java | 4 ++--
.../camel/management/ManagedFromRestGetTest.java | 2 +-
.../camel/component/sparkrest/SparkComponent.java | 6 +++---
.../sparkrest/RestCamelSparkComponentTest.java | 7 ++++---
.../component/sparkrest/RestCamelSparkTest.java | 4 ++--
.../rest/SpringFromRestGetEmbeddedRouteTest.xml | 2 +-
.../component/rest/SpringFromRestGetTest.xml | 2 +-
.../rest/FromRestGetEmbeddedRouteTest.java | 2 +-
.../blueprint/component/rest/FromRestGetTest.java | 2 +-
.../rest/FromRestGetEmbeddedRouteTest.xml | 2 +-
18 files changed, 53 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
index e5a04ad..b0f546e 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -36,7 +36,7 @@ public class RestEndpoint extends DefaultEndpoint {
@UriParam
private String path;
@UriParam
- private String accept;
+ private String consumes;
@UriParam
private String componentName;
@@ -67,12 +67,12 @@ public class RestEndpoint extends DefaultEndpoint {
this.path = path;
}
- public String getAccept() {
- return accept;
+ public String getConsumes() {
+ return consumes;
}
- public void setAccept(String accept) {
- this.accept = accept;
+ public void setConsumes(String consumes) {
+ this.consumes = consumes;
}
public String getComponentName() {
@@ -129,7 +129,7 @@ public class RestEndpoint extends DefaultEndpoint {
}
if (factory != null) {
- Consumer consumer = factory.createConsumer(getCamelContext(), processor, getVerb(), getPath(), getAccept(), getParameters());
+ Consumer consumer = factory.createConsumer(getCamelContext(), processor, getVerb(), getPath(), getConsumes(), getParameters());
configureConsumer(consumer);
return consumer;
} else {
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
index 06d95bc..dd811d6 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -94,14 +94,14 @@ public class PathDefinition {
return addVerb(verb, null);
}
- public PathDefinition accept(String accept) {
+ public PathDefinition consumes(String accept) {
// add to last verb
if (getVerbs().isEmpty()) {
throw new IllegalArgumentException("Must add verb first, such as get/post/delete");
}
VerbDefinition verb = getVerbs().get(getVerbs().size() - 1);
- verb.setAccept(accept);
+ verb.setConsumes(accept);
return this;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/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 24dd3e9..6c3bb5f 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
@@ -17,7 +17,9 @@
package org.apache.camel.model.rest;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
@@ -26,6 +28,7 @@ import javax.xml.bind.annotation.XmlRootElement;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.util.URISupport;
/**
* Represents an XML <rest/> element
@@ -88,7 +91,20 @@ public class RestDefinition {
for (PathDefinition path : getPaths()) {
String uri = path.getUri();
for (VerbDefinition verb : path.getVerbs()) {
- String from = "rest:" + verb.asVerb() + ":" + uri + (getComponent() != null ? "?componentName=" + getComponent() : "");
+ String from = "rest:" + verb.asVerb() + ":" + uri;
+ // append options
+ Map<String, Object> options = new HashMap<String, Object>();
+ if (getComponent() != null) {
+ options.put("componentName", getComponent());
+ }
+ if (verb.getConsumes() != null) {
+ options.put("consumes", verb.getConsumes());
+ }
+ if (!options.isEmpty()) {
+ String query = URISupport.createQueryString(options);
+ from = from + "?" + query;
+ }
+
RouteDefinition route = new RouteDefinition();
route.fromRest(from);
answer.add(route);
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/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 9d99747..ce1482e 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
@@ -32,7 +32,7 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
private String method;
@XmlAttribute
- private String accept;
+ private String consumes;
@XmlTransient
private PathDefinition path;
@@ -53,12 +53,12 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
this.method = method;
}
- public String getAccept() {
- return accept;
+ public String getConsumes() {
+ return consumes;
}
- public void setAccept(String accept) {
- this.accept = accept;
+ public void setConsumes(String consumes) {
+ this.consumes = consumes;
}
// Fluent API
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java b/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java
index bab308a..82d2198 100644
--- a/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java
+++ b/camel-core/src/main/java/org/apache/camel/spi/RestConsumerFactory.java
@@ -33,11 +33,11 @@ public interface RestConsumerFactory {
* @param processor the processor
* @param verb HTTP verb such as GET, POST
* @param path HTTP context-path
- * @param accept accept-type, is <tt>null</tt> to accept anything
+ * @param consumes accept-type, is <tt>null</tt> to accept anything
* @param parameters additional parameters
* @return a newly created REST consumer
* @throws Exception can be thrown
*/
Consumer createConsumer(CamelContext camelContext, Processor processor,
- String verb, String path, String accept, Map<String, Object> parameters) throws Exception;
+ String verb, String path, String consumes, Map<String, Object> parameters) throws Exception;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java b/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
index bb4eddb..5ec21f8 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
@@ -29,7 +29,7 @@ public class DummyRestConsumerFactory implements RestConsumerFactory {
@Override
public Consumer createConsumer(CamelContext camelContext, Processor processor,
- String verb, String path, String accept, Map<String, Object> parameters) throws Exception {
+ String verb, String path, String consumes, Map<String, Object> parameters) throws Exception {
// just use a seda endpoint for testing purpose
String id = ActiveMQUuidGenerator.generateSanitizedId(path);
// remove leading dash as we add that ourselves
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
index a8b21eb..ebb9847 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -50,7 +50,7 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
path = rest.getPaths().get(1);
assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(0).getAccept());
+ assertEquals("application/json", path.getVerbs().get(0).getConsumes());
to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
assertEquals("mock:bye", to.getUri());
@@ -77,7 +77,7 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
.transform(constant("Hello World"))
.endPath()
.path("/say/bye")
- .get().accept("application/json")
+ .get().consumes("application/json")
.to("mock:bye")
.transform(constant("Bye World"))
.post()
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
index c52438e..7d60a09 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
@@ -29,7 +29,7 @@ public class FromRestGetEndPathTest extends FromRestGetTest {
.path("/say/hello")
.get().to("direct:hello").endPath()
.path("/say/bye")
- .get().accept("application/json").to("direct:bye").endPath()
+ .get().consumes("application/json").to("direct:bye").endPath()
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index 72ef31f..34fd0bb 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -50,7 +50,7 @@ public class FromRestGetTest extends ContextTestSupport {
path = rest.getPaths().get(1);
assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(0).getAccept());
+ assertEquals("application/json", path.getVerbs().get(0).getConsumes());
to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
assertEquals("direct:bye", to.getUri());
@@ -74,7 +74,7 @@ public class FromRestGetTest extends ContextTestSupport {
.path("/say/hello")
.get().to("direct:hello")
.path("/say/bye")
- .get().accept("application/json").to("direct:bye")
+ .get().consumes("application/json").to("direct:bye")
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
index bd6b8d4..64d237c 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
@@ -70,7 +70,7 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
.path("/say/hello")
.get().to("direct:hello")
.path("/say/bye")
- .get().accept("application/json").to("direct:bye")
+ .get().consumes("application/json").to("direct:bye")
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
index 38f1566..df58a7c 100644
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
+++ b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
@@ -99,11 +99,11 @@ public class SparkComponent extends UriEndpointComponent implements RestConsumer
@Override
public Consumer createConsumer(CamelContext camelContext, Processor processor,
- String verb, String path, String accept, Map<String, Object> parameters) throws Exception {
+ String verb, String path, String consumes, Map<String, Object> parameters) throws Exception {
// get the endpoint
SparkEndpoint endpoint;
- if (accept != null) {
- endpoint = camelContext.getEndpoint("spark-rest:" + verb + ":" + path + "?accept=" + accept, SparkEndpoint.class);
+ if (consumes != null) {
+ endpoint = camelContext.getEndpoint("spark-rest:" + verb + ":" + path + "?accept=" + consumes, SparkEndpoint.class);
} else {
endpoint = camelContext.getEndpoint("spark-rest:" + verb + ":" + path, SparkEndpoint.class);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
index 244e17e..216ffcb 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
@@ -27,9 +27,10 @@ public class RestCamelSparkComponentTest extends RestCamelSparkTest {
public void configure() throws Exception {
// explicit configure that we want to use spark-rest component
rest().component("spark-rest")
- .path("/spark")
- .get("/hello").to("direct:hello")
- .get("/bye").to("direct:bye")
+ .path("/spark/hello")
+ .get().to("direct:hello")
+ .path("/spark/bye")
+ .get().to("direct:bye")
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
index 2605928..b6473e9 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
@@ -37,7 +37,7 @@ public class RestCamelSparkTest extends BaseSparkTest {
public void testSparkPost() throws Exception {
getMockEndpoint("mock:update").expectedBodiesReceived("I did this");
- template.requestBody("http://0.0.0.0:" + getPort() + "/spark", "I did this", String.class);
+ template.requestBody("http://0.0.0.0:" + getPort() + "/spark/bye", "I did this", String.class);
assertMockEndpointsSatisfied();
}
@@ -49,7 +49,7 @@ public class RestCamelSparkTest extends BaseSparkTest {
public void configure() throws Exception {
// will automatic find the spark component to use, as we setup that component in the BaseSparkTest
rest()
- .path("/spark/hello").to("direct:hello")
+ .path("/spark/hello").get().to("direct:hello")
.path("/spark/bye").get().to("direct:bye")
.path("/spark/bye").post().to("mock:update");
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
index c91bb70..be3ff54 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
@@ -37,7 +37,7 @@
</get>
</path>
<path uri="/say/bye">
- <get accept="application/json">
+ <get consumes="application/json">
<to uri="mock:bye"/>
<transform>
<constant>Bye World</constant>
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
index 128483b..c8681f7 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
@@ -34,7 +34,7 @@
</get>
</path>
<path uri="/say/bye">
- <get accept="application/json">
+ <get consumes="application/json">
<to uri="direct:bye"/>
</get>
<post>
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
index 68cbb69..2ffb96c 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -48,7 +48,7 @@ public class FromRestGetEmbeddedRouteTest extends CamelBlueprintTestSupport {
path = rest.getPaths().get(1);
assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(0).getAccept());
+ assertEquals("application/json", path.getVerbs().get(0).getConsumes());
to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
assertEquals("mock:bye", to.getUri());
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
index 588f221..6d51ffc 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
@@ -48,7 +48,7 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
path = rest.getPaths().get(1);
assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(0).getAccept());
+ assertEquals("application/json", path.getVerbs().get(0).getConsumes());
to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
assertEquals("direct:bye", to.getUri());
http://git-wip-us.apache.org/repos/asf/camel/blob/81928f22/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
index b8a5c2a..f20fe8f 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
@@ -35,7 +35,7 @@
</get>
</path>
<path uri="/say/bye">
- <get accept="application/json">
+ <get consumes="application/json">
<to uri="mock:bye"/>
<transform>
<constant>Bye World</constant>
[15/33] git commit: CAMEL-7354: Renamed rest-binding to rest component
Posted by da...@apache.org.
CAMEL-7354: Renamed rest-binding to rest component
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c29cf0c6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c29cf0c6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c29cf0c6
Branch: refs/heads/master
Commit: c29cf0c61509cd86d6c5acf9de3b671113a60ead
Parents: 31269fd
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Jul 6 11:22:29 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:50 2014 +0200
----------------------------------------------------------------------
.../camel/component/rest/RestComponent.java | 50 +++++++
.../camel/component/rest/RestEndpoint.java | 145 +++++++++++++++++++
.../restbinding/RestBindingComponent.java | 50 -------
.../restbinding/RestBindingEndpoint.java | 145 -------------------
.../apache/camel/model/rest/RestDefinition.java | 2 +-
.../services/org/apache/camel/component/rest | 18 +++
.../org/apache/camel/component/rest-binding | 18 ---
.../rest/DummyRestConsumerFactory.java | 43 ++++++
.../camel/component/rest/FromRestGetTest.java | 86 +++++++++++
.../restbinding/DummyRestConsumerFactory.java | 43 ------
.../component/restbinding/FromRestGetTest.java | 86 -----------
.../management/ManagedFromRestGetTest.java | 2 +-
.../component/rest/SpringFromRestGetTest.java | 29 ++++
.../restbinding/SpringFromRestGetTest.java | 29 ----
.../component/rest/SpringFromRestGetTest.xml | 58 ++++++++
.../restbinding/SpringFromRestGetTest.xml | 58 --------
.../rest/DummyRestConsumerFactory.java | 43 ++++++
.../component/rest/FromRestGetTest.java | 54 +++++++
.../restbinding/DummyRestConsumerFactory.java | 43 ------
.../component/restbinding/FromRestGetTest.java | 54 -------
.../component/rest/FromRestGetTest.xml | 56 +++++++
.../component/restbinding/FromRestGetTest.xml | 56 -------
22 files changed, 584 insertions(+), 584 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
new file mode 100644
index 0000000..efa2990
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
@@ -0,0 +1,50 @@
+/**
+ * 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 java.util.Map;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.util.ObjectHelper;
+
+public class RestComponent extends UriEndpointComponent {
+
+ public RestComponent() {
+ super(RestEndpoint.class);
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ RestEndpoint answer = new RestEndpoint(uri, this);
+ setProperties(answer, parameters);
+ answer.setParameters(parameters);
+
+ if (!remaining.contains(":")) {
+ throw new IllegalArgumentException("Invalid syntax. Must be rest:verb:path");
+ }
+
+ String verb = ObjectHelper.before(remaining, ":");
+ String path = ObjectHelper.after(remaining, ":");
+
+ answer.setVerb(verb);
+ answer.setPath(path);
+
+ return answer;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
new file mode 100644
index 0000000..bb55349
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -0,0 +1,145 @@
+/**
+ * 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 java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.Component;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.RestConsumerFactory;
+import org.apache.camel.spi.UriEndpoint;
+import org.apache.camel.spi.UriParam;
+
+@UriEndpoint(scheme = "rest")
+public class RestEndpoint extends DefaultEndpoint {
+
+ @UriParam
+ private String verb;
+ @UriParam
+ private String path;
+ @UriParam
+ private String accept;
+ @UriParam
+ private String componentName;
+
+ private Map<String, Object> parameters;
+
+ public RestEndpoint(String endpointUri, RestComponent component) {
+ super(endpointUri, component);
+ }
+
+ @Override
+ public RestComponent getComponent() {
+ return (RestComponent) super.getComponent();
+ }
+
+ public String getVerb() {
+ return verb;
+ }
+
+ public void setVerb(String verb) {
+ this.verb = verb;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public String getAccept() {
+ return accept;
+ }
+
+ public void setAccept(String accept) {
+ this.accept = accept;
+ }
+
+ public String getComponentName() {
+ return componentName;
+ }
+
+ public void setComponentName(String componentName) {
+ this.componentName = componentName;
+ }
+
+ public Map<String, Object> getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(Map<String, Object> parameters) {
+ this.parameters = parameters;
+ }
+
+ @Override
+ public Producer createProducer() throws Exception {
+ throw new UnsupportedOperationException("Producer not supported");
+ }
+
+ @Override
+ public Consumer createConsumer(Processor processor) throws Exception {
+ RestConsumerFactory factory = null;
+
+ if (getComponentName() != null) {
+ Component comp = getCamelContext().getComponent(getComponentName());
+ if (comp != null && comp instanceof RestConsumerFactory) {
+ factory = (RestConsumerFactory) comp;
+ } else {
+ throw new IllegalArgumentException("Component " + getComponentName() + " is not a RestConsumerFactory");
+ }
+ }
+
+ // try all components
+ if (factory == null) {
+ for (String name : getCamelContext().getComponentNames()) {
+ Component comp = getCamelContext().getComponent(name);
+ if (comp != null && comp instanceof RestConsumerFactory) {
+ factory = (RestConsumerFactory) comp;
+ break;
+ }
+ }
+ }
+
+ // lookup in registry
+ if (factory == null) {
+ Set<RestConsumerFactory> factories = getCamelContext().getRegistry().findByType(RestConsumerFactory.class);
+ if (factories != null && factories.size() == 1) {
+ factory = factories.iterator().next();
+ }
+ }
+
+ if (factory != null) {
+ Consumer consumer = factory.createConsumer(getCamelContext(), processor, getVerb(), getPath(), getAccept(), getParameters());
+ configureConsumer(consumer);
+ return consumer;
+ } else {
+ throw new IllegalStateException("Cannot find RestConsumerFactory in Registry or as a Component to use");
+ }
+ }
+
+ @Override
+ public boolean isSingleton() {
+ return true;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
deleted file mode 100644
index b10f06f..0000000
--- a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
+++ /dev/null
@@ -1,50 +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.restbinding;
-
-import java.util.Map;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.impl.UriEndpointComponent;
-import org.apache.camel.util.ObjectHelper;
-
-public class RestBindingComponent extends UriEndpointComponent {
-
- public RestBindingComponent() {
- super(RestBindingEndpoint.class);
- }
-
- @Override
- protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- RestBindingEndpoint answer = new RestBindingEndpoint(uri, this);
- setProperties(answer, parameters);
- answer.setParameters(parameters);
-
- if (!remaining.contains(":")) {
- throw new IllegalArgumentException("Invalid syntax. Must be rest-binding:verb:path");
- }
-
- String verb = ObjectHelper.before(remaining, ":");
- String path = ObjectHelper.after(remaining, ":");
-
- answer.setVerb(verb);
- answer.setPath(path);
-
- return answer;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
deleted file mode 100644
index 42595b2..0000000
--- a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
+++ /dev/null
@@ -1,145 +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.restbinding;
-
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.camel.Component;
-import org.apache.camel.Consumer;
-import org.apache.camel.Processor;
-import org.apache.camel.Producer;
-import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.camel.spi.RestConsumerFactory;
-import org.apache.camel.spi.UriEndpoint;
-import org.apache.camel.spi.UriParam;
-
-@UriEndpoint(scheme = "rest-binding")
-public class RestBindingEndpoint extends DefaultEndpoint {
-
- @UriParam
- private String verb;
- @UriParam
- private String path;
- @UriParam
- private String accept;
- @UriParam
- private String componentName;
-
- private Map<String, Object> parameters;
-
- public RestBindingEndpoint(String endpointUri, RestBindingComponent component) {
- super(endpointUri, component);
- }
-
- @Override
- public RestBindingComponent getComponent() {
- return (RestBindingComponent) super.getComponent();
- }
-
- public String getVerb() {
- return verb;
- }
-
- public void setVerb(String verb) {
- this.verb = verb;
- }
-
- public String getPath() {
- return path;
- }
-
- public void setPath(String path) {
- this.path = path;
- }
-
- public String getAccept() {
- return accept;
- }
-
- public void setAccept(String accept) {
- this.accept = accept;
- }
-
- public String getComponentName() {
- return componentName;
- }
-
- public void setComponentName(String componentName) {
- this.componentName = componentName;
- }
-
- public Map<String, Object> getParameters() {
- return parameters;
- }
-
- public void setParameters(Map<String, Object> parameters) {
- this.parameters = parameters;
- }
-
- @Override
- public Producer createProducer() throws Exception {
- throw new UnsupportedOperationException("Producer not supported");
- }
-
- @Override
- public Consumer createConsumer(Processor processor) throws Exception {
- RestConsumerFactory factory = null;
-
- if (getComponentName() != null) {
- Component comp = getCamelContext().getComponent(getComponentName());
- if (comp != null && comp instanceof RestConsumerFactory) {
- factory = (RestConsumerFactory) comp;
- } else {
- throw new IllegalArgumentException("Component " + getComponentName() + " is not a RestConsumerFactory");
- }
- }
-
- // try all components
- if (factory == null) {
- for (String name : getCamelContext().getComponentNames()) {
- Component comp = getCamelContext().getComponent(name);
- if (comp != null && comp instanceof RestConsumerFactory) {
- factory = (RestConsumerFactory) comp;
- break;
- }
- }
- }
-
- // lookup in registry
- if (factory == null) {
- Set<RestConsumerFactory> factories = getCamelContext().getRegistry().findByType(RestConsumerFactory.class);
- if (factories != null && factories.size() == 1) {
- factory = factories.iterator().next();
- }
- }
-
- if (factory != null) {
- Consumer consumer = factory.createConsumer(getCamelContext(), processor, getVerb(), getPath(), getAccept(), getParameters());
- configureConsumer(consumer);
- return consumer;
- } else {
- throw new IllegalStateException("Cannot find RestConsumerFactory in Registry or as a Component to use");
- }
- }
-
- @Override
- public boolean isSingleton() {
- return true;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/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 db48564..c3ec144 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
@@ -86,7 +86,7 @@ public class RestDefinition {
for (PathDefinition path : getPaths()) {
String uri = path.getUri();
for (VerbDefinition verb : path.getVerbs()) {
- String from = "rest-binding:" + verb.getMethod() + ":" + uri + (verb.getUri() != null ? verb.getUri() : "");
+ String from = "rest:" + verb.getMethod() + ":" + uri + (verb.getUri() != null ? verb.getUri() : "");
RouteDefinition route = new RouteDefinition();
route.fromRest(from);
answer.add(route);
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest b/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest
new file mode 100644
index 0000000..40c85ca
--- /dev/null
+++ b/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.rest.RestComponent
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest-binding
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest-binding b/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest-binding
deleted file mode 100644
index 3bf1949..0000000
--- a/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest-binding
+++ /dev/null
@@ -1,18 +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.
-#
-
-class=org.apache.camel.component.restbinding.RestBindingComponent
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java b/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
new file mode 100644
index 0000000..bb4eddb
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/DummyRestConsumerFactory.java
@@ -0,0 +1,43 @@
+/**
+ * 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 java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.component.seda.SedaEndpoint;
+import org.apache.camel.impl.ActiveMQUuidGenerator;
+import org.apache.camel.spi.RestConsumerFactory;
+
+public class DummyRestConsumerFactory implements RestConsumerFactory {
+
+ @Override
+ public Consumer createConsumer(CamelContext camelContext, Processor processor,
+ String verb, String path, String accept, Map<String, Object> parameters) throws Exception {
+ // just use a seda endpoint for testing purpose
+ String id = ActiveMQUuidGenerator.generateSanitizedId(path);
+ // remove leading dash as we add that ourselves
+ if (id.startsWith("-")) {
+ id = id.substring(1);
+ }
+ SedaEndpoint seda = camelContext.getEndpoint("seda:" + verb + "-" + id, SedaEndpoint.class);
+ return seda.createConsumer(processor);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
new file mode 100644
index 0000000..eb284fc
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -0,0 +1,86 @@
+/**
+ * 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.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.rest.PathDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+
+public class FromRestGetTest extends ContextTestSupport {
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ jndi.bind("dummy-test", new DummyRestConsumerFactory());
+ return jndi;
+ }
+
+ public void testFromRestModel() throws Exception {
+ assertEquals(2 + 3, context.getRoutes().size());
+
+ RestDefinition rest = context.getRestDefinitions().get(0);
+ assertNotNull(rest);
+
+ PathDefinition path = rest.getPaths().get(0);
+ assertNotNull(0);
+ assertEquals("/say", path.getUri());
+
+ assertEquals("/hello", path.getVerbs().get(0).getUri());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("direct:hello", to.getUri());
+
+ assertEquals("/bye", path.getVerbs().get(1).getUri());
+ to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
+ assertEquals("direct:bye", to.getUri());
+
+ assertEquals(null, path.getVerbs().get(2).getUri());
+
+ // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
+
+ getMockEndpoint("mock:update").expectedMessageCount(1);
+ template.sendBody("seda:post-say", "I was here");
+ assertMockEndpointsSatisfied();
+
+ String out = template.requestBody("seda:get-say-hello", "Me", String.class);
+ assertEquals("Hello World", out);
+ String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
+ assertEquals("Bye World", out2);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ rest()
+ .path("/say")
+ .get("/hello").to("direct:hello")
+ .get("/bye").to("direct:bye")
+ .post().to("mock:update");
+
+ from("direct:hello")
+ .transform().constant("Hello World");
+
+ from("direct:bye")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestConsumerFactory.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestConsumerFactory.java
deleted file mode 100644
index 95d8106..0000000
--- a/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestConsumerFactory.java
+++ /dev/null
@@ -1,43 +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.restbinding;
-
-import java.util.Map;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Consumer;
-import org.apache.camel.Processor;
-import org.apache.camel.component.seda.SedaEndpoint;
-import org.apache.camel.impl.ActiveMQUuidGenerator;
-import org.apache.camel.spi.RestConsumerFactory;
-
-public class DummyRestConsumerFactory implements RestConsumerFactory {
-
- @Override
- public Consumer createConsumer(CamelContext camelContext, Processor processor,
- String verb, String path, String accept, Map<String, Object> parameters) throws Exception {
- // just use a seda endpoint for testing purpose
- String id = ActiveMQUuidGenerator.generateSanitizedId(path);
- // remove leading dash as we add that ourselves
- if (id.startsWith("-")) {
- id = id.substring(1);
- }
- SedaEndpoint seda = camelContext.getEndpoint("seda:" + verb + "-" + id, SedaEndpoint.class);
- return seda.createConsumer(processor);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
deleted file mode 100644
index da8a765..0000000
--- a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
+++ /dev/null
@@ -1,86 +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.restbinding;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.JndiRegistry;
-import org.apache.camel.model.ToDefinition;
-import org.apache.camel.model.rest.PathDefinition;
-import org.apache.camel.model.rest.RestDefinition;
-
-public class FromRestGetTest extends ContextTestSupport {
-
- @Override
- protected JndiRegistry createRegistry() throws Exception {
- JndiRegistry jndi = super.createRegistry();
- jndi.bind("dummy-test", new DummyRestConsumerFactory());
- return jndi;
- }
-
- public void testFromRestModel() throws Exception {
- assertEquals(2 + 3, context.getRoutes().size());
-
- RestDefinition rest = context.getRestDefinitions().get(0);
- assertNotNull(rest);
-
- PathDefinition path = rest.getPaths().get(0);
- assertNotNull(0);
- assertEquals("/say", path.getUri());
-
- assertEquals("/hello", path.getVerbs().get(0).getUri());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
- assertEquals("direct:hello", to.getUri());
-
- assertEquals("/bye", path.getVerbs().get(1).getUri());
- to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
- assertEquals("direct:bye", to.getUri());
-
- assertEquals(null, path.getVerbs().get(2).getUri());
-
- // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
-
- getMockEndpoint("mock:update").expectedMessageCount(1);
- template.sendBody("seda:post-say", "I was here");
- assertMockEndpointsSatisfied();
-
- String out = template.requestBody("seda:get-say-hello", "Me", String.class);
- assertEquals("Hello World", out);
- String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
- assertEquals("Bye World", out2);
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() throws Exception {
- return new RouteBuilder() {
- @Override
- public void configure() throws Exception {
- rest()
- .path("/say")
- .get("/hello").to("direct:hello")
- .get("/bye").to("direct:bye")
- .post().to("mock:update");
-
- from("direct:hello")
- .transform().constant("Hello World");
-
- from("direct:bye")
- .transform().constant("Bye World");
- }
- };
- }
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
index 43c9d37..3e5facc 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
@@ -21,7 +21,7 @@ import javax.management.ObjectName;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.restbinding.DummyRestConsumerFactory;
+import org.apache.camel.component.rest.DummyRestConsumerFactory;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.SimpleRegistry;
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetTest.java
new file mode 100644
index 0000000..b8908ff
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/component/rest/SpringFromRestGetTest.java
@@ -0,0 +1,29 @@
+/**
+ * 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.CamelContext;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringFromRestGetTest extends FromRestGetTest {
+
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/component/rest/SpringFromRestGetTest.xml");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/components/camel-spring/src/test/java/org/apache/camel/component/restbinding/SpringFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/restbinding/SpringFromRestGetTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/restbinding/SpringFromRestGetTest.java
deleted file mode 100644
index 371721c..0000000
--- a/components/camel-spring/src/test/java/org/apache/camel/component/restbinding/SpringFromRestGetTest.java
+++ /dev/null
@@ -1,29 +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.restbinding;
-
-import org.apache.camel.CamelContext;
-
-import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
-
-public class SpringFromRestGetTest extends FromRestGetTest {
-
- protected CamelContext createCamelContext() throws Exception {
- return createSpringCamelContext(this, "org/apache/camel/component/restbinding/SpringFromRestGetTest.xml");
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
new file mode 100644
index 0000000..0b13013
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- use a dummy rest consumer factory for the rest engine -->
+ <bean id="dummy-rest" class="org.apache.camel.component.rest.DummyRestConsumerFactory"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <rest component="dummy-rest" routeId="myRestRoute">
+ <path uri="/say">
+ <get uri="/hello">
+ <to uri="direct:hello"/>
+ </get>
+ <get uri="/bye">
+ <to uri="direct:bye"/>
+ </get>
+ <post>
+ <to uri="mock:update"/>
+ </post>
+ </path>
+ </rest>
+
+ <route id="helloRoute">
+ <from uri="direct:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </route>
+ <route id="byeRoute">
+ <from uri="direct:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+ </camelContext>
+
+</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
deleted file mode 100644
index 8929e75..0000000
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/restbinding/SpringFromRestGetTest.xml
+++ /dev/null
@@ -1,58 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
- ">
-
- <!-- use a dummy rest consumer factory for the rest engine -->
- <bean id="dummy-rest" class="org.apache.camel.component.restbinding.DummyRestConsumerFactory"/>
-
- <camelContext xmlns="http://camel.apache.org/schema/spring">
-
- <rest component="dummy-rest" routeId="myRestRoute">
- <path uri="/say">
- <get uri="/hello">
- <to uri="direct:hello"/>
- </get>
- <get uri="/bye">
- <to uri="direct:bye"/>
- </get>
- <post>
- <to uri="mock:update"/>
- </post>
- </path>
- </rest>
-
- <route id="helloRoute">
- <from uri="direct:hello"/>
- <transform>
- <constant>Hello World</constant>
- </transform>
- </route>
- <route id="byeRoute">
- <from uri="direct:bye"/>
- <transform>
- <constant>Bye World</constant>
- </transform>
- </route>
- </camelContext>
-
-</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java
new file mode 100644
index 0000000..47d8059
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/DummyRestConsumerFactory.java
@@ -0,0 +1,43 @@
+/**
+ * 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.test.blueprint.component.rest;
+
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.component.seda.SedaEndpoint;
+import org.apache.camel.impl.ActiveMQUuidGenerator;
+import org.apache.camel.spi.RestConsumerFactory;
+
+public class DummyRestConsumerFactory implements RestConsumerFactory {
+
+ @Override
+ public Consumer createConsumer(CamelContext camelContext, Processor processor,
+ String verb, String path, String accept, Map<String, Object> parameters) throws Exception {
+ // just use a seda endpoint for testing purpose
+ String id = ActiveMQUuidGenerator.generateSanitizedId(path);
+ // remove leading dash as we add that ourselves
+ if (id.startsWith("-")) {
+ id = id.substring(1);
+ }
+ SedaEndpoint seda = camelContext.getEndpoint("seda:" + verb + "-" + id, SedaEndpoint.class);
+ return seda.createConsumer(processor);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
new file mode 100644
index 0000000..ce24d4d
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
@@ -0,0 +1,54 @@
+/**
+ * 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.test.blueprint.component.rest;
+
+import org.apache.camel.model.ToDefinition;
+import org.apache.camel.model.rest.PathDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
+import org.junit.Test;
+
+public class FromRestGetTest extends CamelBlueprintTestSupport {
+
+ @Override
+ protected String getBlueprintDescriptor() {
+ return "org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml";
+ }
+
+ @Test
+ public void testFromRestModel() {
+ assertEquals(2 + 3, context.getRoutes().size());
+
+ RestDefinition rest = context.getRestDefinitions().get(0);
+ assertNotNull(rest);
+
+ PathDefinition path = rest.getPaths().get(0);
+ assertNotNull(0);
+ assertEquals("/say", path.getUri());
+
+ assertEquals("/hello", path.getVerbs().get(0).getUri());
+ ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("direct:hello", to.getUri());
+
+ assertEquals("/bye", path.getVerbs().get(1).getUri());
+ to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
+ assertEquals("direct:bye", to.getUri());
+
+ assertEquals(null, path.getVerbs().get(2).getUri());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/DummyRestConsumerFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/DummyRestConsumerFactory.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/DummyRestConsumerFactory.java
deleted file mode 100644
index b8349c5..0000000
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/DummyRestConsumerFactory.java
+++ /dev/null
@@ -1,43 +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.test.blueprint.component.restbinding;
-
-import java.util.Map;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Consumer;
-import org.apache.camel.Processor;
-import org.apache.camel.component.seda.SedaEndpoint;
-import org.apache.camel.impl.ActiveMQUuidGenerator;
-import org.apache.camel.spi.RestConsumerFactory;
-
-public class DummyRestConsumerFactory implements RestConsumerFactory {
-
- @Override
- public Consumer createConsumer(CamelContext camelContext, Processor processor,
- String verb, String path, String accept, Map<String, Object> parameters) throws Exception {
- // just use a seda endpoint for testing purpose
- String id = ActiveMQUuidGenerator.generateSanitizedId(path);
- // remove leading dash as we add that ourselves
- if (id.startsWith("-")) {
- id = id.substring(1);
- }
- SedaEndpoint seda = camelContext.getEndpoint("seda:" + verb + "-" + id, SedaEndpoint.class);
- return seda.createConsumer(processor);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java
deleted file mode 100644
index c02c1de..0000000
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.test.blueprint.component.restbinding;
-
-import org.apache.camel.model.ToDefinition;
-import org.apache.camel.model.rest.PathDefinition;
-import org.apache.camel.model.rest.RestDefinition;
-import org.apache.camel.test.blueprint.CamelBlueprintTestSupport;
-import org.junit.Test;
-
-public class FromRestGetTest extends CamelBlueprintTestSupport {
-
- @Override
- protected String getBlueprintDescriptor() {
- return "org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml";
- }
-
- @Test
- public void testFromRestModel() {
- assertEquals(2 + 3, context.getRoutes().size());
-
- RestDefinition rest = context.getRestDefinitions().get(0);
- assertNotNull(rest);
-
- PathDefinition path = rest.getPaths().get(0);
- assertNotNull(0);
- assertEquals("/say", path.getUri());
-
- assertEquals("/hello", path.getVerbs().get(0).getUri());
- ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
- assertEquals("direct:hello", to.getUri());
-
- assertEquals("/bye", path.getVerbs().get(1).getUri());
- to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
- assertEquals("direct:bye", to.getUri());
-
- assertEquals(null, path.getVerbs().get(2).getUri());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
new file mode 100644
index 0000000..d094a0c
--- /dev/null
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
+
+ <!-- use a dummy rest consumer factory for the rest engine -->
+ <bean id="dummy-rest" class="org.apache.camel.test.blueprint.component.rest.DummyRestConsumerFactory"/>
+
+ <camelContext xmlns="http://camel.apache.org/schema/blueprint">
+
+ <rest component="dummy-rest" routeId="myRestRoute">
+ <path uri="/say">
+ <get uri="/hello">
+ <to uri="direct:hello"/>
+ </get>
+ <get uri="/bye">
+ <to uri="direct:bye"/>
+ </get>
+ <post>
+ <to uri="mock:update"/>
+ </post>
+ </path>
+ </rest>
+
+ <route id="helloRoute">
+ <from uri="direct:hello"/>
+ <transform>
+ <constant>Hello World</constant>
+ </transform>
+ </route>
+ <route id="byeRoute">
+ <from uri="direct:bye"/>
+ <transform>
+ <constant>Bye World</constant>
+ </transform>
+ </route>
+ </camelContext>
+
+</blueprint>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/c29cf0c6/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
deleted file mode 100644
index f5e83f5..0000000
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/restbinding/FromRestGetTest.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="
- http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
-
- <!-- use a dummy rest consumer factory for the rest engine -->
- <bean id="dummy-rest" class="org.apache.camel.test.blueprint.component.restbinding.DummyRestConsumerFactory"/>
-
- <camelContext xmlns="http://camel.apache.org/schema/blueprint">
-
- <rest component="dummy-rest" routeId="myRestRoute">
- <path uri="/say">
- <get uri="/hello">
- <to uri="direct:hello"/>
- </get>
- <get uri="/bye">
- <to uri="direct:bye"/>
- </get>
- <post>
- <to uri="mock:update"/>
- </post>
- </path>
- </rest>
-
- <route id="helloRoute">
- <from uri="direct:hello"/>
- <transform>
- <constant>Hello World</constant>
- </transform>
- </route>
- <route id="byeRoute">
- <from uri="direct:bye"/>
- <transform>
- <constant>Bye World</constant>
- </transform>
- </route>
- </camelContext>
-
-</blueprint>
\ No newline at end of file
[30/33] git commit: CAMEL-7364: Rest DSL allows to configure
properties for rest configuration.
Posted by da...@apache.org.
CAMEL-7364: Rest DSL allows to configure properties for rest configuration.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7bbb88ba
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7bbb88ba
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7bbb88ba
Branch: refs/heads/master
Commit: 7bbb88ba4dfd58064d8be3f0a5405a639df9c07e
Parents: 2f856a6
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Jul 18 10:36:45 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:53 2014 +0200
----------------------------------------------------------------------
.../model/rest/RestConfigurationDefinition.java | 42 ++++++++++------
.../model/rest/RestPropertyDefinition.java | 52 ++++++++++++++++++++
.../org/apache/camel/model/rest/jaxb.index | 1 +
.../rest/FromRestConfigurationTest.java | 3 +-
.../rest/SpringFromRestConfigurationTest.xml | 4 +-
.../rest/FromRestConfigurationTest.java | 1 +
.../rest/FromRestConfigurationTest.xml | 4 +-
7 files changed, 88 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7bbb88ba/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
index 0e8c170..797b06a 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestConfigurationDefinition.java
@@ -16,9 +16,14 @@
*/
package org.apache.camel.model.rest;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.camel.CamelContext;
@@ -41,10 +46,8 @@ public class RestConfigurationDefinition {
@XmlAttribute
private String port;
- // TODO: get properties to work with JAXB in the XSD model
-
-// @XmlElementRef
-// private List<PropertyDefinition> properties = new ArrayList<PropertyDefinition>();
+ @XmlElementRef
+ private List<RestPropertyDefinition> properties = new ArrayList<RestPropertyDefinition>();
public String getComponent() {
return component;
@@ -70,6 +73,14 @@ public class RestConfigurationDefinition {
this.port = port;
}
+ public List<RestPropertyDefinition> getProperties() {
+ return properties;
+ }
+
+ public void setProperties(List<RestPropertyDefinition> properties) {
+ this.properties = properties;
+ }
+
// Fluent API
//-------------------------------------------------------------------------
@@ -97,10 +108,10 @@ public class RestConfigurationDefinition {
}
public RestConfigurationDefinition property(String key, String value) {
- /*PropertyDefinition prop = new PropertyDefinition();
+ RestPropertyDefinition prop = new RestPropertyDefinition();
prop.setKey(key);
prop.setValue(value);
- getProperties().add(prop);*/
+ getProperties().add(prop);
return this;
}
@@ -116,26 +127,25 @@ public class RestConfigurationDefinition {
*/
public RestConfiguration asRestConfiguration(CamelContext context) throws Exception {
RestConfiguration answer = new RestConfiguration();
- if (getComponent() != null) {
- answer.setComponent(CamelContextHelper.parseText(context, getComponent()));
+ if (component != null) {
+ answer.setComponent(CamelContextHelper.parseText(context, component));
}
- if (getHost() != null) {
- answer.setHost(CamelContextHelper.parseText(context, getHost()));
+ if (host != null) {
+ answer.setHost(CamelContextHelper.parseText(context, host));
}
- if (getPort() != null) {
- answer.setPort(CamelContextHelper.parseInteger(context, getPort()));
+ if (port != null) {
+ answer.setPort(CamelContextHelper.parseInteger(context, port));
}
- /*if (!properties.isEmpty()) {
+ if (!properties.isEmpty()) {
Map<String, Object> props = new HashMap<String, Object>();
- for (PropertyDefinition prop : properties) {
+ for (RestPropertyDefinition prop : properties) {
String key = prop.getKey();
String value = CamelContextHelper.parseText(context, prop.getValue());
props.put(key, value);
}
answer.setProperties(props);
- }*/
+ }
return answer;
-
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7bbb88ba/camel-core/src/main/java/org/apache/camel/model/rest/RestPropertyDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestPropertyDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestPropertyDefinition.java
new file mode 100644
index 0000000..e1d5897
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestPropertyDefinition.java
@@ -0,0 +1,52 @@
+/**
+ * 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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Represents the XML type for <restProperty>.
+ */
+@XmlRootElement(name = "restProperty")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class RestPropertyDefinition {
+
+ @XmlAttribute(required = true)
+ String key;
+
+ @XmlAttribute(required = true)
+ String value;
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/7bbb88ba/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
index 1c50df5..5a3e94b 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/rest/jaxb.index
@@ -21,5 +21,6 @@ PostVerbDefinition
PutVerbDefinition
RestConfigurationDefinition
RestDefinition
+RestPropertyDefinition
RestsDefinition
VerbDefinition
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/7bbb88ba/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
index 73992cc..49fb6c8 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestConfigurationTest.java
@@ -27,6 +27,7 @@ public class FromRestConfigurationTest extends FromRestGetTest {
assertEquals("dummy-rest", context.getRestConfiguration().getComponent());
assertEquals("localhost", context.getRestConfiguration().getHost());
assertEquals(9090, context.getRestConfiguration().getPort());
+ assertEquals("bar", context.getRestConfiguration().getProperties().get("foo"));
}
@Override
@@ -34,7 +35,7 @@ public class FromRestConfigurationTest extends FromRestGetTest {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
- restConfiguration().component("dummy-rest").host("localhost").port(9090);
+ restConfiguration().component("dummy-rest").host("localhost").port(9090).property("foo", "bar");
rest("/say/hello")
.get().to("direct:hello");
http://git-wip-us.apache.org/repos/asf/camel/blob/7bbb88ba/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml
index 79c84e5..d9ec45d 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestConfigurationTest.xml
@@ -27,7 +27,9 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
- <restConfiguration component="dummy-rest" host="localhost" port="9090"/>
+ <restConfiguration component="dummy-rest" host="localhost" port="9090">
+ <restProperty key="foo" value="bar"/>
+ </restConfiguration>
<rest uri="/say/hello">
<get>
http://git-wip-us.apache.org/repos/asf/camel/blob/7bbb88ba/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.java
index b2e6f91..25ffdce 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.java
@@ -32,6 +32,7 @@ public class FromRestConfigurationTest extends FromRestGetTest {
assertEquals("dummy-rest", context.getRestConfiguration().getComponent());
assertEquals("localhost", context.getRestConfiguration().getHost());
assertEquals(9090, context.getRestConfiguration().getPort());
+ assertEquals("bar", context.getRestConfiguration().getProperties().get("foo"));
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7bbb88ba/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml
index 9fa70e0..6bf8d0f 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestConfigurationTest.xml
@@ -25,7 +25,9 @@
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
- <restConfiguration component="dummy-rest" host="localhost" port="9090"/>
+ <restConfiguration component="dummy-rest" host="localhost" port="9090">
+ <restProperty key="foo" value="bar"/>
+ </restConfiguration>
<rest uri="/say/hello">
<get>
[19/33] git commit: CAMEL-7354: Rest DSL,
only path is used for defining the path.
Posted by da...@apache.org.
CAMEL-7354: Rest DSL, only path is used for defining the path.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/f73a592f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/f73a592f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/f73a592f
Branch: refs/heads/master
Commit: f73a592f81db0a851bf30df9d7cd67ce71e658eb
Parents: 490f2d8
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 16 12:38:33 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:51 2014 +0200
----------------------------------------------------------------------
.../apache/camel/model/ProcessorDefinition.java | 2 +-
.../apache/camel/model/rest/PathDefinition.java | 48 ++++++------------
.../apache/camel/model/rest/RestDefinition.java | 7 +--
.../apache/camel/model/rest/VerbDefinition.java | 51 ++------------------
.../rest/FromRestGetEmbeddedRouteTest.java | 24 ++++-----
.../component/rest/FromRestGetEndPathTest.java | 7 +--
.../camel/component/rest/FromRestGetTest.java | 27 ++++-------
.../management/ManagedFromRestGetTest.java | 8 +--
.../camel/blueprint/BlueprintJaxbRestTest.java | 15 +++---
.../src/test/resources/test-rest.xml | 8 +--
.../component/sparkrest/RestCamelSparkTest.java | 7 ++-
.../rest/SpringFromRestGetEmbeddedRouteTest.xml | 8 +--
.../component/rest/SpringFromRestGetTest.xml | 8 +--
.../rest/FromRestGetEmbeddedRouteTest.java | 16 ++----
.../component/rest/FromRestGetTest.java | 36 ++++++++------
.../rest/FromRestGetEmbeddedRouteTest.xml | 8 +--
.../component/rest/FromRestGetTest.xml | 8 +--
17 files changed, 111 insertions(+), 177 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
index d2301b6..e5140f2 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
@@ -1319,7 +1319,7 @@ public abstract class ProcessorDefinition<Type extends ProcessorDefinition<Type>
}
/**
- * Ends the current block and returns back to the {@link ChoiceDefinition choice()} DSL.
+ * Ends the current block and returns back to the {@link PathDefinition path()} DSL.
*
* @return the builder
*/
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
index e60fff7..bb70b3c 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -23,6 +23,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
import org.apache.camel.model.ToDefinition;
@@ -32,6 +33,7 @@ public class PathDefinition {
private String uri;
private List<VerbDefinition> verbs = new ArrayList<VerbDefinition>();
+ private RestDefinition rest;
public String getUri() {
return uri;
@@ -51,66 +53,47 @@ public class PathDefinition {
this.verbs = verbs;
}
+ public RestDefinition getRest() {
+ return rest;
+ }
+
+ @XmlTransient
+ public void setRest(RestDefinition rest) {
+ this.rest = rest;
+ }
+
// Fluent API
//-------------------------------------------------------------------------
- public PathDefinition routeId(String routeId) {
- // set on last verb
- if (verbs != null && !verbs.isEmpty()) {
- VerbDefinition last = verbs.get(verbs.size() - 1);
- last.setRouteId(routeId);
- }
- return this;
+ public PathDefinition path(String uri) {
+ // add a new path on the rest
+ return rest.path(uri);
}
public PathDefinition get() {
return addVerb("get", null);
}
- public PathDefinition get(String url) {
- return addVerb("get", url);
- }
-
public PathDefinition post() {
return addVerb("post", null);
}
- public PathDefinition post(String url) {
- return addVerb("post", url);
- }
-
public PathDefinition put() {
return addVerb("put", null);
}
- public PathDefinition put(String url) {
- return addVerb("put", url);
- }
-
public PathDefinition delete() {
return addVerb("delete", null);
}
- public PathDefinition delete(String url) {
- return addVerb("delete", url);
- }
-
public PathDefinition head() {
return addVerb("head", null);
}
- public PathDefinition head(String url) {
- return addVerb("head", url);
- }
-
public PathDefinition verb(String verb) {
return addVerb(verb, null);
}
- public PathDefinition verb(String verb, String url) {
- return addVerb(verb, url);
- }
-
public PathDefinition accept(String accept) {
// add to last verb
if (getVerbs().isEmpty()) {
@@ -141,9 +124,6 @@ public class PathDefinition {
answer.setMethod(verb);
answer.setPath(this);
getVerbs().add(answer);
- if (url != null) {
- answer.setUri(url);
- }
return this;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/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 93180ad..546bb3a 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
@@ -71,6 +71,7 @@ public class RestDefinition {
*/
public PathDefinition path(String uri) {
PathDefinition answer = new PathDefinition();
+ answer.setRest(this);
getPaths().add(answer);
answer.setUri(uri);
return answer;
@@ -87,13 +88,9 @@ public class RestDefinition {
for (PathDefinition path : getPaths()) {
String uri = path.getUri();
for (VerbDefinition verb : path.getVerbs()) {
- String from = "rest:" + verb.getMethod() + ":" + uri + (verb.getUri() != null ? verb.getUri() : "")
- + (getComponent() != null ? "?componentName=" + getComponent() : "");
+ String from = "rest:" + verb.getMethod() + ":" + uri + (getComponent() != null ? "?componentName=" + getComponent() : "");
RouteDefinition route = new RouteDefinition();
route.fromRest(from);
- if (verb.getRouteId() != null) {
- route.setId(verb.getRouteId());
- }
answer.add(route);
route.getOutputs().addAll(verb.getOutputs());
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/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 7b1fbd7..b3f48aa 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
@@ -29,15 +29,9 @@ import org.apache.camel.model.OutputDefinition;
public class VerbDefinition extends OutputDefinition<VerbDefinition> {
@XmlAttribute
- private String routeId;
-
- @XmlAttribute
private String method;
@XmlAttribute
- private String uri;
-
- @XmlAttribute
private String accept;
@XmlTransient
@@ -51,14 +45,6 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
this.path = path;
}
- public String getRouteId() {
- return routeId;
- }
-
- public void setRouteId(String routeId) {
- this.routeId = routeId;
- }
-
public String getMethod() {
return method;
}
@@ -67,14 +53,6 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
this.method = method;
}
- public String getUri() {
- return uri;
- }
-
- public void setUri(String uri) {
- this.uri = uri;
- }
-
public String getAccept() {
return accept;
}
@@ -86,52 +64,33 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
// Fluent API
// -------------------------------------------------------------------------
- public PathDefinition get() {
- return path.get();
+ public PathDefinition path(String uri) {
+ PathDefinition parent = endPath();
+ return parent.path(uri);
}
- public PathDefinition get(String url) {
- return path.get(url);
+ public PathDefinition get() {
+ return path.get();
}
public PathDefinition post() {
return path.post();
}
- public PathDefinition post(String url) {
- return path.post(url);
- }
-
public PathDefinition put() {
return path.put();
}
- public PathDefinition put(String url) {
- return path.put(url);
- }
-
public PathDefinition delete() {
return path.delete();
}
- public PathDefinition delete(String url) {
- return path.delete(url);
- }
-
public PathDefinition head() {
return path.head();
}
- public PathDefinition head(String url) {
- return path.head(url);
- }
-
public PathDefinition verb(String verb) {
return path.verb(verb);
}
- public PathDefinition verb(String verb, String url) {
- return path.verb(verb, url);
- }
-
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
index af5815a..4343646 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -42,27 +42,19 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
- // we should have a hello and bye route
- assertNotNull(context.getRouteDefinition("hello"));
- assertNotNull(context.getRouteDefinition("bye"));
-
+ assertEquals(2, rest.getPaths().size());
PathDefinition path = rest.getPaths().get(0);
- assertNotNull(0);
- assertEquals("/say", path.getUri());
-
- assertEquals("/hello", path.getVerbs().get(0).getUri());
+ assertEquals("/say/hello", path.getUri());
ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
assertEquals("mock:hello", to.getUri());
- assertEquals("/bye", path.getVerbs().get(1).getUri());
+ path = rest.getPaths().get(1);
+ assertEquals("/say/bye", path.getUri());
assertEquals("application/json", path.getVerbs().get(1).getAccept());
to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
assertEquals("mock:bye", to.getUri());
- assertEquals(null, path.getVerbs().get(2).getUri());
-
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
-
getMockEndpoint("mock:update").expectedMessageCount(1);
template.sendBody("seda:post-say", "I was here");
assertMockEndpointsSatisfied();
@@ -79,11 +71,13 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
@Override
public void configure() throws Exception {
rest()
- .path("/say")
- .get("/hello").routeId("hello")
+ .path("/say/hello")
+ .get()
.to("mock:hello")
.transform(constant("Hello World"))
- .get("/bye").accept("application/json").routeId("bye")
+ .endPath()
+ .path("/say/bye")
+ .get().accept("application/json")
.to("mock:bye")
.transform(constant("Bye World"))
.post()
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
index 4910716..c52438e 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEndPathTest.java
@@ -26,9 +26,10 @@ public class FromRestGetEndPathTest extends FromRestGetTest {
@Override
public void configure() throws Exception {
rest()
- .path("/say")
- .get("/hello").routeId("hello").to("direct:hello").endPath()
- .get("/bye").accept("application/json").routeId("bye").to("direct:bye").endPath()
+ .path("/say/hello")
+ .get().to("direct:hello").endPath()
+ .path("/say/bye")
+ .get().accept("application/json").to("direct:bye").endPath()
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index 7042051..4b607b7 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -42,27 +42,19 @@ public class FromRestGetTest extends ContextTestSupport {
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
- // we should have a hello and bye route
- assertNotNull(context.getRouteDefinition("hello"));
- assertNotNull(context.getRouteDefinition("bye"));
-
+ assertEquals(2, rest.getPaths().size());
PathDefinition path = rest.getPaths().get(0);
- assertNotNull(0);
- assertEquals("/say", path.getUri());
-
- assertEquals("/hello", path.getVerbs().get(0).getUri());
+ assertEquals("/say/hello", path.getUri());
ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
- assertEquals("direct:hello", to.getUri());
+ assertEquals("mock:hello", to.getUri());
- assertEquals("/bye", path.getVerbs().get(1).getUri());
+ path = rest.getPaths().get(1);
+ assertEquals("/say/bye", path.getUri());
assertEquals("application/json", path.getVerbs().get(1).getAccept());
to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
- assertEquals("direct:bye", to.getUri());
-
- assertEquals(null, path.getVerbs().get(2).getUri());
+ assertEquals("mock:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
-
getMockEndpoint("mock:update").expectedMessageCount(1);
template.sendBody("seda:post-say", "I was here");
assertMockEndpointsSatisfied();
@@ -79,9 +71,10 @@ public class FromRestGetTest extends ContextTestSupport {
@Override
public void configure() throws Exception {
rest()
- .path("/say")
- .get("/hello").routeId("hello").to("direct:hello").endPath()
- .get("/bye").accept("application/json").routeId("bye").to("direct:bye").endPath()
+ .path("/say/hello")
+ .get().to("direct:hello")
+ .path("/say/bye")
+ .get().accept("application/json").to("direct:bye")
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
index 3e5facc..b9b87e5 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
@@ -59,7 +59,6 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
log.info(xml2);
// and we should have rest in the routes that indicate its from a rest dsl
assertTrue(xml2.contains("rest=\"true\""));
-
}
@Override
@@ -68,9 +67,10 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
@Override
public void configure() throws Exception {
rest()
- .path("/say")
- .get("/hello").to("direct:hello")
- .get("/bye").to("direct:bye")
+ .path("/say/hello")
+ .get().to("direct:hello")
+ .path("/say/bye")
+ .get().accept("application/json").to("direct:bye")
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
index dc8ec0a..7015e15 100644
--- a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
+++ b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
@@ -69,13 +69,14 @@ public class BlueprintJaxbRestTest extends TestSupport {
CamelContextFactoryBean cfb = (CamelContextFactoryBean) object;
assertEquals(1, cfb.getRests().size());
- assertEquals(1, cfb.getRests().get(0).getPaths().size());
- assertEquals("/say", cfb.getRests().get(0).getPaths().get(0).getUri());
- assertEquals(3, cfb.getRests().get(0).getPaths().get(0).getVerbs().size());
+ assertEquals(2, cfb.getRests().get(0).getPaths().size());
+ assertEquals("/say/hello", cfb.getRests().get(0).getPaths().get(0).getUri());
+ assertEquals("/say/bye", cfb.getRests().get(0).getPaths().get(1).getUri());
+
+ assertEquals(1, cfb.getRests().get(0).getPaths().get(0).getVerbs().size());
+ assertEquals(2, cfb.getRests().get(0).getPaths().get(1).getVerbs().size());
assertEquals("get", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(0).getMethod());
- assertEquals("/hello", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(0).getUri());
- assertEquals("get", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(1).getMethod());
- assertEquals("/bye", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(1).getUri());
- assertEquals("post", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(2).getMethod());
+ assertEquals("get", cfb.getRests().get(0).getPaths().get(1).getVerbs().get(0).getMethod());
+ assertEquals("post", cfb.getRests().get(0).getPaths().get(1).getVerbs().get(1).getMethod());
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/components/camel-blueprint/src/test/resources/test-rest.xml
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/resources/test-rest.xml b/components/camel-blueprint/src/test/resources/test-rest.xml
index 5facf8b..194eb4d 100644
--- a/components/camel-blueprint/src/test/resources/test-rest.xml
+++ b/components/camel-blueprint/src/test/resources/test-rest.xml
@@ -21,11 +21,13 @@
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<rest component="dummy-rest">
- <path uri="/say">
- <get uri="/hello">
+ <path uri="/say/hello">
+ <get>
<to uri="direct:hello"/>
</get>
- <get uri="/bye">
+ </path>
+ <path uri="/say/bye">
+ <get>
<to uri="direct:bye"/>
</get>
<post>
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
index c9b6169..2605928 100644
--- a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
@@ -49,10 +49,9 @@ public class RestCamelSparkTest extends BaseSparkTest {
public void configure() throws Exception {
// will automatic find the spark component to use, as we setup that component in the BaseSparkTest
rest()
- .path("/spark")
- .get("/hello").to("direct:hello")
- .get("/bye").to("direct:bye")
- .post().to("mock:update");
+ .path("/spark/hello").to("direct:hello")
+ .path("/spark/bye").get().to("direct:bye")
+ .path("/spark/bye").post().to("mock:update");
from("direct:hello")
.transform().constant("Hello World");
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
index bd78d08..c91bb70 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetEmbeddedRouteTest.xml
@@ -28,14 +28,16 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<rest component="dummy-rest">
- <path uri="/say">
- <get uri="/hello" routeId="hello">
+ <path uri="/say/hello">
+ <get>
<to uri="mock:hello"/>
<transform>
<constant>Hello World</constant>
</transform>
</get>
- <get uri="/bye" accept="application/json" routeId="bye">
+ </path>
+ <path uri="/say/bye">
+ <get accept="application/json">
<to uri="mock:bye"/>
<transform>
<constant>Bye World</constant>
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
index 9bbd736..128483b 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
@@ -28,11 +28,13 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
<rest component="dummy-rest">
- <path uri="/say">
- <get uri="/hello" routeId="hello">
+ <path uri="/say/hello">
+ <get>
<to uri="direct:hello"/>
</get>
- <get uri="/bye" accept="application/json" routeId="bye">
+ </path>
+ <path uri="/say/bye">
+ <get accept="application/json">
<to uri="direct:bye"/>
</get>
<post>
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
index 3671dfc..ab5aafc 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -40,27 +40,19 @@ public class FromRestGetEmbeddedRouteTest extends CamelBlueprintTestSupport {
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
- // we should have a hello and bye route
- assertNotNull(context.getRouteDefinition("hello"));
- assertNotNull(context.getRouteDefinition("bye"));
-
+ assertEquals(2, rest.getPaths().size());
PathDefinition path = rest.getPaths().get(0);
- assertNotNull(0);
- assertEquals("/say", path.getUri());
-
- assertEquals("/hello", path.getVerbs().get(0).getUri());
+ assertEquals("/say/hello", path.getUri());
ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
assertEquals("mock:hello", to.getUri());
- assertEquals("/bye", path.getVerbs().get(1).getUri());
+ path = rest.getPaths().get(1);
+ assertEquals("/say/bye", path.getUri());
assertEquals("application/json", path.getVerbs().get(1).getAccept());
to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
assertEquals("mock:bye", to.getUri());
- assertEquals(null, path.getVerbs().get(2).getUri());
-
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
-
getMockEndpoint("mock:update").expectedMessageCount(1);
template.sendBody("seda:post-say", "I was here");
assertMockEndpointsSatisfied();
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
index 71b0a6f..2aa7f2f 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
@@ -29,30 +29,38 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
return "org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml";
}
- @Test
- public void testFromRestModel() {
- assertEquals(2 + 3, context.getRoutes().size());
+ protected int getExpectedNumberOfRoutes() {
+ return 2 + 3;
+ }
- // we should have a hello and bye route
- assertNotNull(context.getRouteDefinition("hello"));
- assertNotNull(context.getRouteDefinition("bye"));
+ @Test
+ public void testFromRestModel() throws Exception {
+ assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
+ assertEquals(2, rest.getPaths().size());
PathDefinition path = rest.getPaths().get(0);
- assertNotNull(0);
- assertEquals("/say", path.getUri());
-
- assertEquals("/hello", path.getVerbs().get(0).getUri());
+ assertEquals("/say/hello", path.getUri());
ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
- assertEquals("direct:hello", to.getUri());
+ assertEquals("mock:hello", to.getUri());
- assertEquals("/bye", path.getVerbs().get(1).getUri());
+ path = rest.getPaths().get(1);
+ assertEquals("/say/bye", path.getUri());
+ assertEquals("application/json", path.getVerbs().get(1).getAccept());
to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
- assertEquals("direct:bye", to.getUri());
+ assertEquals("mock:bye", to.getUri());
+
+ // the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
+ getMockEndpoint("mock:update").expectedMessageCount(1);
+ template.sendBody("seda:post-say", "I was here");
+ assertMockEndpointsSatisfied();
- assertEquals(null, path.getVerbs().get(2).getUri());
+ String out = template.requestBody("seda:get-say-hello", "Me", String.class);
+ assertEquals("Hello World", out);
+ String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
+ assertEquals("Bye World", out2);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
index cf415fb..b8a5c2a 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.xml
@@ -26,14 +26,16 @@
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<rest component="dummy-rest">
- <path uri="/say">
- <get uri="/hello" routeId="hello">
+ <path uri="/say/hello">
+ <get>
<to uri="mock:hello"/>
<transform>
<constant>Hello World</constant>
</transform>
</get>
- <get uri="/bye" accept="application/json" routeId="bye">
+ </path>
+ <path uri="/say/bye">
+ <get accept="application/json">
<to uri="mock:bye"/>
<transform>
<constant>Bye World</constant>
http://git-wip-us.apache.org/repos/asf/camel/blob/f73a592f/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
index 55db1fd..f3876a2 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
@@ -26,11 +26,13 @@
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
<rest component="dummy-rest">
- <path uri="/say">
- <get uri="/hello" routeId="hello">
+ <path uri="/say/hello">
+ <get>
<to uri="direct:hello"/>
</get>
- <get uri="/bye" accept="application/json" routeId="bye">
+ </path>
+ <path uri="/say/bye">
+ <get accept="application/json">
<to uri="direct:bye"/>
</get>
<post>
[17/33] git commit: CAMEL-7354: integrated camel-spark-rest with new
rest component.
Posted by da...@apache.org.
CAMEL-7354: integrated camel-spark-rest with new rest component.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3862067b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3862067b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3862067b
Branch: refs/heads/master
Commit: 3862067b38a4b99f99ca142b66d51ff686d1bfa9
Parents: c29cf0c
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 15 12:11:12 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:50 2014 +0200
----------------------------------------------------------------------
.../camel/component/rest/RestEndpoint.java | 2 +-
.../apache/camel/model/rest/PathDefinition.java | 9 +++
.../apache/camel/model/rest/RestDefinition.java | 27 ++++----
.../camel/model/rest/RestsDefinition.java | 1 -
.../apache/camel/model/rest/VerbDefinition.java | 11 ++++
.../camel/component/rest/FromRestGetTest.java | 8 ++-
.../src/test/resources/test-rest.xml | 2 +-
.../component/sparkrest/SparkComponent.java | 21 ++++++-
.../sparkrest/RestCamelSparkComponentTest.java | 43 +++++++++++++
.../component/sparkrest/RestCamelSparkTest.java | 65 ++++++++++++++++++++
.../component/rest/SpringFromRestGetTest.xml | 10 +--
.../component/rest/FromRestGetTest.java | 4 ++
.../component/rest/FromRestGetTest.xml | 10 +--
13 files changed, 186 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
index bb55349..e5a04ad 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -104,7 +104,7 @@ public class RestEndpoint extends DefaultEndpoint {
Component comp = getCamelContext().getComponent(getComponentName());
if (comp != null && comp instanceof RestConsumerFactory) {
factory = (RestConsumerFactory) comp;
- } else {
+ } else if (comp != null) {
throw new IllegalArgumentException("Component " + getComponentName() + " is not a RestConsumerFactory");
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
index d646916..2c29b2f 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -54,6 +54,15 @@ public class PathDefinition {
// Fluent API
//-------------------------------------------------------------------------
+ public PathDefinition routeId(String routeId) {
+ // set on last verb
+ if (verbs != null && !verbs.isEmpty()) {
+ VerbDefinition last = verbs.get(verbs.size() - 1);
+ last.setRouteId(routeId);
+ }
+ return this;
+ }
+
public PathDefinition get() {
return get(null);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/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 c3ec144..93180ad 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
@@ -35,7 +35,6 @@ import org.apache.camel.model.RouteDefinition;
public class RestDefinition {
private String component;
- private String routeId;
private List<PathDefinition> paths = new ArrayList<PathDefinition>();
public String getComponent() {
@@ -47,15 +46,6 @@ public class RestDefinition {
this.component = component;
}
- public String getRouteId() {
- return routeId;
- }
-
- @XmlAttribute
- public void setRouteId(String routeId) {
- this.routeId = routeId;
- }
-
public List<PathDefinition> getPaths() {
return paths;
}
@@ -68,6 +58,17 @@ public class RestDefinition {
// Fluent API
//-------------------------------------------------------------------------
+ /**
+ * To use a specific Camel rest component
+ */
+ public RestDefinition component(String componentId) {
+ setComponent(componentId);
+ return this;
+ }
+
+ /**
+ * Defines the rest path to use
+ */
public PathDefinition path(String uri) {
PathDefinition answer = new PathDefinition();
getPaths().add(answer);
@@ -86,9 +87,13 @@ public class RestDefinition {
for (PathDefinition path : getPaths()) {
String uri = path.getUri();
for (VerbDefinition verb : path.getVerbs()) {
- String from = "rest:" + verb.getMethod() + ":" + uri + (verb.getUri() != null ? verb.getUri() : "");
+ String from = "rest:" + verb.getMethod() + ":" + uri + (verb.getUri() != null ? verb.getUri() : "")
+ + (getComponent() != null ? "?componentName=" + getComponent() : "");
RouteDefinition route = new RouteDefinition();
route.fromRest(from);
+ if (verb.getRouteId() != null) {
+ route.setId(verb.getRouteId());
+ }
answer.add(route);
route.getOutputs().addAll(verb.getOutputs());
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
index 11aad02..2a0ff25 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestsDefinition.java
@@ -80,7 +80,6 @@ public class RestsDefinition extends OptionalIdentifiedDefinition<RestsDefinitio
public RestDefinition rest() {
RestDefinition rest = createRest();
return rest(rest);
-
}
public RestDefinition rest(RestDefinition rest) {
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/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 5ef289e..c486045 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
@@ -31,6 +31,9 @@ import org.apache.camel.model.ProcessorDefinition;
public class VerbDefinition {
@XmlAttribute
+ private String routeId;
+
+ @XmlAttribute
private String method;
@XmlAttribute
@@ -39,6 +42,14 @@ public class VerbDefinition {
@XmlElementRef
private List<ProcessorDefinition<?>> outputs = new ArrayList<ProcessorDefinition<?>>();
+ public String getRouteId() {
+ return routeId;
+ }
+
+ public void setRouteId(String routeId) {
+ this.routeId = routeId;
+ }
+
public String getMethod() {
return method;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index eb284fc..bc16772 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -38,6 +38,10 @@ public class FromRestGetTest extends ContextTestSupport {
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
+ // we should have a hello and bye route
+ assertNotNull(context.getRouteDefinition("hello"));
+ assertNotNull(context.getRouteDefinition("bye"));
+
PathDefinition path = rest.getPaths().get(0);
assertNotNull(0);
assertEquals("/say", path.getUri());
@@ -71,8 +75,8 @@ public class FromRestGetTest extends ContextTestSupport {
public void configure() throws Exception {
rest()
.path("/say")
- .get("/hello").to("direct:hello")
- .get("/bye").to("direct:bye")
+ .get("/hello").routeId("hello").to("direct:hello")
+ .get("/bye").routeId("bye").to("direct:bye")
.post().to("mock:update");
from("direct:hello")
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/components/camel-blueprint/src/test/resources/test-rest.xml
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/resources/test-rest.xml b/components/camel-blueprint/src/test/resources/test-rest.xml
index f6958b7..5facf8b 100644
--- a/components/camel-blueprint/src/test/resources/test-rest.xml
+++ b/components/camel-blueprint/src/test/resources/test-rest.xml
@@ -20,7 +20,7 @@
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
- <rest component="dummy-rest" routeId="myRestRoute">
+ <rest component="dummy-rest">
<path uri="/say">
<get uri="/hello">
<to uri="direct:hello"/>
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
index 2cf1548..38f1566 100644
--- a/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
+++ b/components/camel-spark-rest/src/main/java/org/apache/camel/component/sparkrest/SparkComponent.java
@@ -18,13 +18,17 @@ package org.apache.camel.component.sparkrest;
import java.util.Map;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.spi.RestConsumerFactory;
import org.apache.camel.util.ObjectHelper;
import spark.Spark;
import spark.SparkBase;
-public class SparkComponent extends UriEndpointComponent {
+public class SparkComponent extends UriEndpointComponent implements RestConsumerFactory {
private int port = SparkBase.SPARK_DEFAULT_PORT;
private SparkConfiguration sparkConfiguration = new SparkConfiguration();
@@ -92,4 +96,19 @@ public class SparkComponent extends UriEndpointComponent {
super.doShutdown();
Spark.stop();
}
+
+ @Override
+ public Consumer createConsumer(CamelContext camelContext, Processor processor,
+ String verb, String path, String accept, Map<String, Object> parameters) throws Exception {
+ // get the endpoint
+ SparkEndpoint endpoint;
+ if (accept != null) {
+ endpoint = camelContext.getEndpoint("spark-rest:" + verb + ":" + path + "?accept=" + accept, SparkEndpoint.class);
+ } else {
+ endpoint = camelContext.getEndpoint("spark-rest:" + verb + ":" + path, SparkEndpoint.class);
+ }
+ setProperties(endpoint, parameters);
+
+ return endpoint.createConsumer(processor);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
new file mode 100644
index 0000000..244e17e
--- /dev/null
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkComponentTest.java
@@ -0,0 +1,43 @@
+/**
+ * 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.sparkrest;
+
+import org.apache.camel.builder.RouteBuilder;
+
+public class RestCamelSparkComponentTest extends RestCamelSparkTest {
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // explicit configure that we want to use spark-rest component
+ rest().component("spark-rest")
+ .path("/spark")
+ .get("/hello").to("direct:hello")
+ .get("/bye").to("direct:bye")
+ .post().to("mock:update");
+
+ from("direct:hello")
+ .transform().constant("Hello World");
+
+ from("direct:bye")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
new file mode 100644
index 0000000..c9b6169
--- /dev/null
+++ b/components/camel-spark-rest/src/test/java/org/apache/camel/component/sparkrest/RestCamelSparkTest.java
@@ -0,0 +1,65 @@
+/**
+ * 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.sparkrest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+public class RestCamelSparkTest extends BaseSparkTest {
+
+ @Test
+ public void testSparkHello() throws Exception {
+ String out = template.requestBody("http://0.0.0.0:" + getPort() + "/spark/hello", null, String.class);
+ assertEquals("Hello World", out);
+ }
+
+ @Test
+ public void testSparkBye() throws Exception {
+ String out = template.requestBody("http://0.0.0.0:" + getPort() + "/spark/bye", null, String.class);
+ assertEquals("Bye World", out);
+ }
+
+ @Test
+ public void testSparkPost() throws Exception {
+ getMockEndpoint("mock:update").expectedBodiesReceived("I did this");
+
+ template.requestBody("http://0.0.0.0:" + getPort() + "/spark", "I did this", String.class);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // will automatic find the spark component to use, as we setup that component in the BaseSparkTest
+ rest()
+ .path("/spark")
+ .get("/hello").to("direct:hello")
+ .get("/bye").to("direct:bye")
+ .post().to("mock:update");
+
+ from("direct:hello")
+ .transform().constant("Hello World");
+
+ from("direct:bye")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
index 0b13013..f33e99d 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/SpringFromRestGetTest.xml
@@ -27,12 +27,12 @@
<camelContext xmlns="http://camel.apache.org/schema/spring">
- <rest component="dummy-rest" routeId="myRestRoute">
+ <rest component="dummy-rest">
<path uri="/say">
- <get uri="/hello">
+ <get uri="/hello" routeId="hello">
<to uri="direct:hello"/>
</get>
- <get uri="/bye">
+ <get uri="/bye" routeId="bye">
<to uri="direct:bye"/>
</get>
<post>
@@ -41,13 +41,13 @@
</path>
</rest>
- <route id="helloRoute">
+ <route>
<from uri="direct:hello"/>
<transform>
<constant>Hello World</constant>
</transform>
</route>
- <route id="byeRoute">
+ <route>
<from uri="direct:bye"/>
<transform>
<constant>Bye World</constant>
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
index ce24d4d..71b0a6f 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
@@ -33,6 +33,10 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
public void testFromRestModel() {
assertEquals(2 + 3, context.getRoutes().size());
+ // we should have a hello and bye route
+ assertNotNull(context.getRouteDefinition("hello"));
+ assertNotNull(context.getRouteDefinition("bye"));
+
RestDefinition rest = context.getRestDefinitions().get(0);
assertNotNull(rest);
http://git-wip-us.apache.org/repos/asf/camel/blob/3862067b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
index d094a0c..0ee3624 100644
--- a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
+++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.xml
@@ -25,12 +25,12 @@
<camelContext xmlns="http://camel.apache.org/schema/blueprint">
- <rest component="dummy-rest" routeId="myRestRoute">
+ <rest component="dummy-rest">
<path uri="/say">
- <get uri="/hello">
+ <get uri="/hello" routeId="hello">
<to uri="direct:hello"/>
</get>
- <get uri="/bye">
+ <get uri="/bye" routeId="bye">
<to uri="direct:bye"/>
</get>
<post>
@@ -39,13 +39,13 @@
</path>
</rest>
- <route id="helloRoute">
+ <route>
<from uri="direct:hello"/>
<transform>
<constant>Hello World</constant>
</transform>
</route>
- <route id="byeRoute">
+ <route>
<from uri="direct:bye"/>
<transform>
<constant>Bye World</constant>
[12/33] git commit: CAMEL-7354: Add jmx about rest
Posted by da...@apache.org.
CAMEL-7354: Add jmx about rest
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2ffb9a5a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2ffb9a5a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2ffb9a5a
Branch: refs/heads/master
Commit: 2ffb9a5a43fc69fb0344ca524f465e643d337a44
Parents: 2e4e7f8
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 2 18:01:42 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:49 2014 +0200
----------------------------------------------------------------------
.../mbean/ManagedCamelContextMBean.java | 3 +
.../org/apache/camel/builder/RouteBuilder.java | 2 +-
.../management/mbean/ManagedCamelContext.java | 14 ++++
.../org/apache/camel/model/RouteDefinition.java | 14 ++++
.../apache/camel/model/rest/RestDefinition.java | 3 +-
.../management/ManagedFromRestGetTest.java | 88 ++++++++++++++++++++
6 files changed, 122 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
index 583ad01..700ae22 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
@@ -164,6 +164,9 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean
@ManagedOperation(description = "Request body and headers (in out)")
Object requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers) throws Exception;
+ @ManagedOperation(description = "Dumps the rests as XML")
+ String dumpRestsAsXml() throws Exception;
+
@ManagedOperation(description = "Dumps the routes as XML")
String dumpRoutesAsXml() throws Exception;
http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index 9e4e334..3659a84 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -408,7 +408,7 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
}
protected void configureRoute(RouteDefinition route) {
- route.setGroup(getClass().getName());
+ // noop
}
/**
http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index e26c8aa..a641b68 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -47,6 +47,8 @@ import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.ModelHelper;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+import org.apache.camel.model.rest.RestsDefinition;
/**
* @version
@@ -298,6 +300,18 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
return answer;
}
+ public String dumpRestsAsXml() throws Exception {
+ List<RestDefinition> rests = context.getRestDefinitions();
+ if (rests.isEmpty()) {
+ return null;
+ }
+
+ // use a routes definition to dump the rests
+ RestsDefinition def = new RestsDefinition();
+ def.setRests(rests);
+ return ModelHelper.dumpModelAsXml(def);
+ }
+
public String dumpRoutesAsXml() throws Exception {
List<RouteDefinition> routes = context.getRouteDefinitions();
if (routes.isEmpty()) {
http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
index 05a5b5f..7f12ccf 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -80,6 +80,7 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
// keep state whether the error handler is context scoped or not
// (will by default be context scoped of no explicit error handler configured)
private boolean contextScopedErrorHandler = true;
+ private Boolean rest;
public RouteDefinition() {
}
@@ -93,6 +94,14 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
}
/**
+ * This route is created from the REST DSL.
+ */
+ public void fromRest(String uri) {
+ from(uri);
+ rest = true;
+ }
+
+ /**
* Prepares the route definition to be ready to be added to {@link CamelContext}
*
* @param context the camel context
@@ -765,6 +774,11 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
this.errorHandlerBuilder = errorHandlerBuilder;
}
+ @XmlAttribute
+ public Boolean isRest() {
+ return rest;
+ }
+
@SuppressWarnings("deprecation")
public boolean isContextScopedErrorHandler(CamelContext context) {
if (!contextScopedErrorHandler) {
http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/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 56cc843..d63badc 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
@@ -87,7 +87,8 @@ public class RestDefinition {
String uri = path.getUri();
for (VerbDefinition verb : path.getVerbs()) {
String from = "rest-binding:" + verb.getMethod() + ":" + uri + (verb.getUri() != null ? verb.getUri() : "");
- RouteDefinition route = new RouteDefinition(from);
+ RouteDefinition route = new RouteDefinition();
+ route.fromRest(from);
answer.add(route);
route.getOutputs().add(verb.getTo());
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2ffb9a5a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
new file mode 100644
index 0000000..f70d372
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
@@ -0,0 +1,88 @@
+/**
+ * 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.management;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.restbinding.DummyRestBindingCapableComponent;
+import org.apache.camel.model.rest.PathDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+
+public class ManagedFromRestGetTest extends ManagementTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ // register our dummy rest capable component
+ context.addComponent("dummy-rest", new DummyRestBindingCapableComponent());
+
+ return context;
+ }
+
+ public void testFromRestModel() throws Exception {
+ // JMX tests dont work well on AIX CI servers (hangs them)
+ if (isPlatform("aix")) {
+ return;
+ }
+
+ MBeanServer mbeanServer = getMBeanServer();
+
+ ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\"");
+
+ String xml = (String) mbeanServer.invoke(on, "dumpRestsAsXml", null, null);
+ assertNotNull(xml);
+ log.info(xml);
+
+ assertTrue(xml.contains("rests"));
+ assertTrue(xml.contains("rest"));
+ assertTrue(xml.contains("<path uri=\"/say\">"));
+ assertTrue(xml.contains("<get method=\"get\" uri=\"/hello\">"));
+ assertTrue(xml.contains("<get method=\"get\" uri=\"/bye\">"));
+ assertTrue(xml.contains("<post method=\"post\">"));
+
+ String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
+ log.info(xml2);
+ // and we should have rest in the routes that indicate its from a rest dsl
+ assertTrue(xml2.contains("rest=\"true\""));
+
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ rest()
+ .path("/say")
+ .get("/hello").to("direct:hello")
+ .get("/bye").to("direct:bye")
+ .post().to("seda:update");
+
+ from("direct:hello")
+ .transform().constant("Hello World");
+
+ from("direct:bye")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+}
[33/33] git commit: camel-spring-javaconfig must test with spring 3
due api breakings in spring.
Posted by da...@apache.org.
camel-spring-javaconfig must test with spring 3 due api breakings in spring.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b08ff977
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b08ff977
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b08ff977
Branch: refs/heads/master
Commit: b08ff977aef01ce4b665a6a78da370772bac79da
Parents: ea23613
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Jul 19 13:16:27 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 13:16:27 2014 +0200
----------------------------------------------------------------------
components/camel-spring-javaconfig/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/b08ff977/components/camel-spring-javaconfig/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring-javaconfig/pom.xml b/components/camel-spring-javaconfig/pom.xml
index 038d97f..61aa8b0 100644
--- a/components/camel-spring-javaconfig/pom.xml
+++ b/components/camel-spring-javaconfig/pom.xml
@@ -66,7 +66,7 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
- <artifactId>camel-test-spring</artifactId>
+ <artifactId>camel-test-spring3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
[08/33] git commit: CAMEL-7354: Migrating rest DSL to be separated
from regular Camel routes.
Posted by da...@apache.org.
CAMEL-7354: Migrating rest DSL to be separated from regular Camel routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3c2bff28
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3c2bff28
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3c2bff28
Branch: refs/heads/master
Commit: 3c2bff286d8d4179ff2defa460cb03e7fb22e4a1
Parents: a9856bb
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 2 12:49:45 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:48 2014 +0200
----------------------------------------------------------------------
.../java/org/apache/camel/CamelContext.java | 19 ++++++++++++
.../org/apache/camel/builder/RouteBuilder.java | 27 +++++++++++++++++
.../apache/camel/impl/DefaultCamelContext.java | 14 +++++++++
.../apache/camel/model/ModelCamelContext.java | 16 ++++++++++
.../apache/camel/model/rest/PathDefinition.java | 10 +++----
.../apache/camel/model/rest/RestDefinition.java | 4 +--
.../apache/camel/model/rest/VerbDefinition.java | 7 ++++-
.../component/restbinding/FromRestGetTest.java | 31 ++++++++++----------
8 files changed, 104 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3c2bff28/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 8e32849..d1156fd 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -29,6 +29,7 @@ import org.apache.camel.builder.ErrorHandlerBuilder;
import org.apache.camel.model.DataFormatDefinition;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.spi.CamelContextNameStrategy;
import org.apache.camel.spi.ClassResolver;
import org.apache.camel.spi.DataFormat;
@@ -387,6 +388,24 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
RouteDefinition getRouteDefinition(String id);
/**
+ * Returns a list of the current REST definitions
+ *
+ * @return list of the current REST definitions
+ * @deprecated use {@link org.apache.camel.model.ModelCamelContext#getRestDefinitions()}
+ */
+ @Deprecated
+ List<RestDefinition> getRestDefinitions();
+
+ /**
+ * Adds a collection of rest definitions to the context
+ *
+ * @param restDefinitions the rest(s) definition to add
+ * @throws Exception if the rest definitions could not be created for whatever reason
+ */
+ @Deprecated
+ void addRestDefinitions(Collection<RestDefinition> restDefinitions) throws Exception;
+
+ /**
* Returns the order in which the route inputs was started.
* <p/>
* The order may not be according to the startupOrder defined on the route.
http://git-wip-us.apache.org/repos/asf/camel/blob/3c2bff28/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index db96fea..8864da7 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -277,6 +277,11 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
configureRoutes((ModelCamelContext)context);
// add routes to Camel by populating them
populateRoutes();
+
+ // after routes then configure and populate rests
+ configureRests((ModelCamelContext) context);
+ // add rests to Camel by populating them
+ populateRests();
}
/**
@@ -294,6 +299,19 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
}
/**
+ * Configures the rests
+ *
+ * @param context the Camel context
+ * @return the rests configured
+ * @throws Exception can be thrown during configuration
+ */
+ public RestsDefinition configureRests(ModelCamelContext context) throws Exception {
+ setContext(context);
+ restCollection.setCamelContext(context);
+ return restCollection;
+ }
+
+ /**
* Includes the routes from the build to this builder.
* <p/>
* This allows you to use other builds as route templates.
@@ -352,6 +370,15 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
camelContext.addRouteDefinitions(getRouteCollection().getRoutes());
}
+ protected void populateRests() throws Exception {
+ ModelCamelContext camelContext = getContext();
+ if (camelContext == null) {
+ throw new IllegalArgumentException("CamelContext has not been injected!");
+ }
+ getRestCollection().setCamelContext(camelContext);
+ camelContext.addRestDefinitions(getRestCollection().getRests());
+ }
+
public RestsDefinition getRestCollection() {
return restCollection;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c2bff28/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index dc34791..846f647 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -82,6 +82,7 @@ import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RouteDefinitionHelper;
import org.apache.camel.model.RoutesDefinition;
+import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.processor.interceptor.BacklogDebugger;
import org.apache.camel.processor.interceptor.BacklogTracer;
import org.apache.camel.processor.interceptor.Debug;
@@ -171,6 +172,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
private ManagementStrategy managementStrategy;
private ManagementMBeanAssembler managementMBeanAssembler;
private final List<RouteDefinition> routeDefinitions = new ArrayList<RouteDefinition>();
+ private final List<RestDefinition> restDefinitions = new ArrayList<RestDefinition>();
private List<InterceptStrategy> interceptStrategies = new ArrayList<InterceptStrategy>();
// special flags to control the first startup which can are special
@@ -1407,6 +1409,18 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
return null;
}
+ public synchronized List<RestDefinition> getRestDefinitions() {
+ return restDefinitions;
+ }
+
+ public void addRestDefinitions(Collection<RestDefinition> restDefinitions) throws Exception {
+ this.restDefinitions.addAll(restDefinitions);
+ // TODO: should we support not starting rest?
+ //if (shouldStartRoutes()) {
+ // startRouteDefinitions(routeDefinitions);
+ //}
+ }
+
public List<InterceptStrategy> getInterceptStrategies() {
return interceptStrategies;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c2bff28/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java b/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
index b85fc93..912aa62 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ModelCamelContext.java
@@ -22,6 +22,7 @@ import java.util.List;
import java.util.Map;
import org.apache.camel.CamelContext;
+import org.apache.camel.model.rest.RestDefinition;
/**
* Model level interface for the {@link CamelContext}
@@ -95,6 +96,21 @@ public interface ModelCamelContext extends CamelContext {
void removeRouteDefinition(RouteDefinition routeDefinition) throws Exception;
/**
+ * Returns a list of the current REST definitions
+ *
+ * @return list of the current REST definitions
+ */
+ List<RestDefinition> getRestDefinitions();
+
+ /**
+ * Adds a collection of rest definitions to the context
+ *
+ * @param restDefinitions the rest(s) definition to add
+ * @throws Exception if the rest definitions could not be created for whatever reason
+ */
+ void addRestDefinitions(Collection<RestDefinition> restDefinitions) throws Exception;
+
+ /**
* Starts the given route if it has been previously stopped
*
* @param route the route to start
http://git-wip-us.apache.org/repos/asf/camel/blob/3c2bff28/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
index 39741cb..2eb7b4a 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -31,17 +31,17 @@ import org.apache.camel.model.ToDefinition;
public class PathDefinition {
@XmlAttribute
- private String url;
+ private String uri;
@XmlElementRef
private List<VerbDefinition> verbs = new ArrayList<VerbDefinition>();
- public String getUrl() {
- return url;
+ public String getUri() {
+ return uri;
}
- public void setUrl(String url) {
- this.url = url;
+ public void setUri(String uri) {
+ this.uri = uri;
}
public List<VerbDefinition> getVerbs() {
http://git-wip-us.apache.org/repos/asf/camel/blob/3c2bff28/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 3cbb67a..4b4826d 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
@@ -65,10 +65,10 @@ public class RestDefinition {
// Fluent API
//-------------------------------------------------------------------------
- public PathDefinition path(String url) {
+ public PathDefinition path(String uri) {
PathDefinition answer = new PathDefinition();
getPaths().add(answer);
- answer.setUrl(url);
+ answer.setUri(uri);
return answer;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c2bff28/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 b0f5050..c0721bb 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
@@ -20,11 +20,15 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlRootElement;
import org.apache.camel.model.ToDefinition;
+@XmlRootElement(name = "verb")
@XmlAccessorType(XmlAccessType.FIELD)
-public abstract class VerbDefinition {
+public class VerbDefinition {
+
+ // TODO: we would ideally want this to be abstract and not in the XML DSL
@XmlAttribute
private String uri;
@@ -47,4 +51,5 @@ public abstract class VerbDefinition {
public void setTo(ToDefinition to) {
this.to = to;
}
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3c2bff28/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
index b9baeb8..211f768 100644
--- a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
@@ -19,7 +19,8 @@ package org.apache.camel.component.restbinding;
import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.rest.PathDefinition;
+import org.apache.camel.model.rest.RestDefinition;
public class FromRestGetTest extends ContextTestSupport {
@@ -33,26 +34,24 @@ public class FromRestGetTest extends ContextTestSupport {
return context;
}
-/* public void testFromRestModel() {
- assertEquals(1, context.getRoutes().size());
+ public void testFromRestModel() {
+ assertEquals(2, context.getRoutes().size());
- RouteDefinition route = context.getRouteDefinition("foo");
- assertNotNull(route);
+ RestDefinition rest = context.getRestDefinitions().get(0);
+ assertNotNull(rest);
- FromRestDefinition from = (FromRestDefinition) route.getInputs().get(0);
- assertNotNull(from);
- assertEquals("get", from.getVerb());
- assertEquals("/hello", from.getPath());
- assertNull(from.getAccept());
- }
+ PathDefinition path = rest.getPaths().get(0);
+ assertNotNull(0);
+ assertEquals("/say", path.getUri());
- public void testFromRest() throws Exception {
- getMockEndpoint("mock:foo").expectedMessageCount(1);
+ assertEquals("/hello", path.getVerbs().get(0).getUri());
+ assertEquals("direct:hello", path.getVerbs().get(0).getTo().getUri());
- template.sendBody("seda:get-hello", "Hello World");
+ assertEquals("/bye", path.getVerbs().get(1).getUri());
+ assertEquals("direct:bye", path.getVerbs().get(1).getTo().getUri());
- assertMockEndpointsSatisfied();
- }*/
+ assertEquals(null, path.getVerbs().get(2).getUri());
+ }
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
[05/33] git commit: CAMEL-7354: rest-binding in camel-core
Posted by da...@apache.org.
CAMEL-7354: rest-binding in camel-core
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2f19857a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2f19857a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2f19857a
Branch: refs/heads/master
Commit: 2f19857a392df2735ec49d442390fa26956b844b
Parents: 08d68bc
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 1 14:07:20 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:47 2014 +0200
----------------------------------------------------------------------
.../org/apache/camel/builder/RouteBuilder.java | 10 +++
.../restbinding/RestBindingComponent.java | 23 +++++
.../restbinding/RestBindingConsumer.java | 29 ------
.../restbinding/RestBindingEndpoint.java | 38 ++++++--
.../apache/camel/model/FromRestDefinition.java | 93 ++++++++++++++++++++
.../org/apache/camel/model/RouteDefinition.java | 10 +++
.../apache/camel/model/RoutesDefinition.java | 11 +++
.../apache/camel/spi/RestBindingCapable.java | 37 ++++++++
.../org/apache/camel/component/rest-binding | 18 ++++
.../resources/org/apache/camel/model/jaxb.index | 1 +
.../DummyRestBindingCapableComponent.java | 47 ++++++++++
.../component/restbinding/FromRestGetTest.java | 70 +++++++++++++++
.../issues/AdviceWithTransactionIssueTest.xml | 8 +-
13 files changed, 356 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
index e17dace..4392d1b 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/RouteBuilder.java
@@ -69,6 +69,16 @@ public abstract class RouteBuilder extends BuilderSupport implements RoutesBuild
public abstract void configure() throws Exception;
/**
+ * Creates a new REST route
+ */
+ public RouteDefinition fromRest(String verb, String path) {
+ getRouteCollection().setCamelContext(getContext());
+ RouteDefinition answer = getRouteCollection().fromRest(verb, path);
+ configureRoute(answer);
+ return answer;
+ }
+
+ /**
* Creates a new route from the given URI input
*
* @param uri the from uri
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
index 62a5f84..d24b72e 100644
--- a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingComponent.java
@@ -18,8 +18,10 @@ package org.apache.camel.component.restbinding;
import java.util.Map;
+import org.apache.camel.Component;
import org.apache.camel.Endpoint;
import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.spi.RestBindingCapable;
import org.apache.camel.util.ObjectHelper;
public class RestBindingComponent extends UriEndpointComponent {
@@ -30,8 +32,11 @@ public class RestBindingComponent extends UriEndpointComponent {
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ preCheckConditions();
+
RestBindingEndpoint answer = new RestBindingEndpoint(uri, this);
setProperties(answer, parameters);
+ answer.setParameters(parameters);
if (!remaining.contains(":")) {
throw new IllegalArgumentException("Invalid syntax. Must be rest-binding:verb:path");
@@ -45,4 +50,22 @@ public class RestBindingComponent extends UriEndpointComponent {
return answer;
}
+
+
+ protected void preCheckConditions() throws Exception {
+ if (lookupRestBindingCapableComponent() == null) {
+ throw new IllegalStateException("There are no registered components in CamelContext that is RestBindingCapable");
+ }
+ }
+
+ public RestBindingCapable lookupRestBindingCapableComponent() {
+ for (String id : getCamelContext().getComponentNames()) {
+ Component component = getCamelContext().getComponent(id);
+ if (component instanceof RestBindingCapable) {
+ return (RestBindingCapable) component;
+ }
+ }
+ return null;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingConsumer.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingConsumer.java b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingConsumer.java
deleted file mode 100644
index 4480bf4..0000000
--- a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingConsumer.java
+++ /dev/null
@@ -1,29 +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.restbinding;
-
-import org.apache.camel.Processor;
-import org.apache.camel.impl.DefaultConsumer;
-
-public class RestBindingConsumer extends DefaultConsumer {
-
- public RestBindingConsumer(RestBindingEndpoint endpoint, Processor processor) {
- super(endpoint, processor);
- }
-
- // TODO: lookup which components support rest binding and create an endpoint and create the delegate consumer
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
index df7c62f..da6ce09 100644
--- a/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
+++ b/camel-core/src/main/java/org/apache/camel/component/restbinding/RestBindingEndpoint.java
@@ -16,15 +16,17 @@
*/
package org.apache.camel.component.restbinding;
-import org.apache.camel.Component;
+import java.util.Map;
+
import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.camel.spi.RestBindingCapable;
import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
-@UriEndpoint(scheme = "rest", consumerClass = RestBindingConsumer.class)
+@UriEndpoint(scheme = "rest-binding")
public class RestBindingEndpoint extends DefaultEndpoint {
@UriParam
@@ -34,10 +36,17 @@ public class RestBindingEndpoint extends DefaultEndpoint {
@UriParam
private String accept;
- public RestBindingEndpoint(String endpointUri, Component component) {
+ private Map<String, Object> parameters;
+
+ public RestBindingEndpoint(String endpointUri, RestBindingComponent component) {
super(endpointUri, component);
}
+ @Override
+ public RestBindingComponent getComponent() {
+ return (RestBindingComponent) super.getComponent();
+ }
+
public String getVerb() {
return verb;
}
@@ -62,6 +71,14 @@ public class RestBindingEndpoint extends DefaultEndpoint {
this.accept = accept;
}
+ public Map<String, Object> getParameters() {
+ return parameters;
+ }
+
+ public void setParameters(Map<String, Object> parameters) {
+ this.parameters = parameters;
+ }
+
@Override
public Producer createProducer() throws Exception {
throw new UnsupportedOperationException("Producer not supported");
@@ -69,13 +86,22 @@ public class RestBindingEndpoint extends DefaultEndpoint {
@Override
public Consumer createConsumer(Processor processor) throws Exception {
- Consumer consumer = new RestBindingConsumer(this, processor);
- configureConsumer(consumer);
- return consumer;
+ // create the consumer directly from the component that supports rest binding
+ // TODO: should we have a RestBindingConsumer class that delegates to the actual consumer?
+ // TODO: what if there is 2+ RestBindingCapable components in the registry?
+ RestBindingCapable component = getComponent().lookupRestBindingCapableComponent();
+ if (component != null) {
+ Consumer consumer = component.createConsumer(this, processor);
+ configureConsumer(consumer);
+ return consumer;
+ } else {
+ throw new IllegalStateException("There are no registered components in CamelContext that is RestBindingCapable");
+ }
}
@Override
public boolean isSingleton() {
return true;
}
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/main/java/org/apache/camel/model/FromRestDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/FromRestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/FromRestDefinition.java
new file mode 100644
index 0000000..dca9ce4
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/FromRestDefinition.java
@@ -0,0 +1,93 @@
+/**
+ * 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;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.spi.RouteContext;
+
+@XmlRootElement(name = "fromRest")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class FromRestDefinition extends FromDefinition {
+
+ // TODO: verb should be an enum
+
+ @XmlAttribute
+ private String verb;
+ @XmlAttribute
+ private String path;
+ @XmlAttribute
+ private String accept;
+ @XmlTransient
+ private Endpoint endpoint;
+
+ public FromRestDefinition() {
+ }
+
+ public FromRestDefinition(String verb, String path) {
+ this(verb, path, null);
+ }
+
+ public FromRestDefinition(String verb, String path, String accept) {
+ this.verb = verb;
+ this.path = path;
+ this.accept = accept;
+ }
+
+ public Endpoint resolveEndpoint(RouteContext context) {
+ if (endpoint == null) {
+ if (accept != null) {
+ return context.resolveEndpoint("rest-binding:" + verb + ":" + path + "?accept=" + accept);
+ } else {
+ return context.resolveEndpoint("rest-binding:" + verb + ":" + path);
+ }
+ } else {
+ return endpoint;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "fromRest[" + getLabel() + "]";
+ }
+
+ @Override
+ public String getShortName() {
+ return "fromRest";
+ }
+
+ public String getLabel() {
+ return verb + "(" + "/" + path + ")";
+ }
+
+ public String getVerb() {
+ return verb;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public String getAccept() {
+ return accept;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
index 05a5b5f..3caade6 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
@@ -284,6 +284,16 @@ public class RouteDefinition extends ProcessorDefinition<RouteDefinition> {
// -----------------------------------------------------------------------
/**
+ * Creates an REST input to the route
+ *
+ * @return the builder
+ */
+ public RouteDefinition fromRest(String verb, String path) {
+ getInputs().add(new FromRestDefinition(verb, path));
+ return this;
+ }
+
+ /**
* Creates an input to the route
*
* @param uri the from uri
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java
index ab99fe0..b5929ec 100644
--- a/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java
@@ -149,6 +149,17 @@ public class RoutesDefinition extends OptionalIdentifiedDefinition<RoutesDefinit
}
/**
+ * Creates a new REST route
+ *
+ * @return the builder
+ */
+ public RouteDefinition fromRest(String verb, String path) {
+ RouteDefinition route = createRoute();
+ route.fromRest(verb, path);
+ return route(route);
+ }
+
+ /**
* Creates a new route from the given URI input
*
* @param uri the from uri
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/main/java/org/apache/camel/spi/RestBindingCapable.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/spi/RestBindingCapable.java b/camel-core/src/main/java/org/apache/camel/spi/RestBindingCapable.java
new file mode 100644
index 0000000..645f1bc
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/spi/RestBindingCapable.java
@@ -0,0 +1,37 @@
+/**
+ * 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.spi;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.component.restbinding.RestBindingEndpoint;
+
+public interface RestBindingCapable {
+
+ /**
+ * Creates a new REST <a
+ * href="http://camel.apache.org/event-driven-consumer.html">Event
+ * Driven Consumer</a>, using the details from the {@link org.apache.camel.component.restbinding.RestBindingEndpoint},
+ * which consumes messages from the endpoint using the given processor
+ *
+ * @param endpoint the binding endpoint
+ * @param processor the processor
+ * @return a newly created REST consumer
+ * @throws Exception can be thrown
+ */
+ Consumer createConsumer(RestBindingEndpoint endpoint, Processor processor) throws Exception;
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest-binding
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest-binding b/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest-binding
new file mode 100644
index 0000000..3bf1949
--- /dev/null
+++ b/camel-core/src/main/resources/META-INF/services/org/apache/camel/component/rest-binding
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+
+class=org.apache.camel.component.restbinding.RestBindingComponent
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
----------------------------------------------------------------------
diff --git a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
index 1e32f42..4afe1f1 100644
--- a/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
+++ b/camel-core/src/main/resources/org/apache/camel/model/jaxb.index
@@ -30,6 +30,7 @@ ExpressionSubElementDefinition
FilterDefinition
FinallyDefinition
FromDefinition
+RestFromDefinition
IdempotentConsumerDefinition
InOnlyDefinition
InOutDefinition
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java
new file mode 100644
index 0000000..6374b70
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/restbinding/DummyRestBindingCapableComponent.java
@@ -0,0 +1,47 @@
+/**
+ * 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.restbinding;
+
+import java.util.Map;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Endpoint;
+import org.apache.camel.Processor;
+import org.apache.camel.component.seda.SedaEndpoint;
+import org.apache.camel.impl.ActiveMQUuidGenerator;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.spi.RestBindingCapable;
+
+public class DummyRestBindingCapableComponent extends DefaultComponent implements RestBindingCapable {
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
+ return null;
+ }
+
+ @Override
+ public Consumer createConsumer(RestBindingEndpoint endpoint, Processor processor) throws Exception {
+ // just use a seda endpoint for testing purpose
+ String id = ActiveMQUuidGenerator.generateSanitizedId(endpoint.getPath());
+ // remove leading dash as we add that ourselves
+ if (id.startsWith("-")) {
+ id = id.substring(1);
+ }
+ SedaEndpoint seda = getCamelContext().getEndpoint("seda:" + endpoint.getVerb() + "-" + id, SedaEndpoint.class);
+ return seda.createConsumer(processor);
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
new file mode 100644
index 0000000..69141c4
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/restbinding/FromRestGetTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.restbinding;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.FromRestDefinition;
+import org.apache.camel.model.RouteDefinition;
+
+public class FromRestGetTest extends ContextTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ CamelContext context = super.createCamelContext();
+
+ // register our dummy rest capable component
+ context.addComponent("dummy-rest", new DummyRestBindingCapableComponent());
+
+ return context;
+ }
+
+ public void testFromRestModel() {
+ assertEquals(1, context.getRoutes().size());
+
+ RouteDefinition route = context.getRouteDefinition("foo");
+ assertNotNull(route);
+
+ FromRestDefinition from = (FromRestDefinition) route.getInputs().get(0);
+ assertNotNull(from);
+ assertEquals("get", from.getVerb());
+ assertEquals("/hello", from.getPath());
+ assertNull(from.getAccept());
+ }
+
+ public void testFromRest() throws Exception {
+ getMockEndpoint("mock:foo").expectedMessageCount(1);
+
+ template.sendBody("seda:get-hello", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // fromRest().get("/hello")
+ fromRest("get", "/hello").routeId("foo")
+ .to("mock:foo")
+ .transform().constant("Bye World");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2f19857a/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml
index 1d4bcb2..ebab224 100644
--- a/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml
@@ -25,11 +25,11 @@
<import resource="../interceptor/transactionalClientDataSource.xml"/>
<camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/spring">
+
<route id="route1">
- <from uri="seda:start"/>
- <transacted/>
- <to id="mock-a" uri="mock:a"/>
- <to id="mock-b" uri="mock:b"/>
+ <get path="/customer/:name"/>
+ <to uri="bean:customerService?method=findCustomer($header.name})"/>
</route>
+
</camelContext>
</beans>
[20/33] git commit: CAMEL-7354: Rest DSL,
only path is used for defining the path.
Posted by da...@apache.org.
CAMEL-7354: Rest DSL, only path is used for defining the path.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/571b1345
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/571b1345
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/571b1345
Branch: refs/heads/master
Commit: 571b1345c2bf3612eb9f96c8ee29b75bf02b752a
Parents: f73a592
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Jul 16 14:48:11 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 19 09:38:51 2014 +0200
----------------------------------------------------------------------
.../camel/model/rest/DeleteVerbDefinition.java | 3 ---
.../camel/model/rest/GetVerbDefinition.java | 3 ---
.../camel/model/rest/HeadVerbDefinition.java | 3 ---
.../apache/camel/model/rest/PathDefinition.java | 27 +++++++++++++++-----
.../camel/model/rest/PostVerbDefinition.java | 3 ---
.../camel/model/rest/PutVerbDefinition.java | 3 ---
.../apache/camel/model/rest/RestDefinition.java | 8 +++---
.../apache/camel/model/rest/VerbDefinition.java | 18 +++++++++++++
.../rest/FromRestGetEmbeddedRouteTest.java | 6 ++---
.../camel/component/rest/FromRestGetTest.java | 10 ++++----
.../management/ManagedCamelContextTest.java | 2 +-
.../management/ManagedFromRestGetTest.java | 8 +++---
.../camel/blueprint/BlueprintJaxbRestTest.java | 6 ++---
.../rest/FromRestGetEmbeddedRouteTest.java | 6 ++---
.../component/rest/FromRestGetTest.java | 10 ++++----
15 files changed, 67 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/camel-core/src/main/java/org/apache/camel/model/rest/DeleteVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/DeleteVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/DeleteVerbDefinition.java
index 137c607..990819a 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/DeleteVerbDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/DeleteVerbDefinition.java
@@ -24,7 +24,4 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
public class DeleteVerbDefinition extends VerbDefinition {
- public DeleteVerbDefinition() {
- setMethod("delete");
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java
index 03315d4..f3e398e 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/GetVerbDefinition.java
@@ -24,7 +24,4 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
public class GetVerbDefinition extends VerbDefinition {
- public GetVerbDefinition() {
- setMethod("get");
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/camel-core/src/main/java/org/apache/camel/model/rest/HeadVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/HeadVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/HeadVerbDefinition.java
index 7db89a3..abcd2f9 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/HeadVerbDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/HeadVerbDefinition.java
@@ -24,7 +24,4 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
public class HeadVerbDefinition extends VerbDefinition {
- public HeadVerbDefinition() {
- setMethod("head");
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
index bb70b3c..06d95bc 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PathDefinition.java
@@ -28,18 +28,20 @@ import javax.xml.bind.annotation.XmlTransient;
import org.apache.camel.model.ToDefinition;
@XmlRootElement(name = "path")
-@XmlAccessorType(XmlAccessType.PROPERTY)
+@XmlAccessorType(XmlAccessType.FIELD)
public class PathDefinition {
+ @XmlAttribute(required = true)
private String uri;
+ @XmlElementRef
private List<VerbDefinition> verbs = new ArrayList<VerbDefinition>();
+ @XmlTransient
private RestDefinition rest;
public String getUri() {
return uri;
}
- @XmlAttribute(required = true)
public void setUri(String uri) {
this.uri = uri;
}
@@ -48,7 +50,6 @@ public class PathDefinition {
return verbs;
}
- @XmlElementRef
public void setVerbs(List<VerbDefinition> verbs) {
this.verbs = verbs;
}
@@ -57,7 +58,6 @@ public class PathDefinition {
return rest;
}
- @XmlTransient
public void setRest(RestDefinition rest) {
this.rest = rest;
}
@@ -120,8 +120,23 @@ public class PathDefinition {
}
private PathDefinition addVerb(String verb, String url) {
- VerbDefinition answer = new VerbDefinition();
- answer.setMethod(verb);
+ VerbDefinition answer;
+
+ if ("get".equals(verb)) {
+ answer = new GetVerbDefinition();
+ } else if ("post".equals(verb)) {
+ answer = new PostVerbDefinition();
+ } else if ("delete".equals(verb)) {
+ answer = new DeleteVerbDefinition();
+ } else if ("head".equals(verb)) {
+ answer = new HeadVerbDefinition();
+ } else if ("put".equals(verb)) {
+ answer = new PutVerbDefinition();
+ } else {
+ answer = new VerbDefinition();
+ answer.setMethod(verb);
+ }
+
answer.setPath(this);
getVerbs().add(answer);
return this;
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java
index 3a8f39e..a5d2fb0 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PostVerbDefinition.java
@@ -24,7 +24,4 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
public class PostVerbDefinition extends VerbDefinition {
- public PostVerbDefinition() {
- setMethod("post");
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/camel-core/src/main/java/org/apache/camel/model/rest/PutVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/PutVerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/PutVerbDefinition.java
index 2a2f616..b1f4541 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/PutVerbDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/PutVerbDefinition.java
@@ -24,7 +24,4 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD)
public class PutVerbDefinition extends VerbDefinition {
- public PutVerbDefinition() {
- setMethod("put");
- }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/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 546bb3a..24dd3e9 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
@@ -31,17 +31,18 @@ import org.apache.camel.model.RouteDefinition;
* Represents an XML <rest/> element
*/
@XmlRootElement(name = "rest")
-@XmlAccessorType(XmlAccessType.PROPERTY)
+@XmlAccessorType(XmlAccessType.FIELD)
public class RestDefinition {
+ @XmlAttribute
private String component;
+ @XmlElementRef
private List<PathDefinition> paths = new ArrayList<PathDefinition>();
public String getComponent() {
return component;
}
- @XmlAttribute
public void setComponent(String component) {
this.component = component;
}
@@ -50,7 +51,6 @@ public class RestDefinition {
return paths;
}
- @XmlElementRef
public void setPaths(List<PathDefinition> paths) {
this.paths = paths;
}
@@ -88,7 +88,7 @@ public class RestDefinition {
for (PathDefinition path : getPaths()) {
String uri = path.getUri();
for (VerbDefinition verb : path.getVerbs()) {
- String from = "rest:" + verb.getMethod() + ":" + uri + (getComponent() != null ? "?componentName=" + getComponent() : "");
+ String from = "rest:" + verb.asVerb() + ":" + uri + (getComponent() != null ? "?componentName=" + getComponent() : "");
RouteDefinition route = new RouteDefinition();
route.fromRest(from);
answer.add(route);
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/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 b3f48aa..9d99747 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
@@ -93,4 +93,22 @@ public class VerbDefinition extends OutputDefinition<VerbDefinition> {
return path.verb(verb);
}
+ public String asVerb() {
+ // we do not want the jaxb model to repeat itself, by outputting <get method="get">
+ // so we defer the verb from the instance type
+ if (this instanceof GetVerbDefinition) {
+ return "get";
+ } else if (this instanceof PostVerbDefinition) {
+ return "post";
+ } else if (this instanceof PutVerbDefinition) {
+ return "put";
+ } else if (this instanceof DeleteVerbDefinition) {
+ return "delete";
+ } else if (this instanceof HeadVerbDefinition) {
+ return "head";
+ } else {
+ return method;
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
index 4343646..a8b21eb 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -50,13 +50,13 @@ public class FromRestGetEmbeddedRouteTest extends ContextTestSupport {
path = rest.getPaths().get(1);
assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(1).getAccept());
- to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
+ assertEquals("application/json", path.getVerbs().get(0).getAccept());
+ to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
assertEquals("mock:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
getMockEndpoint("mock:update").expectedMessageCount(1);
- template.sendBody("seda:post-say", "I was here");
+ template.sendBody("seda:post-say-bye", "I was here");
assertMockEndpointsSatisfied();
String out = template.requestBody("seda:get-say-hello", "Me", String.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
index 4b607b7..72ef31f 100644
--- a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestGetTest.java
@@ -46,17 +46,17 @@ public class FromRestGetTest extends ContextTestSupport {
PathDefinition path = rest.getPaths().get(0);
assertEquals("/say/hello", path.getUri());
ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
- assertEquals("mock:hello", to.getUri());
+ assertEquals("direct:hello", to.getUri());
path = rest.getPaths().get(1);
assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(1).getAccept());
- to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
- assertEquals("mock:bye", to.getUri());
+ assertEquals("application/json", path.getVerbs().get(0).getAccept());
+ to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("direct:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
getMockEndpoint("mock:update").expectedMessageCount(1);
- template.sendBody("seda:post-say", "I was here");
+ template.sendBody("seda:post-say-bye", "I was here");
assertMockEndpointsSatisfied();
String out = template.requestBody("seda:get-say-hello", "Me", String.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
index 8223e7b..735ee6c 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java
@@ -195,7 +195,7 @@ public class ManagedCamelContextTest extends ManagementTestSupport {
Map<String, Properties> info = (Map<String, Properties>) mbeanServer.invoke(on, "findComponents", null, null);
assertNotNull(info);
- assertEquals(22, info.size());
+ assertEquals(23, info.size());
Properties prop = info.get("seda");
assertNotNull(prop);
assertEquals("seda", prop.get("name"));
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
index b9b87e5..bd6b8d4 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedFromRestGetTest.java
@@ -50,10 +50,10 @@ public class ManagedFromRestGetTest extends ManagementTestSupport {
assertTrue(xml.contains("rests"));
assertTrue(xml.contains("rest"));
- assertTrue(xml.contains("<path uri=\"/say\">"));
- assertTrue(xml.contains("<get method=\"get\" uri=\"/hello\">"));
- assertTrue(xml.contains("<get method=\"get\" uri=\"/bye\">"));
- assertTrue(xml.contains("<post method=\"post\">"));
+ assertTrue(xml.contains("<path uri=\"/say/hello\">"));
+ assertTrue(xml.contains("<path uri=\"/say/bye\">"));
+ assertTrue(xml.contains("<get>"));
+ assertTrue(xml.contains("<post>"));
String xml2 = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
log.info(xml2);
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
----------------------------------------------------------------------
diff --git a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
index 7015e15..a7e6d07 100644
--- a/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
+++ b/components/camel-blueprint/src/test/java/org/apache/camel/blueprint/BlueprintJaxbRestTest.java
@@ -75,8 +75,8 @@ public class BlueprintJaxbRestTest extends TestSupport {
assertEquals(1, cfb.getRests().get(0).getPaths().get(0).getVerbs().size());
assertEquals(2, cfb.getRests().get(0).getPaths().get(1).getVerbs().size());
- assertEquals("get", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(0).getMethod());
- assertEquals("get", cfb.getRests().get(0).getPaths().get(1).getVerbs().get(0).getMethod());
- assertEquals("post", cfb.getRests().get(0).getPaths().get(1).getVerbs().get(1).getMethod());
+ assertEquals("get", cfb.getRests().get(0).getPaths().get(0).getVerbs().get(0).asVerb());
+ assertEquals("get", cfb.getRests().get(0).getPaths().get(1).getVerbs().get(0).asVerb());
+ assertEquals("post", cfb.getRests().get(0).getPaths().get(1).getVerbs().get(1).asVerb());
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
index ab5aafc..68cbb69 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetEmbeddedRouteTest.java
@@ -48,13 +48,13 @@ public class FromRestGetEmbeddedRouteTest extends CamelBlueprintTestSupport {
path = rest.getPaths().get(1);
assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(1).getAccept());
- to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
+ assertEquals("application/json", path.getVerbs().get(0).getAccept());
+ to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
assertEquals("mock:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
getMockEndpoint("mock:update").expectedMessageCount(1);
- template.sendBody("seda:post-say", "I was here");
+ template.sendBody("seda:post-say-bye", "I was here");
assertMockEndpointsSatisfied();
String out = template.requestBody("seda:get-say-hello", "Me", String.class);
http://git-wip-us.apache.org/repos/asf/camel/blob/571b1345/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
index 2aa7f2f..588f221 100644
--- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
+++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/FromRestGetTest.java
@@ -44,17 +44,17 @@ public class FromRestGetTest extends CamelBlueprintTestSupport {
PathDefinition path = rest.getPaths().get(0);
assertEquals("/say/hello", path.getUri());
ToDefinition to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
- assertEquals("mock:hello", to.getUri());
+ assertEquals("direct:hello", to.getUri());
path = rest.getPaths().get(1);
assertEquals("/say/bye", path.getUri());
- assertEquals("application/json", path.getVerbs().get(1).getAccept());
- to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(1).getOutputs().get(0));
- assertEquals("mock:bye", to.getUri());
+ assertEquals("application/json", path.getVerbs().get(0).getAccept());
+ to = assertIsInstanceOf(ToDefinition.class, path.getVerbs().get(0).getOutputs().get(0));
+ assertEquals("direct:bye", to.getUri());
// the rest becomes routes and the input is a seda endpoint created by the DummyRestConsumerFactory
getMockEndpoint("mock:update").expectedMessageCount(1);
- template.sendBody("seda:post-say", "I was here");
+ template.sendBody("seda:post-say-bye", "I was here");
assertMockEndpointsSatisfied();
String out = template.requestBody("seda:get-say-hello", "Me", String.class);