本文整理汇总了Java中org.apache.camel.model.RoutesDefinition类的典型用法代码示例。如果您正苦于以下问题:Java RoutesDefinition类的具体用法?Java RoutesDefinition怎么用?Java RoutesDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RoutesDefinition类属于org.apache.camel.model包,在下文中一共展示了RoutesDefinition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testXmlDSL
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
@Test
public void testXmlDSL() throws Exception {
CamelContext camelContext = new DefaultCamelContext();
// This is normally done by the Spring implemented registry, we keep it simple here...
TamayaPropertiesComponent props = new TamayaPropertiesComponent();
props.setTamayaOverrides(true);
camelContext.addComponent("properties", props);
// Read routes from XML DSL
InputStream is = getClass().getResourceAsStream("/META-INF/routes.xml");
RoutesDefinition routes = camelContext.loadRoutesDefinition(is);
for(RouteDefinition def: routes.getRoutes()) {
camelContext.addRouteDefinition(def);
}
camelContext.start();
Greeter greeter = new ProxyBuilder(camelContext).endpoint("direct:hello1").build(Greeter.class);
assertEquals("Good Bye from Apache Tamaya!", greeter.greet());
greeter = new ProxyBuilder(camelContext).endpoint("direct:hello2").build(Greeter.class);
assertEquals("Good Bye from Apache Tamaya!", greeter.greet());
greeter = new ProxyBuilder(camelContext).endpoint("direct:hello3").build(Greeter.class);
assertEquals("Good Bye from Apache Tamaya!", greeter.greet());
}
开发者ID:apache,项目名称:incubator-tamaya-sandbox,代码行数:22,代码来源:TamayaPropertyResolverTest.java
示例2: addOrUpdateRoutesFromXml
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
public void addOrUpdateRoutesFromXml(String xml, boolean urlDecode) throws Exception {
// decode String as it may have been encoded, from its xml source
if (urlDecode) {
xml = URLDecoder.decode(xml, "UTF-8");
}
InputStream is = context.getTypeConverter().mandatoryConvertTo(InputStream.class, xml);
RoutesDefinition def = context.loadRoutesDefinition(is);
if (def == null) {
return;
}
try {
// add will remove existing route first
context.addRouteDefinitions(def.getRoutes());
} catch (Exception e) {
// log the error as warn as the management api may be invoked remotely over JMX which does not propagate such exception
String msg = "Error updating routes from xml: " + xml + " due: " + e.getMessage();
LOG.warn(msg, e);
throw e;
}
}
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:ManagedCamelContext.java
示例3: marshalRootElement
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
/**
* Returns the root element to be marshalled as XML
*
* @return
*/
public Object marshalRootElement() {
if (justRoutes) {
RoutesDefinition routes = new RoutesDefinition();
routes.setRoutes(contextElement.getRoutes());
return routes;
} else {
return contextElement;
}
}
开发者ID:fabric8io,项目名称:fabric8-forge,代码行数:15,代码来源:XmlModel.java
示例4: configure
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
@Override
public void configure() throws Exception {
from("file://" + xmlRouteDir + "?noop=true&idempotent=true&delay=5000&include=.*\\.xml")
.routeId(this.context.getName() + "-xmlDropInRoute")
.description("Consumes Spring xml routes from the routes/xml/" + this.context.getName() + " directory")
.process(
exchange -> {
try (InputStream is = exchange.getIn().getBody(InputStream.class)) {
RoutesDefinition routes = context.loadRoutesDefinition(is);
context.addRouteDefinitions(routes.getRoutes());
}
}
);
}
开发者ID:Steve973,项目名称:camel-standalone,代码行数:15,代码来源:XmlDropInRouteBuilder.java
示例5: getRoutesDefinition
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
public static RoutesDefinition getRoutesDefinition(String name, String modifier, Map<String,String> attributes) {
RoutesDefinitionRuleSet rdrs = getRoutesDefinitionRuleSet(name, modifier, attributes);
if (rdrs == null)
return null;
else
return rdrs.getRoutesDefinition();
}
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:8,代码来源:CamelRouteCache.java
示例6: RoutesDefinitionRuleSet
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
public RoutesDefinitionRuleSet(RoutesDefinition routes, Asset ruleSet) {
this.routesDefinition = routes;
this.ruleSet = ruleSet;
for (RouteDefinition routeDef : routesDefinition.getRoutes()) {
routeIds.add(routeDef.getId());
}
}
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:9,代码来源:RoutesDefinitionRuleSet.java
示例7: getRoutesDefinition
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
/**
* Returns the latest version whose attributes match the custom attribute
* criteria specified via "CustomAttributes".
* Override to apply additional or non-standard conditions.
* @param version
*/
protected RoutesDefinition getRoutesDefinition(String name, String version) throws AdapterException {
String modifier = "";
Map<String,String> params = getHandlerParameters();
if (params != null) {
for (String paramName : params.keySet()) {
if (modifier.length() == 0)
modifier += "?";
else
modifier += "&";
modifier += paramName + "=" + params.get(paramName);
}
}
Map<String,String> customAttrs = null;
String customAttrString = getAttributeValue(CUSTOM_ATTRIBUTES);
if (!StringHelper.isEmpty(customAttrString)) {
customAttrs = StringHelper.parseMap(customAttrString);
}
RoutesDefinitionRuleSet rdrs;
if (version == null)
rdrs = CamelRouteCache.getRoutesDefinitionRuleSet(name, modifier, customAttrs);
else
rdrs = CamelRouteCache.getRoutesDefinitionRuleSet(new AssetVersionSpec(name, version), modifier, customAttrs);
if (rdrs == null) {
throw new AdapterException("Unable to load Camel route: " + name + modifier);
}
else {
super.logdebug("Using RoutesDefinition: " + rdrs.getRuleSet().getLabel());
return rdrs.getRoutesDefinition();
}
}
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:41,代码来源:CamelRouteAdapter.java
示例8: testLoadRouteFromXml
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
@Test
public void testLoadRouteFromXml() throws Exception {
assertNotNull("Existing foo route should be there", context.getRoute("foo"));
assertEquals(1, context.getRoutes().size());
// test that existing route works
MockEndpoint foo = getMockEndpoint("mock:foo");
foo.expectedBodiesReceived("Hello World");
template.sendBody("direct:foo", "Hello World");
foo.assertIsSatisfied();
// load bar route from classpath using JAXB
JAXBContext jaxb = new DefaultModelJAXBContextFactory().newJAXBContext();
Unmarshaller unmarshaller = jaxb.createUnmarshaller();
Resource rs = new ClassPathResource("org/apache/camel/itest/jaxb/BarRoute.xml");
Object value = unmarshaller.unmarshal(rs.getInputStream());
// it should be a RoutesDefinition (we can have multiple routes in the same XML file)
RoutesDefinition routes = (RoutesDefinition) value;
assertNotNull("Should load routes from XML", routes);
assertEquals(1, routes.getRoutes().size());
// add the routes to existing CamelContext
context.addRouteDefinitions(routes.getRoutes());
assertNotNull("Loaded bar route should be there", context.getRoute("bar"));
assertEquals(2, context.getRoutes().size());
// test that loaded route works
MockEndpoint bar = getMockEndpoint("mock:bar");
bar.expectedBodiesReceived("Bye World");
template.sendBody("direct:bar", "Bye World");
bar.assertIsSatisfied();
}
开发者ID:HydAu,项目名称:Camel,代码行数:36,代码来源:SpringLoadRouteFromXmlTest.java
示例9: start
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
@Override
public void start(BundleContext bundleContext) throws Exception {
try {
this.bundleContext = bundleContext;
log.debug("Initializing bundle {}.", bundleContext.getBundle().getBundleId());
camelContext = createCamelContext();
camelContext.addRoutes(this);
ConfigurationAdmin configurationAdmin = requiredService(ConfigurationAdmin.class);
Configuration camelKuraConfig = configurationAdmin.getConfiguration(camelXmlRoutesPid());
if (camelKuraConfig != null && camelKuraConfig.getProperties() != null) {
Object routePropertyValue = camelKuraConfig.getProperties().get(camelXmlRoutesProperty());
if (routePropertyValue != null) {
InputStream routesXml = new ByteArrayInputStream(routePropertyValue.toString().getBytes());
RoutesDefinition loadedRoutes = camelContext.loadRoutesDefinition(routesXml);
camelContext.addRouteDefinitions(loadedRoutes.getRoutes());
}
}
beforeStart(camelContext);
log.debug("About to start Camel Kura router: {}", getClass().getName());
camelContext.start();
producerTemplate = camelContext.createProducerTemplate();
consumerTemplate = camelContext.createConsumerTemplate();
log.debug("Bundle {} started.", bundleContext.getBundle().getBundleId());
} catch (Throwable e) {
String errorMessage = "Problem when starting Kura module " + getClass().getName() + ":";
log.warn(errorMessage, e);
// Print error to the Kura console.
System.err.println(errorMessage);
e.printStackTrace();
throw e;
}
}
开发者ID:HydAu,项目名称:Camel,代码行数:37,代码来源:KuraRouter.java
示例10: routesDefinitionBean
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
private SyntheticBean<?> routesDefinitionBean(RoutesDefinition definition, URL url) {
return new SyntheticBean<>(manager,
// TODO: should be @Named if the id is set
new SyntheticAnnotated(RoutesDefinition.class,
manager.createAnnotatedType(RoutesDefinition.class).getTypeClosure(),
ANY, DEFAULT),
RoutesDefinition.class,
new SyntheticInjectionTarget<>(() -> definition), bean ->
"imported routes definition "
+ (hasId(definition) ? "[" + definition.getId() + "] " : "")
+ "from resource [" + url + "]");
}
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:XmlCdiBeanFactory.java
示例11: loadXmlRoutes
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
private void loadXmlRoutes(ApplicationContext applicationContext, CamelContext camelContext, String directory) throws Exception {
LOG.info("Loading additional Camel XML routes from: {}", directory);
try {
Resource[] xmlRoutes = applicationContext.getResources(directory);
for (Resource xmlRoute : xmlRoutes) {
LOG.debug("Found XML route: {}", xmlRoute);
RoutesDefinition xmlDefinition = camelContext.loadRoutesDefinition(xmlRoute.getInputStream());
camelContext.addRouteDefinitions(xmlDefinition.getRoutes());
}
} catch (FileNotFoundException e) {
LOG.debug("No XML routes found in {}. Skipping XML routes detection.", directory);
}
}
开发者ID:HydAu,项目名称:Camel,代码行数:14,代码来源:RoutesCollector.java
示例12: loadRoute
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
/**
* Loads a set of route definitions from an XML file.
*
* @param xmlPath
* path to the file containing one or more route definitions
* @param camelContext
* CamelContext
* @param propertyResolver
* The property Resolver
* @return list of route definitions
*/
public static List<RouteDefinition> loadRoute(String xmlPath, SwitchYardCamelContext camelContext,
PropertyResolver propertyResolver) {
List<RouteDefinition> routes = null;
try {
Object obj = CamelModelFactory.createCamelModelObjectFromXML(xmlPath);
// Look for top-level element - camelContext, routes or route
if (obj instanceof CamelContextFactoryBean) {
routes = processCamelContextElement((CamelContextFactoryBean)obj, camelContext);
} else if (obj instanceof RoutesDefinition) {
routes = ((RoutesDefinition)obj).getRoutes();
} else if (obj instanceof RouteDefinition) {
routes = new ArrayList<RouteDefinition>(1);
routes.add((RouteDefinition)obj);
}
// If we couldn't find a route definition, throw an error
if (routes == null) {
CamelComponentMessages.MESSAGES.noRoutesFoundInXMLFile(xmlPath);
}
return routes;
} catch (Exception e) {
throw new SwitchYardException(e);
}
}
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:40,代码来源:RouteFactory.java
示例13: routesDefinitionBean
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
private SyntheticBean<?> routesDefinitionBean(RoutesDefinition definition, URL url) {
return new SyntheticBean<>(manager,
// TODO: should be @Named if the id is set
new SyntheticAnnotated(RoutesDefinition.class,
manager.createAnnotatedType(RoutesDefinition.class).getTypeClosure(),
ANY, DEFAULT),
RoutesDefinition.class,
new SyntheticInjectionTarget<>(() -> definition),
bean -> "imported routes definition "
+ (hasId(definition) ? "[" + definition.getId() + "] " : "")
+ "from resource [" + url + "]");
}
开发者ID:astefanutti,项目名称:camel-cdi,代码行数:13,代码来源:XmlCdiBeanFactory.java
示例14: invoke
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
@Override
protected Object invoke(Object pConnection, Object request)
throws AdapterException, ConnectionException {
try {
String routeDefAttr = getAttributeValueSmart(ROUTE_DEF);
String routeDefVer = getAttributeValueSmart(ROUTE_DEF_VER);
if (routeDefAttr == null)
throw new AdapterException("Missing attribute: " + ROUTE_DEF);
RoutesDefinition routesDef = getRoutesDefinition(routeDefAttr, routeDefVer);
RouteDefinition routeDef = null;
if (routesDef.getRoutes().size() == 0) {
throw new AdapterException("No routes found in " + routesDef);
}
if (routesDef.getRoutes().size() > 1) {
String routeId = getAttributeValueSmart(ROUTE_ID);
if (routeId == null)
throw new AdapterException(ROUTE_ID + " attribute required when route definition contains more than one route");
for (RouteDefinition route : routesDef.getRoutes()) {
if (routeId.equals(route.getId()))
routeDef = route;
}
if (routeDef == null)
throw new AdapterException("Cannot find route ID=" + routeId + " in route definition asset '" + ROUTE_DEF + "'.");
}
else {
routeDef = routesDef.getRoutes().get(0);
}
Map<String,Object> headers = getHeaders();
if (headers == null)
headers = new HashMap<String,Object>();
headers.put("routeId", routeDef.getId());
WorkflowHandler handler = getWorkflowHandler(routeDefAttr);
if (handler == null)
throw new EventException("No workflow handler for: " + routeDefAttr + ". Make sure that the mdw-camel bundle is started");
return handler.invoke(request, headers);
}
catch (Exception ex) {
logger.severeException(ex.getMessage(), ex);
throw new AdapterException(-1, ex.getMessage(), ex);
}
}
开发者ID:CenturyLinkCloud,项目名称:mdw,代码行数:47,代码来源:CamelRouteAdapter.java
示例15: dumpRoutesAsXml
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
@Override
public String dumpRoutesAsXml(boolean resolvePlaceholders) throws Exception {
List<RouteDefinition> routes = context.getRouteDefinitions();
if (routes.isEmpty()) {
return null;
}
// use a routes definition to dump the routes
RoutesDefinition def = new RoutesDefinition();
def.setRoutes(routes);
String xml = ModelHelper.dumpModelAsXml(context, def);
// if resolving placeholders we parse the xml, and resolve the property placeholders during parsing
if (resolvePlaceholders) {
final AtomicBoolean changed = new AtomicBoolean();
InputStream is = new ByteArrayInputStream(xml.getBytes());
Document dom = XmlLineNumberParser.parseXml(is, new XmlLineNumberParser.XmlTextTransformer() {
@Override
public String transform(String text) {
try {
String after = getContext().resolvePropertyPlaceholders(text);
if (!changed.get()) {
changed.set(!text.equals(after));
}
return after;
} catch (Exception e) {
// ignore
return text;
}
}
});
// okay there were some property placeholder replaced so re-create the model
if (changed.get()) {
xml = context.getTypeConverter().mandatoryConvertTo(String.class, dom);
RoutesDefinition copy = ModelHelper.createModelFromXml(context, xml, RoutesDefinition.class);
xml = ModelHelper.dumpModelAsXml(context, copy);
}
}
return xml;
}
开发者ID:HydAu,项目名称:Camel,代码行数:42,代码来源:ManagedCamelContext.java
示例16: setRouteCollection
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
public void setRouteCollection(RoutesDefinition routeCollection) {
this.routeCollection = routeCollection;
}
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:RouteBuilder.java
示例17: getRouteCollection
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
public RoutesDefinition getRouteCollection() {
return this.routeCollection;
}
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:RouteBuilder.java
示例18: loadRoutesFromXML
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
/**
* Loads the routes from the given XML content
*/
public static RoutesDefinition loadRoutesFromXML(ModelCamelContext camelContext, String xml) throws JAXBException {
return ModelHelper.createModelFromXml(camelContext, xml, RoutesDefinition.class);
}
开发者ID:HydAu,项目名称:Camel,代码行数:7,代码来源:RoutesXml.java
示例19: loadRoutesFromClasspath
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
/**
* Loads the routes from the classpath
*/
public static RoutesDefinition loadRoutesFromClasspath(ModelCamelContext camelContext, String uri) throws JAXBException {
InputStream stream = ObjectHelper.loadResourceAsStream(uri);
ObjectHelper.notNull(stream, "Could not find resource '" + uri + "' on the ClassLoader");
return ModelHelper.createModelFromXml(camelContext, stream, RoutesDefinition.class);
}
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:RoutesXml.java
示例20: loadRoutesFromURL
import org.apache.camel.model.RoutesDefinition; //导入依赖的package包/类
/**
* Loads the routes from a {@link URL}
*/
public static RoutesDefinition loadRoutesFromURL(ModelCamelContext camelContext, URL url) throws JAXBException, IOException {
ObjectHelper.notNull(url, "url");
return ModelHelper.createModelFromXml(camelContext, url.openStream(), RoutesDefinition.class);
}
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:RoutesXml.java
注:本文中的org.apache.camel.model.RoutesDefinition类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论