Author: davsclaus Date: Tue Apr 27 14:24:28 2010 New Revision: 938471 URL: http://svn.apache.org/viewvc?rev=938471&view=rev Log: CAMEL-2677: Spring XML can now use routeContext to have routes defined in external XML files.
Added: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinition.java (with props) camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelRouteContextFactoryBean.java (with props) camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.java (with props) camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRefsTest.java (with props) camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.java (with props) camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefTest.java (with props) camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.xml (with props) camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRefsTest.xml (with props) camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.xml (with props) camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefTest.xml (with props) camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/myCoolRoutes.xml (with props) Modified: camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java camel/trunk/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index Added: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinition.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinition.java?rev=938471&view=auto ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinition.java (added) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinition.java Tue Apr 27 14:24:28 2010 @@ -0,0 +1,69 @@ +/** + * 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.util.CamelContextHelper; +import org.apache.camel.util.ObjectHelper; + +/** + * Represents an XML <routeContextRef/> element + * + * @version $Revision$ + */ +...@xmlrootelement(name = "routeContextRef") +...@xmlaccessortype(XmlAccessType.FIELD) +public class RouteContextRefDefinition { + + @XmlAttribute(required = true) + private String ref; + + public RouteContextRefDefinition() { + } + + @Override + public String toString() { + return "RouteContextRef[" + getRef() + "]"; + } + + public String getRef() { + return ref; + } + + public void setRef(String ref) { + this.ref = ref; + } + + @SuppressWarnings("unchecked") + public List<RouteDefinition> lookupRoutes(CamelContext camelContext) { + ObjectHelper.notNull(camelContext, "camelContext", this); + ObjectHelper.notNull(ref, "ref", this); + + List answer = CamelContextHelper.lookup(camelContext, ref, List.class); + if (answer == null) { + throw new IllegalArgumentException("Cannot find RouteContext with id " + ref); + } + return answer; + } + +} Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinition.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteContextRefDefinition.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index?rev=938471&r1=938470&r2=938471&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index (original) +++ camel/trunk/camel-core/src/main/resources/org/apache/camel/model/jaxb.index Tue Apr 27 14:24:28 2010 @@ -58,6 +58,7 @@ ResequenceDefinition RollbackDefinition RouteBuilderDefinition RouteDefinition +RouteContextRefDefinition RoutesDefinition RoutingSlipDefinition SamplingDefinition Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=938471&r1=938470&r2=938471&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original) +++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Tue Apr 27 14:24:28 2010 @@ -51,10 +51,10 @@ import org.apache.camel.model.InterceptS import org.apache.camel.model.OnCompletionDefinition; import org.apache.camel.model.OnExceptionDefinition; import org.apache.camel.model.PackageScanDefinition; -import org.apache.camel.model.PolicyDefinition; import org.apache.camel.model.ProcessorDefinition; import org.apache.camel.model.RouteBuilderDefinition; import org.apache.camel.model.RouteContainer; +import org.apache.camel.model.RouteContextRefDefinition; import org.apache.camel.model.RouteDefinition; import org.apache.camel.model.ThreadPoolProfileDefinition; import org.apache.camel.model.ToDefinition; @@ -76,6 +76,7 @@ import org.apache.camel.spi.LifecycleStr import org.apache.camel.spi.ManagementStrategy; import org.apache.camel.spi.PackageScanClassResolver; import org.apache.camel.spi.Registry; +import org.apache.camel.spi.RouteContext; import org.apache.camel.spi.ShutdownStrategy; import org.apache.camel.spi.ThreadPoolProfile; import org.apache.camel.util.CamelContextHelper; @@ -146,6 +147,8 @@ public class CamelContextFactoryBean ext private List beans; @XmlElement(name = "routeBuilder", required = false) private List<RouteBuilderDefinition> builderRefs = new ArrayList<RouteBuilderDefinition>(); + @XmlElement(name = "routeContextRef", required = false) + private List<RouteContextRefDefinition> routeRefs = new ArrayList<RouteContextRefDefinition>(); @XmlElement(name = "threadPoolProfile", required = false) private List<ThreadPoolProfileDefinition> threadPoolProfiles; @XmlElement(name = "threadPool", required = false) @@ -197,7 +200,7 @@ public class CamelContextFactoryBean ext public ClassLoader getContextClassLoaderOnStart() { return contextClassLoaderOnStart; } - + public void afterPropertiesSet() throws Exception { if (ObjectHelper.isEmpty(getId())) { throw new IllegalArgumentException("Id must be set"); @@ -343,6 +346,9 @@ public class CamelContextFactoryBean ext initSpringCamelContext(getContext()); + // must init route refs before we prepare the routes below + initRouteRefs(); + // do special preparation for some concepts such as interceptors and policies // this is needed as JAXB does not build exactly the same model definition as Spring DSL would do // using route builders. So we have here a little custom code to fix the JAXB gaps @@ -382,8 +388,8 @@ public class CamelContextFactoryBean ext if (dataFormats != null) { getContext().setDataFormats(dataFormats.asMap()); - } - + } + // lets force any lazy creation getContext().addRouteDefinitions(routes); @@ -609,6 +615,23 @@ public class CamelContextFactoryBean ext } } + private void initRouteRefs() throws Exception { + // add route refs to existing routes + if (routeRefs != null) { + for (RouteContextRefDefinition ref : routeRefs) { + List<RouteDefinition> defs = ref.lookupRoutes(getContext()); + for (RouteDefinition def : defs) { + if (LOG.isDebugEnabled()) { + LOG.debug("Adding route from " + ref + " -> " + def); + } + // add in top as they are most likely to be common/shared + // which you may want to start first + routes.add(0, def); + } + } + } + } + @SuppressWarnings("unchecked") private <T> T getBeanForType(Class<T> clazz) { T bean = null; @@ -885,6 +908,14 @@ public class CamelContextFactoryBean ext this.builderRefs = builderRefs; } + public List<RouteContextRefDefinition> getRouteRefs() { + return routeRefs; + } + + public void setRouteRefs(List<RouteContextRefDefinition> routeRefs) { + this.routeRefs = routeRefs; + } + public String getErrorHandlerRef() { return errorHandlerRef; } Added: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelRouteContextFactoryBean.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelRouteContextFactoryBean.java?rev=938471&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelRouteContextFactoryBean.java (added) +++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelRouteContextFactoryBean.java Tue Apr 27 14:24:28 2010 @@ -0,0 +1,60 @@ +/** + * 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.RouteDefinition; +import org.springframework.beans.factory.FactoryBean; + +/** + * @version $Revision$ + */ +...@xmlrootelement(name = "routeContext") +...@xmlaccessortype(XmlAccessType.FIELD) +public class CamelRouteContextFactoryBean extends IdentifiedType implements FactoryBean { + + @XmlElement(name = "route", required = true) + private List<RouteDefinition> routes = new ArrayList<RouteDefinition>(); + + public Object getObject() throws Exception { + return routes; + } + + public Class getObjectType() { + return List.class; + } + + public boolean isSingleton() { + return true; + } + + public List<RouteDefinition> getRoutes() { + return routes; + } + + public void setRoutes(List<RouteDefinition> routes) { + this.routes = routes; + } + +} Propchange: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelRouteContextFactoryBean.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelRouteContextFactoryBean.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=938471&r1=938470&r2=938471&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java (original) +++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java Tue Apr 27 14:24:28 2010 @@ -33,6 +33,7 @@ import org.w3c.dom.NodeList; import org.apache.camel.builder.xml.Namespaces; import org.apache.camel.model.FromDefinition; +import org.apache.camel.model.RouteDefinition; import org.apache.camel.model.SendDefinition; import org.apache.camel.spi.NamespaceAware; import org.apache.camel.spring.CamelBeanPostProcessor; @@ -42,6 +43,7 @@ import org.apache.camel.spring.CamelEndp import org.apache.camel.spring.CamelJMXAgentDefinition; import org.apache.camel.spring.CamelProducerTemplateFactoryBean; import org.apache.camel.spring.CamelPropertyPlaceholderDefinition; +import org.apache.camel.spring.CamelRouteContextFactoryBean; import org.apache.camel.spring.CamelThreadPoolFactoryBean; import org.apache.camel.spring.remoting.CamelProxyFactoryBean; import org.apache.camel.spring.remoting.CamelServiceExporter; @@ -64,6 +66,7 @@ public class CamelNamespaceHandler exten private static final String SPRING_NS = "http://camel.apache.org/schema/spring"; private static final Log LOG = LogFactory.getLog(CamelNamespaceHandler.class); protected BeanDefinitionParser endpointParser = new BeanDefinitionParser(CamelEndpointFactoryBean.class); + protected BeanDefinitionParser routeParser = new BeanDefinitionParser(RouteDefinition.class); protected BeanDefinitionParser beanPostProcessorParser = new BeanDefinitionParser(CamelBeanPostProcessor.class); protected Set<String> parserElementNames = new HashSet<String>(); private JAXBContext jaxbContext; @@ -88,6 +91,9 @@ public class CamelNamespaceHandler exten } public void init() { + // register routeContext parser + registerParser("routeContext", new RouteContextDefinitionParser()); + addBeanDefinitionParser("proxy", CamelProxyFactoryBean.class, true); addBeanDefinitionParser("template", CamelProducerTemplateFactoryBean.class, true); addBeanDefinitionParser("consumerTemplate", CamelConsumerTemplateFactoryBean.class, true); @@ -98,10 +104,11 @@ public class CamelNamespaceHandler exten // jmx agent and property placeholder cannot be used outside of the camel context addBeanDefinitionParser("jmxAgent", CamelJMXAgentDefinition.class, false); addBeanDefinitionParser("propertyPlaceholder", CamelPropertyPlaceholderDefinition.class, false); - // errorhandler could be the sub element of camelContext - BeanDefinitionParser parser = new ErrorHandlerDefinitionParser(); - registerParser("errorHandler", parser); - parserMap.put("errorHandler", parser); + + // errorhandler could be the sub element of camelContext or defined outside camelContext + BeanDefinitionParser errorHandlerParser = new ErrorHandlerDefinitionParser(); + registerParser("errorHandler", errorHandlerParser); + parserMap.put("errorHandler", errorHandlerParser); // camel context boolean osgi = false; @@ -113,13 +120,11 @@ public class CamelNamespaceHandler exten // not running with camel-osgi so we fallback to the regular factory bean LOG.trace("Cannot find class so assuming not running in OSGi container: " + t.getMessage()); } - if (osgi) { LOG.info("camel-osgi.jar/camel-spring-osgi.jar detected in classpath"); } else { LOG.info("camel-osgi.jar/camel-spring-osgi.jar not detected in classpath"); } - if (LOG.isDebugEnabled()) { LOG.debug("Using " + cl.getCanonicalName() + " as CamelContextBeanDefinitionParser"); } @@ -154,7 +159,7 @@ public class CamelNamespaceHandler exten try { return binder.unmarshal(element); } catch (JAXBException e) { - throw new BeanDefinitionStoreException("Failed to parse JAXB element: " + e, e); + throw new BeanDefinitionStoreException("Failed to parse JAXB element", e); } } @@ -188,7 +193,36 @@ public class CamelNamespaceHandler exten return classes; } + protected class RouteContextDefinitionParser extends BeanDefinitionParser { + + public RouteContextDefinitionParser() { + super(CamelRouteContextFactoryBean.class); + } + + @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 CamelRouteContextFactoryBean) { + CamelRouteContextFactoryBean factoryBean = (CamelRouteContextFactoryBean)value; + builder.addPropertyValue("routes", factoryBean.getRoutes()); + } + } + } + + protected class CamelContextBeanDefinitionParser extends BeanDefinitionParser { + public CamelContextBeanDefinitionParser(Class type) { super(type); } @@ -211,7 +245,7 @@ public class CamelNamespaceHandler exten try { binder = getJaxbContext().createBinder(); } catch (JAXBException e) { - throw new BeanDefinitionStoreException("Failed to create the JAXB binder : " + e, e); + throw new BeanDefinitionStoreException("Failed to create the JAXB binder", e); } Object value = parseUsingJaxb(element, parserContext, binder); @@ -227,6 +261,7 @@ public class CamelNamespaceHandler exten builder.addPropertyValue("onCompletions", factoryBean.getOnCompletions()); builder.addPropertyValue("onExceptions", factoryBean.getOnExceptions()); builder.addPropertyValue("builderRefs", factoryBean.getBuilderRefs()); + builder.addPropertyValue("routeRefs", factoryBean.getRouteRefs()); builder.addPropertyValue("properties", factoryBean.getProperties()); builder.addPropertyValue("packageScan", factoryBean.getPackageScan()); if (factoryBean.getPackages().length > 0) { @@ -270,7 +305,6 @@ public class CamelNamespaceHandler exten } } } - // register as endpoint defined indirectly in the routes by from/to types having id explicit set registerEndpointsWithIdsDefinedInFromOrToTypes(element, parserContext, contextId, binder); @@ -287,7 +321,6 @@ public class CamelNamespaceHandler exten createBeanPostProcessor(parserContext, contextId, childElement, builder); } } - } protected void addDependsOn(CamelContextFactoryBean factoryBean, BeanDefinitionBuilder builder) { Modified: camel/trunk/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index?rev=938471&r1=938470&r2=938471&view=diff ============================================================================== --- camel/trunk/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index (original) +++ camel/trunk/components/camel-spring/src/main/resources/org/apache/camel/spring/jaxb.index Tue Apr 27 14:24:28 2010 @@ -22,5 +22,6 @@ CamelJMXAgentDefinition CamelProducerTemplateFactoryBean CamelPropertyPlaceholderDefinition CamelProxyFactoryDefinition +CamelRouteContextFactoryBean CamelServiceExporterDefinition CamelThreadPoolFactoryBean Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.java?rev=938471&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.java (added) +++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.java Tue Apr 27 14:24:28 2010 @@ -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.spring.config; + +import org.apache.camel.spring.SpringTestSupport; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version $Revision$ + */ +public class RouteRefIncludeXmlFileTest extends SpringTestSupport { + + public void testRouteRefInside() throws Exception { + getMockEndpoint("mock:inside").expectedMessageCount(1); + + template.sendBody("direct:inside", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + public void testRouteRefOutside() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(1); + getMockEndpoint("mock:bar").expectedMessageCount(1); + + template.sendBody("direct:start", "Hello World"); + template.sendBody("direct:bar", "Bye World"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.xml"); + } +} \ No newline at end of file Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRefsTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRefsTest.java?rev=938471&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRefsTest.java (added) +++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRefsTest.java Tue Apr 27 14:24:28 2010 @@ -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.spring.config; + +import org.apache.camel.spring.SpringTestSupport; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version $Revision$ + */ +public class RouteRefMultipleRefsTest extends SpringTestSupport { + + public void testRouteRefOutside() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(1); + getMockEndpoint("mock:foo").expectedMessageCount(1); + + template.sendBody("direct:start", "Hello World"); + template.sendBody("direct:foo", "Bye World"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/spring/config/RouteRefMultipleRefsTest.xml"); + } +} \ No newline at end of file Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRefsTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRefsTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.java?rev=938471&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.java (added) +++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.java Tue Apr 27 14:24:28 2010 @@ -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.spring.config; + +import org.apache.camel.spring.SpringTestSupport; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version $Revision$ + */ +public class RouteRefMultipleRoutesTest extends SpringTestSupport { + + public void testRouteRefInside() throws Exception { + getMockEndpoint("mock:inside").expectedMessageCount(1); + + template.sendBody("direct:inside", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + public void testRouteRefOutside() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(1); + getMockEndpoint("mock:bar").expectedMessageCount(1); + + template.sendBody("direct:start", "Hello World"); + template.sendBody("direct:bar", "Bye World"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/spring/config/RouteRefMultipleRoutesTest.xml"); + } +} \ No newline at end of file Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefTest.java URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefTest.java?rev=938471&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefTest.java (added) +++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefTest.java Tue Apr 27 14:24:28 2010 @@ -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.spring.config; + +import org.apache.camel.spring.SpringTestSupport; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version $Revision$ + */ +public class RouteRefTest extends SpringTestSupport { + + public void testRouteRefInside() throws Exception { + getMockEndpoint("mock:inside").expectedMessageCount(1); + + template.sendBody("direct:inside", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + public void testRouteRefOutside() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(1); + + template.sendBody("direct:start", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/spring/config/RouteRefTest.xml"); + } +} Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/RouteRefTest.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.xml?rev=938471&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.xml (added) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.xml Tue Apr 27 14:24:28 2010 @@ -0,0 +1,43 @@ +<?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-2.5.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <!-- START SNIPPET: e1 --> + + <!-- import the routes from another XML file --> + <import resource="myCoolRoutes.xml"/> + + <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring"> + + <!-- refer to a given route to be used --> + <routeContextRef ref="myCoolRoutes"/> + + <!-- we can of course still use routes inside camelContext --> + <route id="inside"> + <from uri="direct:inside"/> + <to uri="mock:inside"/> + </route> + </camelContext> + <!-- END SNIPPET: e1 --> + +</beans> Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefIncludeXmlFileTest.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRefsTest.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRefsTest.xml?rev=938471&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRefsTest.xml (added) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRefsTest.xml Tue Apr 27 14:24:28 2010 @@ -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-2.5.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <!-- START SNIPPET: e1 --> + <routeContext id="myCoolRoute" xmlns="http://camel.apache.org/schema/spring"> + <!-- we can have a route --> + <route id="cool"> + <from uri="direct:start"/> + <to uri="mock:result"/> + </route> + </routeContext> + + <!-- we can have more routeContexts --> + <routeContext id="myOtherRoute" xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="direct:foo"/> + <to uri="mock:foo"/> + </route> + </routeContext> + + <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring"> + <!-- we can include multiple route contexts --> + <routeContextRef ref="myCoolRoute"/> + <routeContextRef ref="myOtherRoute"/> + </camelContext> + <!-- END SNIPPET: e1 --> + +</beans> Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRefsTest.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRefsTest.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRefsTest.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.xml?rev=938471&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.xml (added) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.xml Tue Apr 27 14:24:28 2010 @@ -0,0 +1,52 @@ +<?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-2.5.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <!-- START SNIPPET: e1 --> + <routeContext id="myCoolRoutes" xmlns="http://camel.apache.org/schema/spring"> + <!-- we can have a route --> + <route id="cool"> + <from uri="direct:start"/> + <to uri="mock:result"/> + </route> + <!-- and another route, you can have as many your like --> + <route id="bar"> + <from uri="direct:bar"/> + <to uri="mock:bar"/> + </route> + </routeContext> + + <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring"> + + <!-- refer to a given route to be used --> + <routeContextRef ref="myCoolRoutes"/> + + <!-- we can of course still use routes inside camelContext --> + <route id="inside"> + <from uri="direct:inside"/> + <to uri="mock:inside"/> + </route> + </camelContext> + <!-- END SNIPPET: e1 --> + +</beans> Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefMultipleRoutesTest.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefTest.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefTest.xml?rev=938471&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefTest.xml (added) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefTest.xml Tue Apr 27 14:24:28 2010 @@ -0,0 +1,46 @@ +<?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-2.5.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <!-- START SNIPPET: e1 --> + <routeContext id="myCoolRoute" xmlns="http://camel.apache.org/schema/spring"> + <route id="cool"> + <from uri="direct:start"/> + <to uri="mock:result"/> + </route> + </routeContext> + + <camelContext id="myCamel" xmlns="http://camel.apache.org/schema/spring"> + + <!-- refer to a given route context to be included --> + <routeContextRef ref="myCoolRoute"/> + + <!-- we can of course still use routes inside camelContext --> + <route id="inside"> + <from uri="direct:inside"/> + <to uri="mock:inside"/> + </route> + </camelContext> + <!-- END SNIPPET: e1 --> + +</beans> Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefTest.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefTest.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/RouteRefTest.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/myCoolRoutes.xml URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/myCoolRoutes.xml?rev=938471&view=auto ============================================================================== --- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/myCoolRoutes.xml (added) +++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/myCoolRoutes.xml Tue Apr 27 14:24:28 2010 @@ -0,0 +1,42 @@ +<?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-2.5.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <!-- START SNIPPET: e1 --> + <!-- this is an included XML file where we only the the routeContext --> + + <routeContext id="myCoolRoutes" xmlns="http://camel.apache.org/schema/spring"> + <!-- we can have a route --> + <route id="cool"> + <from uri="direct:start"/> + <to uri="mock:result"/> + </route> + <!-- and another route, you can have as many your like --> + <route id="bar"> + <from uri="direct:bar"/> + <to uri="mock:bar"/> + </route> + </routeContext> + <!-- END SNIPPET: e1 --> + +</beans> Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/myCoolRoutes.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/myCoolRoutes.xml ------------------------------------------------------------------------------ svn:keywords = Rev Date Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/myCoolRoutes.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml