Repository: camel Updated Branches: refs/heads/master e8fb927b9 -> d98a45e84
CAMEL-7354: Rest DSL. Added <restContext> so we can externalize the rests like you can do with routes. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9d23bf31 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9d23bf31 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9d23bf31 Branch: refs/heads/master Commit: 9d23bf31b09f14d3f90e7c4f40f572c0d30ba480 Parents: e8fb927 Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Jul 30 11:59:22 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Jul 30 11:59:22 2014 +0200 ---------------------------------------------------------------------- .../camel/model/RestContextRefDefinition.java | 59 ++++++++ .../model/RestContextRefDefinitionHelper.java | 142 +++++++++++++++++++ .../model/RouteContextRefDefinitionHelper.java | 2 +- .../resources/org/apache/camel/model/jaxb.index | 1 + .../apache/camel/model/XmlRestParseTest.java | 44 ++++++ .../org/apache/camel/model/XmlTestSupport.java | 8 ++ .../org/apache/camel/model/simpleRest.xml | 27 ++++ .../blueprint/CamelContextFactoryBean.java | 11 ++ .../blueprint/CamelRestContextFactoryBean.java | 40 ++++++ .../handler/CamelNamespaceHandler.java | 46 ++++++ .../org/apache/camel/blueprint/jaxb.index | 1 + .../xml/AbstractCamelContextFactoryBean.java | 22 ++- .../camel/osgi/CamelNamespaceHandler.java | 1 + .../camel/spring/CamelContextFactoryBean.java | 11 ++ .../spring/CamelRestContextFactoryBean.java | 59 ++++++++ .../spring/handler/CamelNamespaceHandler.java | 38 ++++- .../org/apache/camel/spring/jaxb.index | 1 + .../camel/component/rest/RestRefTest.java | 64 +++++++++ .../apache/camel/component/rest/RestRefTest.xml | 64 +++++++++ .../blueprint/component/rest/RestRefTest.java | 66 +++++++++ .../blueprint/component/rest/RestRefTest.xml | 62 ++++++++ 21 files changed, 765 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/camel-core/src/main/java/org/apache/camel/model/RestContextRefDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/RestContextRefDefinition.java b/camel-core/src/main/java/org/apache/camel/model/RestContextRefDefinition.java new file mode 100644 index 0000000..7f8e7ca --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/model/RestContextRefDefinition.java @@ -0,0 +1,59 @@ +/** + * 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 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.XmlRootElement; + +import org.apache.camel.CamelContext; +import org.apache.camel.model.rest.RestDefinition; + +/** + * Represents an XML <restContextRef/> element + * + * @version + */ +@XmlRootElement(name = "restContextRef") +@XmlAccessorType(XmlAccessType.FIELD) +public class RestContextRefDefinition { + @XmlAttribute(required = true) + private String ref; + + public RestContextRefDefinition() { + } + + @Override + public String toString() { + return "RestContextRef[" + getRef() + "]"; + } + + public String getRef() { + return ref; + } + + public void setRef(String ref) { + this.ref = ref; + } + + public List<RestDefinition> lookupRests(CamelContext camelContext) { + return RestContextRefDefinitionHelper.lookupRests(camelContext, ref); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/camel-core/src/main/java/org/apache/camel/model/RestContextRefDefinitionHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/RestContextRefDefinitionHelper.java b/camel-core/src/main/java/org/apache/camel/model/RestContextRefDefinitionHelper.java new file mode 100644 index 0000000..31149d8 --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/model/RestContextRefDefinitionHelper.java @@ -0,0 +1,142 @@ +/** + * 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 java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; + +import org.apache.camel.CamelContext; +import org.apache.camel.model.language.NamespaceAwareExpression; +import org.apache.camel.model.rest.RestDefinition; +import org.apache.camel.util.CamelContextHelper; +import org.apache.camel.util.ObjectHelper; + +/** + * Helper for {@link org.apache.camel.model.RestContextRefDefinition}. + */ +public final class RestContextRefDefinitionHelper { + + private static JAXBContext jaxbContext; + + private RestContextRefDefinitionHelper() { + } + + /** + * Lookup the rests from the {@link org.apache.camel.model.RestContextRefDefinition}. + * <p/> + * This implementation must be used to lookup the rests as it performs a deep clone of the rests + * as a {@link org.apache.camel.model.RestContextRefDefinition} can be re-used with multiple {@link org.apache.camel.CamelContext} and each + * context should have their own instances of the routes. This is to ensure no side-effects and sharing + * of instances between the contexts. For example such as property placeholders may be context specific + * so the routes should not use placeholders from another {@link org.apache.camel.CamelContext}. + * + * @param camelContext the CamelContext + * @param ref the id of the {@link org.apache.camel.model.RestContextRefDefinition} to lookup and get the routes. + * @return the rests. + */ + @SuppressWarnings("unchecked") + public static synchronized List<RestDefinition> lookupRests(CamelContext camelContext, String ref) { + ObjectHelper.notNull(camelContext, "camelContext"); + ObjectHelper.notNull(ref, "ref"); + + List<RestDefinition> answer = CamelContextHelper.lookup(camelContext, ref, List.class); + if (answer == null) { + throw new IllegalArgumentException("Cannot find RestContext with id " + ref); + } + + // must clone the rest definitions as they can be reused with multiple CamelContexts + // and they would need their own instances of the definitions to not have side effects among + // the CamelContext - for example property placeholder resolutions etc. + List<RestDefinition> clones = new ArrayList<RestDefinition>(answer.size()); + try { + JAXBContext jaxb = getOrCreateJAXBContext(); + for (RestDefinition def : answer) { + RestDefinition clone = cloneRestDefinition(jaxb, def); + if (clone != null) { + clones.add(clone); + } + } + } catch (Exception e) { + throw ObjectHelper.wrapRuntimeCamelException(e); + } + + return clones; + } + + private static synchronized JAXBContext getOrCreateJAXBContext() throws JAXBException { + if (jaxbContext == null) { + // must use classloader from CamelContext to have JAXB working + jaxbContext = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES, CamelContext.class.getClassLoader()); + } + return jaxbContext; + } + + private static RestDefinition cloneRestDefinition(JAXBContext jaxbContext, RestDefinition def) throws JAXBException { + Marshaller marshal = jaxbContext.createMarshaller(); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + marshal.marshal(def, bos); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + Object clone = unmarshaller.unmarshal(bis); + + if (clone != null && clone instanceof RestDefinition) { + RestDefinition def2 = (RestDefinition) clone; + + // TODO: revisit this + /* + // need to clone the namespaces also as they are not JAXB marshalled (as they are transient) + Iterator<ExpressionNode> it = ProcessorDefinitionHelper.filterTypeInOutputs(def.getOutputs(), ExpressionNode.class); + Iterator<ExpressionNode> it2 = ProcessorDefinitionHelper.filterTypeInOutputs(def2.getOutputs(), ExpressionNode.class); + while (it.hasNext() && it2.hasNext()) { + ExpressionNode node = it.next(); + ExpressionNode node2 = it2.next(); + + NamespaceAwareExpression name = null; + NamespaceAwareExpression name2 = null; + if (node.getExpression() instanceof NamespaceAwareExpression) { + name = (NamespaceAwareExpression) node.getExpression(); + } + if (node2.getExpression() instanceof NamespaceAwareExpression) { + name2 = (NamespaceAwareExpression) node2.getExpression(); + } + + if (name != null && name2 != null && name.getNamespaces() != null && !name.getNamespaces().isEmpty()) { + Map<String, String> map = new HashMap<String, String>(); + map.putAll(name.getNamespaces()); + name2.setNamespaces(map); + } + }*/ + + return def2; + } + + return null; + } + + + +} http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinitionHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinitionHelper.java b/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinitionHelper.java index 500aca9..d90dea5 100644 --- a/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinitionHelper.java +++ b/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinitionHelper.java @@ -46,7 +46,7 @@ public final class RouteContextRefDefinitionHelper { /** * Lookup the routes from the {@link RouteContextRefDefinition}. * <p/> - * This implmementation must be used to lookup the routes as it performs a deep clone of the routes + * This implementation must be used to lookup the routes as it performs a deep clone of the routes * as a {@link RouteContextRefDefinition} can be re-used with multiple {@link CamelContext} and each * context should have their own instances of the routes. This is to ensure no side-effects and sharing * of instances between the contexts. For example such as property placeholders may be context specific http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/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..f0d43ae 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 @@ -58,6 +58,7 @@ RemoveHeaderDefinition RemoveHeadersDefinition RemovePropertyDefinition ResequenceDefinition +RestContextRefDefinition RollbackDefinition RouteBuilderDefinition RouteDefinition http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/camel-core/src/test/java/org/apache/camel/model/XmlRestParseTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/model/XmlRestParseTest.java b/camel-core/src/test/java/org/apache/camel/model/XmlRestParseTest.java new file mode 100644 index 0000000..a9d7acc --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/model/XmlRestParseTest.java @@ -0,0 +1,44 @@ +/** + * 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.JAXBException; + +import org.apache.camel.model.rest.GetVerbDefinition; +import org.apache.camel.model.rest.RestContainer; +import org.apache.camel.model.rest.RestDefinition; + +public class XmlRestParseTest extends XmlTestSupport { + + public void testParseSimpleRestXml() throws Exception { + RestDefinition rest = assertOneRest("simpleRest.xml"); + assertEquals("/users", rest.getUri()); + + assertEquals(1, rest.getVerbs().size()); + GetVerbDefinition get = (GetVerbDefinition) rest.getVerbs().get(0); + assertEquals("/view/{id}", get.getUri()); + assertEquals("direct:getUser", get.getTo().getUri()); + } + + protected RestDefinition assertOneRest(String uri) throws JAXBException { + RestContainer context = assertParseRestAsJaxb(uri); + RestDefinition rest = assertOneElement(context.getRests()); + return rest; + } + + +} http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/camel-core/src/test/java/org/apache/camel/model/XmlTestSupport.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/model/XmlTestSupport.java b/camel-core/src/test/java/org/apache/camel/model/XmlTestSupport.java index cec6815..ee8366b 100644 --- a/camel-core/src/test/java/org/apache/camel/model/XmlTestSupport.java +++ b/camel-core/src/test/java/org/apache/camel/model/XmlTestSupport.java @@ -23,6 +23,7 @@ import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import org.apache.camel.TestSupport; +import org.apache.camel.model.rest.RestContainer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,6 +41,13 @@ public abstract class XmlTestSupport extends TestSupport { return context; } + protected RestContainer assertParseRestAsJaxb(String uri) throws JAXBException { + Object value = parseUri(uri); + RestContainer context = assertIsInstanceOf(RestContainer.class, value); + log.info("Found: " + context); + return context; + } + protected Object parseUri(String uri) throws JAXBException { Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); URL resource = getClass().getResource(uri); http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/camel-core/src/test/resources/org/apache/camel/model/simpleRest.xml ---------------------------------------------------------------------- diff --git a/camel-core/src/test/resources/org/apache/camel/model/simpleRest.xml b/camel-core/src/test/resources/org/apache/camel/model/simpleRest.xml new file mode 100644 index 0000000..de6ba7f --- /dev/null +++ b/camel-core/src/test/resources/org/apache/camel/model/simpleRest.xml @@ -0,0 +1,27 @@ +<?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. +--> +<rests xmlns="http://camel.apache.org/schema/spring" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> + + <rest uri="/users"> + <get uri="/view/{id}"> + <to uri="direct:getUser"/> + </get> + </rest> + +</rests> http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/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 d40ef6f..56f1fba 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 @@ -48,6 +48,7 @@ import org.apache.camel.model.InterceptSendToEndpointDefinition; import org.apache.camel.model.OnCompletionDefinition; import org.apache.camel.model.OnExceptionDefinition; import org.apache.camel.model.PackageScanDefinition; +import org.apache.camel.model.RestContextRefDefinition; import org.apache.camel.model.RouteBuilderDefinition; import org.apache.camel.model.RouteContextRefDefinition; import org.apache.camel.model.RouteDefinition; @@ -142,6 +143,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu private List<RouteBuilderDefinition> builderRefs = new ArrayList<RouteBuilderDefinition>(); @XmlElement(name = "routeContextRef", required = false) private List<RouteContextRefDefinition> routeRefs = new ArrayList<RouteContextRefDefinition>(); + @XmlElement(name = "restContextRef", required = false) + private List<RestContextRefDefinition> restRefs = new ArrayList<RestContextRefDefinition>(); @XmlElement(name = "threadPoolProfile", required = false) private List<ThreadPoolProfileDefinition> threadPoolProfiles; @XmlElement(name = "threadPool", required = false) @@ -425,6 +428,14 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Blu this.routeRefs = routeRefs; } + public List<RestContextRefDefinition> getRestRefs() { + return restRefs; + } + + public void setRestRefs(List<RestContextRefDefinition> restRefs) { + this.restRefs = restRefs; + } + public List<CamelRedeliveryPolicyFactoryBean> getRedeliveryPolicies() { return redeliveryPolicies; } http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelRestContextFactoryBean.java ---------------------------------------------------------------------- diff --git a/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelRestContextFactoryBean.java b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelRestContextFactoryBean.java new file mode 100644 index 0000000..41c7040 --- /dev/null +++ b/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelRestContextFactoryBean.java @@ -0,0 +1,40 @@ +/** + * 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 java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.camel.model.IdentifiedType; +import org.apache.camel.model.rest.RestDefinition; + +@XmlRootElement(name = "restContext") +@XmlAccessorType(XmlAccessType.FIELD) +public class CamelRestContextFactoryBean extends IdentifiedType { + + @XmlElement(name = "rest", required = true) + private List<RestDefinition> rests = new ArrayList<RestDefinition>(); + + public List<RestDefinition> getRests() throws Exception { + return rests; + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/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 bd1eb67..b29d5c0 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 @@ -32,6 +32,7 @@ import javax.xml.bind.Binder; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; +import org.apache.camel.blueprint.CamelRestContextFactoryBean; import org.apache.camel.model.ToDefinition; import org.apache.camel.model.rest.RestDefinition; import org.apache.camel.model.rest.VerbDefinition; @@ -116,6 +117,7 @@ public class CamelNamespaceHandler implements NamespaceHandler { private static final String CAMEL_CONTEXT = "camelContext"; private static final String ROUTE_CONTEXT = "routeContext"; + private static final String REST_CONTEXT = "restContext"; private static final String KEY_STORE_PARAMETERS = "keyStoreParameters"; private static final String SECURE_RANDOM_PARAMETERS = "secureRandomParameters"; private static final String SSL_CONTEXT_PARAMETERS = "sslContextParameters"; @@ -159,6 +161,9 @@ public class CamelNamespaceHandler implements NamespaceHandler { if (element.getLocalName().equals(ROUTE_CONTEXT)) { return parseRouteContextNode(element, context); } + if (element.getLocalName().equals(REST_CONTEXT)) { + return parseRestContextNode(element, context); + } if (element.getLocalName().equals(KEY_STORE_PARAMETERS)) { return parseKeyStoreParametersNode(element, context); } @@ -336,6 +341,47 @@ public class CamelNamespaceHandler implements NamespaceHandler { return ctx; } + private Metadata parseRestContextNode(Element element, ParserContext context) { + LOG.trace("Parsing RestContext {}", element); + // now parse the rests with JAXB + Binder<Node> binder; + try { + binder = getJaxbContext().createBinder(); + } catch (JAXBException e) { + throw new ComponentDefinitionException("Failed to create the JAXB binder : " + e, e); + } + Object value = parseUsingJaxb(element, context, binder); + if (!(value instanceof CamelRestContextFactoryBean)) { + throw new ComponentDefinitionException("Expected an instance of " + CamelRestContextFactoryBean.class); + } + + CamelRestContextFactoryBean rcfb = (CamelRestContextFactoryBean) value; + String id = rcfb.getId(); + + MutablePassThroughMetadata factory = context.createMetadata(MutablePassThroughMetadata.class); + factory.setId(".camelBlueprint.passThrough." + id); + factory.setObject(new PassThroughCallable<Object>(rcfb)); + + MutableBeanMetadata factory2 = context.createMetadata(MutableBeanMetadata.class); + factory2.setId(".camelBlueprint.factory." + id); + factory2.setFactoryComponent(factory); + factory2.setFactoryMethod("call"); + + MutableBeanMetadata ctx = context.createMetadata(MutableBeanMetadata.class); + ctx.setId(id); + ctx.setRuntimeClass(List.class); + ctx.setFactoryComponent(factory2); + ctx.setFactoryMethod("getRests"); + // must be lazy as we want CamelContext to be activated first + ctx.setActivation(ACTIVATION_LAZY); + + // lets inject the namespaces into any namespace aware POJOs + injectNamespaces(element, binder); + + LOG.trace("Parsing RestContext done, returning {}", element, ctx); + return ctx; + } + private Metadata parseKeyStoreParametersNode(Element element, ParserContext context) { LOG.trace("Parsing KeyStoreParameters {}", element); // now parse the key store parameters with JAXB http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index ---------------------------------------------------------------------- diff --git a/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index b/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index index 136f5de..2c1b625 100644 --- a/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index +++ b/components/camel-blueprint/src/main/resources/org/apache/camel/blueprint/jaxb.index @@ -21,5 +21,6 @@ CamelErrorHandlerFactoryBean CamelProducerTemplateFactoryBean CamelThreadPoolFactoryBean CamelRedeliveryPolicyFactoryBean +CamelRestContextFactoryBean CamelRouteContextFactoryBean CamelProxyFactoryBean http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/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 6d6b9ce..7ca86df 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 @@ -52,6 +52,7 @@ import org.apache.camel.model.ModelCamelContext; import org.apache.camel.model.OnCompletionDefinition; import org.apache.camel.model.OnExceptionDefinition; import org.apache.camel.model.PackageScanDefinition; +import org.apache.camel.model.RestContextRefDefinition; import org.apache.camel.model.RouteBuilderDefinition; import org.apache.camel.model.RouteContainer; import org.apache.camel.model.RouteContextRefDefinition; @@ -84,7 +85,6 @@ 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; @@ -314,6 +314,9 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex findRouteBuilders(); installRoutes(); + // must init rest refs before we add the rests + initRestRefs(); + // and add the rests getContext().addRestDefinitions(getRests()); } @@ -525,6 +528,21 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex } } + protected void initRestRefs() throws Exception { + // add rest refs to existing rests + if (getRestRefs() != null) { + for (RestContextRefDefinition ref : getRestRefs()) { + List<RestDefinition> defs = ref.lookupRests(getContext()); + for (RestDefinition def : defs) { + LOG.debug("Adding rest from {} -> {}", ref, def); + // add in top as they are most likely to be common/shared + // which you may want to start first + getRests().add(0, def); + } + } + } + } + protected abstract <S> S getBeanForType(Class<S> clazz); public void destroy() throws Exception { @@ -610,6 +628,8 @@ public abstract class AbstractCamelContextFactoryBean<T extends ModelCamelContex public abstract List<RouteContextRefDefinition> getRouteRefs(); + public abstract List<RestContextRefDefinition> getRestRefs(); + public abstract String getErrorHandlerRef(); public abstract DataFormatsDefinition getDataFormats(); http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/components/camel-spring/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java b/components/camel-spring/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java index 3890eea..41fcf6c 100644 --- a/components/camel-spring/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java +++ b/components/camel-spring/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java @@ -37,6 +37,7 @@ public class CamelNamespaceHandler extends org.apache.camel.spring.handler.Camel 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); return classes; } http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/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 478c4f1..0a39e2a 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 @@ -46,6 +46,7 @@ import org.apache.camel.model.InterceptSendToEndpointDefinition; import org.apache.camel.model.OnCompletionDefinition; import org.apache.camel.model.OnExceptionDefinition; import org.apache.camel.model.PackageScanDefinition; +import org.apache.camel.model.RestContextRefDefinition; import org.apache.camel.model.RouteBuilderDefinition; import org.apache.camel.model.RouteContextRefDefinition; import org.apache.camel.model.RouteDefinition; @@ -150,6 +151,8 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr private List<RouteBuilderDefinition> builderRefs = new ArrayList<RouteBuilderDefinition>(); @XmlElement(name = "routeContextRef", required = false) private List<RouteContextRefDefinition> routeRefs = new ArrayList<RouteContextRefDefinition>(); + @XmlElement(name = "restContextRef", required = false) + private List<RestContextRefDefinition> restRefs = new ArrayList<RestContextRefDefinition>(); @XmlElement(name = "threadPoolProfile", required = false) private List<ThreadPoolProfileDefinition> threadPoolProfiles; @XmlElement(name = "threadPool", required = false) @@ -665,6 +668,14 @@ public class CamelContextFactoryBean extends AbstractCamelContextFactoryBean<Spr this.routeRefs = routeRefs; } + public List<RestContextRefDefinition> getRestRefs() { + return restRefs; + } + + public void setRestRefs(List<RestContextRefDefinition> restRefs) { + this.restRefs = restRefs; + } + public String getErrorHandlerRef() { return errorHandlerRef; } http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/components/camel-spring/src/main/java/org/apache/camel/spring/CamelRestContextFactoryBean.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/main/java/org/apache/camel/spring/CamelRestContextFactoryBean.java b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelRestContextFactoryBean.java new file mode 100644 index 0000000..09f183c --- /dev/null +++ b/components/camel-spring/src/main/java/org/apache/camel/spring/CamelRestContextFactoryBean.java @@ -0,0 +1,59 @@ +/** + * 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.spring; + +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.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.apache.camel.model.IdentifiedType; +import org.apache.camel.model.rest.RestDefinition; +import org.springframework.beans.factory.FactoryBean; + +/** + * @version + */ +@XmlRootElement(name = "restContext") +@XmlAccessorType(XmlAccessType.FIELD) +public class CamelRestContextFactoryBean extends IdentifiedType implements FactoryBean<List<RestDefinition>> { + + @XmlElement(name = "rest", required = true) + private List<RestDefinition> rests = new ArrayList<RestDefinition>(); + + public List<RestDefinition> getObject() throws Exception { + return rests; + } + + public Class<?> getObjectType() { + return rests.getClass(); + } + + public boolean isSingleton() { + return true; + } + + public List<RestDefinition> getRests() { + return rests; + } + + public void setRests(List<RestDefinition> rests) { + this.rests = rests; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/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 1c256bd..125f6dd 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 @@ -46,6 +46,7 @@ import org.apache.camel.spring.CamelContextFactoryBean; import org.apache.camel.spring.CamelEndpointFactoryBean; import org.apache.camel.spring.CamelProducerTemplateFactoryBean; import org.apache.camel.spring.CamelRedeliveryPolicyFactoryBean; +import org.apache.camel.spring.CamelRestContextFactoryBean; import org.apache.camel.spring.CamelRouteContextFactoryBean; import org.apache.camel.spring.CamelThreadPoolFactoryBean; import org.apache.camel.spring.remoting.CamelProxyFactoryBean; @@ -98,9 +99,11 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport { } public void init() { + // register restContext parser + registerParser("restContext", new RestContextDefinitionParser()); // register routeContext parser - registerParser("routeContext", new RouteContextDefinitionParser()); - +// registerParser("routeContext", new RouteContextDefinitionParser()); + addBeanDefinitionParser("keyStoreParameters", KeyStoreParametersFactoryBean.class, true, true); addBeanDefinitionParser("secureRandomParameters", SecureRandomParametersFactoryBean.class, true, true); registerBeanDefinitionParser("sslContextParameters", new SSLContextParametersFactoryBeanBeanDefinitionParser()); @@ -276,6 +279,36 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport { } } + protected class RestContextDefinitionParser extends BeanDefinitionParser { + + public RestContextDefinitionParser() { + super(CamelRestContextFactoryBean.class, false); + } + + @Override + protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + renameNamespaceRecursive(element); + super.doParse(element, parserContext, builder); + + // now lets parse the routes with JAXB + Binder<Node> binder; + try { + binder = getJaxbContext().createBinder(); + } catch (JAXBException e) { + throw new BeanDefinitionStoreException("Failed to create the JAXB binder", e); + } + Object value = parseUsingJaxb(element, parserContext, binder); + + if (value instanceof CamelRestContextFactoryBean) { + CamelRestContextFactoryBean factoryBean = (CamelRestContextFactoryBean) value; + builder.addPropertyValue("rests", factoryBean.getRests()); + } + + // lets inject the namespaces into any namespace aware POJOs + injectNamespaces(element, binder); + } + } + protected class CamelContextBeanDefinitionParser extends BeanDefinitionParser { public CamelContextBeanDefinitionParser(Class<?> type) { @@ -324,6 +357,7 @@ public class CamelNamespaceHandler extends NamespaceHandlerSupport { builder.addPropertyValue("onExceptions", factoryBean.getOnExceptions()); builder.addPropertyValue("builderRefs", factoryBean.getBuilderRefs()); builder.addPropertyValue("routeRefs", factoryBean.getRouteRefs()); + builder.addPropertyValue("restRefs", factoryBean.getRestRefs()); builder.addPropertyValue("properties", factoryBean.getProperties()); builder.addPropertyValue("packageScan", factoryBean.getPackageScan()); builder.addPropertyValue("contextScan", factoryBean.getContextScan()); http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index b/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index index 5988d1b..780a60e 100644 --- a/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index +++ b/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index @@ -20,5 +20,6 @@ CamelContextFactoryBean CamelEndpointFactoryBean CamelProducerTemplateFactoryBean CamelRedeliveryPolicyFactoryBean +CamelRestContextFactoryBean CamelRouteContextFactoryBean CamelThreadPoolFactoryBean http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/components/camel-spring/src/test/java/org/apache/camel/component/rest/RestRefTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/component/rest/RestRefTest.java b/components/camel-spring/src/test/java/org/apache/camel/component/rest/RestRefTest.java new file mode 100644 index 0000000..322107a --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/component/rest/RestRefTest.java @@ -0,0 +1,64 @@ +/** + * 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.model.ToDefinition; +import org.apache.camel.model.rest.RestDefinition; +import org.apache.camel.spring.SpringTestSupport; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version + */ +public class RestRefTest extends SpringTestSupport { + + public void testRestRefTest() throws Exception { + assertEquals(2 + 3, 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).getTo()); + 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 AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/component/rest/RestRefTest.xml"); + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/9d23bf31/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml new file mode 100644 index 0000000..c381953 --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/component/rest/RestRefTest.xml @@ -0,0 +1,64 @@ +<?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"/> + + <restContext id="myCoolRest" xmlns="http://camel.apache.org/schema/spring"> + <rest uri="/say/hello"> + <get> + <to uri="direct:hello"/> + </get> + </rest> + </restContext> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + + <restContextRef ref="myCoolRest"/> + + <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/9d23bf31/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/RestRefTest.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/RestRefTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/RestRefTest.java new file mode 100644 index 0000000..4d4d7b6 --- /dev/null +++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/component/rest/RestRefTest.java @@ -0,0 +1,66 @@ +/** + * 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 RestRefTest extends CamelBlueprintTestSupport { + + @Override + protected String getBlueprintDescriptor() { + return "org/apache/camel/test/blueprint/component/rest/RestRefTest.xml"; + } + + protected int getExpectedNumberOfRoutes() { + return 2 + 3; + } + + @Test + public void testRestRefTest() 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).getTo()); + 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/9d23bf31/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/RestRefTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/RestRefTest.xml b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/RestRefTest.xml new file mode 100644 index 0000000..c12c6e3 --- /dev/null +++ b/components/camel-test-blueprint/src/test/resources/org/apache/camel/test/blueprint/component/rest/RestRefTest.xml @@ -0,0 +1,62 @@ +<?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"/> + + <restContext id="myCoolRest" xmlns="http://camel.apache.org/schema/blueprint"> + <rest uri="/say/hello"> + <get> + <to uri="direct:hello"/> + </get> + </rest> + </restContext> + + <camelContext xmlns="http://camel.apache.org/schema/blueprint"> + + <restContextRef ref="myCoolRest"/> + + <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