@Override public void install(File file) throws Exception { try (InputStream is = new FileInputStream(file)) { List<RouteDefinition> routeDefinitions; LOGGER.info("Loading route path: {}", file.getName()); routeDefinitions = camelContext.loadRoutesDefinition(is).getRoutes(); camelContext.addRouteDefinitions(routeDefinitions); processedFiles.put(file, routeDefinitions); camelContext.startAllRoutes(); } catch (Exception e) { LOGGER.warn("Failed to read route definition. See debug log for stack trace."); LOGGER.debug(e.getMessage(), e); } }
private void loadRouteDefinitions(final List<String> routes) { try { RoutesDefinition routeDefs = camelContext.loadRoutesDefinition( IOUtils.toInputStream("<routes xmlns=\"http://camel.apache.org/schema/spring\">" + StringUtils.join(routes) + "</routes>", StandardCharsets.UTF_8)); camelContext.addRouteDefinitions(routeDefs.getRoutes()); } catch (Exception e) { LOG.error("While adding route definitions into Camel Context {}", camelContext, e); throw new CamelException(e); } }
private void loadXmlRoutes(ApplicationContext applicationContext, CamelContext camelContext, String directory) throws Exception { String[] parts = directory.split(","); for (String part : parts) { LOG.info("Loading additional Camel XML routes from: {}", part); try { Resource[] xmlRoutes = applicationContext.getResources(part); 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.", part); } } }
@Override public void applyRoutes(CamelContext camelContext) throws Exception { CamelRunner.removeMissingRoutes(camelContext, this.builder.getRouteCollection().getRoutes()); camelContext.addRoutes(this.builder); } }
for (RouteDefinition rd : routesDefinition.getRoutes()) { camelContext.startRoute(rd);
camelContext.addRouteDefinitions(routesDefinition.getRoutes()); is.close(); } catch (Throwable e) {
/** * Create a new route from the given RouteBuilder instance and service name. * @param routeBuilder RouteBuilder instance containing an @Route definition * @param camelContext CamelContext * @param namespace the namespace to append to switchyard:// service URIs * @return the route definition */ public static List<RouteDefinition> createRoute(RouteBuilder routeBuilder, SwitchYardCamelContext camelContext, String namespace) { // Create the route and tell it to create a route try { if (camelContext != null) { routeBuilder.setContext(camelContext); } routeBuilder.configure(); List<RouteDefinition> routes = routeBuilder.getRouteCollection().getRoutes(); if (routes.isEmpty()) { throw CamelComponentMessages.MESSAGES.noRoutesFoundinJavaDSLClass(routeBuilder.getClass().getName()); } return routes; } catch (Exception ex) { throw CamelComponentMessages.MESSAGES.failedToInitializeDSLClass(routeBuilder.getClass().getName(), ex); } }
public void stop(int code) { try { getContext().removeRouteDefinitions(getRouteCollection().getRoutes()); } catch (Exception e) { LOGGER.error("Could not stop route: {}", toString(), e); } }
InputStream routesXml = new ByteArrayInputStream(routePropertyValue.toString().getBytes()); RoutesDefinition loadedRoutes = camelContext.loadRoutesDefinition(routesXml); camelContext.addRouteDefinitions(loadedRoutes.getRoutes());
private void loadFragments(Step step) { if (StepKind.extension != step.getStepKind()) { return; } final StepAction action = step.getAction().filter(StepAction.class::isInstance).map(StepAction.class::cast).get(); if (action.getDescriptor().getKind() == StepAction.Kind.ENDPOINT) { final CamelContext context = getContext(); final String resource = action.getDescriptor().getResource(); if (ObjectHelper.isNotEmpty(resource) && resources.add(resource)) { final Object instance = mandatoryLoadResource(context, resource); final RoutesDefinition definitions = mandatoryConvertToRoutesDefinition(resource, instance); LOGGER.debug("Resolved resource: {} as {}", resource, instance.getClass()); try { context.addRouteDefinitions(definitions.getRoutes()); } catch (Exception e) { throw new IllegalStateException(e); } } } }
routes = processCamelContextElement((CamelContextFactoryBean)obj, camelContext); } else if (obj instanceof RoutesDefinition) { routes = ((RoutesDefinition)obj).getRoutes(); } else if (obj instanceof RouteDefinition) { routes = new ArrayList<RouteDefinition>(1);
try { final RoutesDefinition definition = model.loadRoutesDefinition(this.getClass().getResourceAsStream("/" + routeResource)); model.addRouteDefinitions(definition.getRoutes()); stats.incDeployed(); } catch (Exception e) {
public class ContextStartEventListener extends EventNotifierSupport implements ApplicationContextAware { private ApplicationContext applicationContext; @Override public void setApplicationContext(ApplicationContext applicationContext) { this.applicationContext = applicationContext; } @Override public void notify(EventObject event) throws Exception { if (event instanceof CamelContextStartedEvent) { try { CamelContextStartedEvent startedEvent = (CamelContextStartedEvent) event; DefaultCamelContext context=(DefaultCamelContext)startedEvent.getContext(); Resource[] xmlResources=applicationContext.getResources("classpath*:net/**/route.xml"); for (int i=0;i<xmlResources.length;i++) { InputStream is = xmlResources[i].getInputStream(); RoutesDefinition routes = context.loadRoutesDefinition(is); context.addRouteDefinitions(routes.getRoutes()); } } catch (Throwable ex) { // do something on error } } } ...
RoutesDefinition routesDefinition = camelContext.loadRoutesDefinition(is); for (RouteDefinition rd: routesDefinition.getRoutes()){ camelContext.startRoute(rd);
RoutesDefinition routesDefinition = camelContext.loadRoutesDefinition(is); for (RouteDefinition rd: routesDefinition.getRoutes()){ camelContext.startRoute(rd);
@Override public void run() { try { if (context.getStatus().isSuspended()){ context.resume(); //target.add(CamelWidget.this.form); }else if (!context.getStatus().isStarted()){ clearContext(context); String script = getDocument().field("script"); RoutesDefinition routes = context.loadRoutesDefinition(new ByteArrayInputStream( script.getBytes())); context.addRouteDefinitions(routes.getRoutes()); context.start(); } } catch (Exception e) { LOG.error("Cannot start or resume Camel Context",e); } } }).start();
/** * Creates new Camel routes in route builder. * @param routeBuilder * @return */ public CamelRouteActionBuilder create(RouteBuilder routeBuilder) { CreateCamelRouteAction camelRouteAction = new CreateCamelRouteAction(); try { if (!routeBuilder.getContext().equals(getCamelContext())) { routeBuilder.configureRoutes(getCamelContext()); } else { routeBuilder.configure(); } camelRouteAction.setRoutes(routeBuilder.getRouteCollection().getRoutes()); } catch (Exception e) { throw new CitrusRuntimeException("Failed to configure route definitions with camel context", e); } camelRouteAction.setCamelContext(getCamelContext()); action.setDelegate(camelRouteAction); return this; }
@Test public void testBuilder() throws Exception { IntegrationRuntimeConfiguration configuration = new IntegrationRuntimeConfiguration(); IntegrationRouteBuilder routeBuilder = new IntegrationRouteBuilder(configuration.getConfigurationLocation(), Collections.emptyList()); // initialize routes routeBuilder.configure(); // Dump routes as XML for troubleshooting dumpRoutes(new DefaultCamelContext(), routeBuilder.getRouteCollection()); RoutesDefinition routes = routeBuilder.getRouteCollection(); assertThat(routes.getRoutes()).hasSize(1); RouteDefinition route = routes.getRoutes().get(0); assertThat(route.getInputs()).hasSize(1); assertThat(route.getInputs().get(0)).hasFieldOrPropertyWithValue("uri", "direct:expression"); assertThat(route.getOutputs()).hasSize(4); assertThat(getOutput(route, 0)).isInstanceOf(SetHeaderDefinition.class); assertThat(getOutput(route, 1)).isInstanceOf(SetHeaderDefinition.class); assertThat(getOutput(route, 2)).isInstanceOf(ProcessDefinition.class); assertThat(getOutput(route, 3)).isInstanceOf(PipelineDefinition.class); assertThat(getOutput(route, 3).getOutputs()).hasSize(2); assertThat(getOutput(route, 3, 0)).isInstanceOf(SetHeaderDefinition.class); assertThat(getOutput(route, 3, 1)).isInstanceOf(SplitDefinition.class); assertThat(getOutput(route, 3, 1).getOutputs()).hasSize(2); assertThat(getOutput(route, 3, 1, 0)).isInstanceOf(ProcessDefinition.class); assertThat(getOutput(route, 3, 1, 1)).isInstanceOf(PipelineDefinition.class); assertThat(getOutput(route, 3, 1, 1).getOutputs()).hasSize(3); assertThat(getOutput(route, 3, 1, 1, 0)).isInstanceOf(SetHeaderDefinition.class); assertThat(getOutput(route, 3, 1, 1, 1)).isInstanceOf(ToDefinition.class); assertThat(getOutput(route, 3, 1, 1, 1)).hasFieldOrPropertyWithValue("uri", "mock:expression"); assertThat(getOutput(route, 3, 1, 1, 2)).isInstanceOf(ProcessDefinition.class); }
public EcaRoutesDefinition(RoutesDefinition other) { setRoutes(other.getRoutes()); setIntercepts(other.getIntercepts()); setInterceptFroms(other.getInterceptFroms()); setInterceptSendTos(other.getInterceptSendTos()); setOnExceptions(other.getOnExceptions()); setOnCompletions(other.getOnCompletions()); setCamelContext(other.getCamelContext()); setErrorHandlerBuilder(other.getErrorHandlerBuilder()); }