@PostConstruct public void addRouteDefinitions() throws Exception { if (ObjectHelper.isNotEmpty(definitions)) { context.addRouteDefinitions(definitions); } } }
private void addRouteDefinitions(List<RouteDefinition> routeDefinitions) { try { camelContext.addRouteDefinitions(routeDefinitions); } catch (Exception e) { throw new RuntimeCamelException(e); } } }
@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 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); } } }
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); } } } }
private void loadXmlRests(ApplicationContext applicationContext, CamelContext camelContext, String directory) throws Exception { String[] parts = directory.split(","); for (String part : parts) { LOG.info("Loading additional Camel XML rests from: {}", part); try { final Resource[] xmlRests = applicationContext.getResources(part); for (final Resource xmlRest : xmlRests) { final RestsDefinition xmlDefinitions = camelContext.loadRestsDefinition(xmlRest.getInputStream()); camelContext.addRestDefinitions(xmlDefinitions.getRests()); for (final RestDefinition xmlDefinition : xmlDefinitions.getRests()) { final List<RouteDefinition> routeDefinitions = xmlDefinition.asRouteDefinition(camelContext); camelContext.addRouteDefinitions(routeDefinitions); } } } catch (FileNotFoundException e) { LOG.debug("No XML rests found in {}. Skipping XML rests detection.", part); } } }
@Override public void applyRoutes(final CamelContext camelContext) throws Exception { final RoutesDefinition routes = getRoutes(camelContext); removeMissingRoutes(camelContext, routes.getRoutes()); camelContext.addRouteDefinitions(routes.getRoutes()); }
@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();
private boolean addRouteToContext(Bean<?> routeBean, Bean<?> contextBean, BeanManager manager, AfterDeploymentValidation adv) { try { CamelContext context = getReference(manager, CamelContext.class, contextBean); try { Object route = getReference(manager, Object.class, routeBean); if (route instanceof RoutesBuilder) { context.addRoutes((RoutesBuilder) route); } else if (route instanceof RouteContainer) { context.addRouteDefinitions(((RouteContainer) route).getRoutes()); } else { throw new IllegalArgumentException( "Invalid routes type [" + routeBean.getBeanClass().getName() + "], " + "must be either of type RoutesBuilder or RouteContainer!"); } return true; } catch (Exception cause) { adv.addDeploymentProblem( new InjectionException( "Error adding routes of type [" + routeBean.getBeanClass().getName() + "] " + "to Camel context [" + context.getName() + "]", cause)); } } catch (Exception exception) { adv.addDeploymentProblem(exception); } return false; } }