コード例 #1
0
  @Before
  public void setUp() throws Exception {
    log.info("********************************************************************************");
    log.info("Testing: " + getTestMethodName() + "(" + getClass().getName() + ")");
    log.info("********************************************************************************");

    log.debug("setUp test");
    if (!useJmx()) {
      disableJMX();
    } else {
      enableJMX();
    }

    context = createCamelContext();
    assertValidContext(context);

    // reduce default shutdown timeout to avoid waiting for 300 seconds
    context.getShutdownStrategy().setTimeout(getShutdownTimeout());

    // set debugger
    context.setDebugger(new DefaultDebugger());
    context.getDebugger().addBreakpoint(breakpoint);
    // note: when stopping CamelContext it will automatic remove the breakpoint

    template = context.createProducerTemplate();
    template.start();
    consumer = context.createConsumerTemplate();
    consumer.start();

    // enable auto mocking if enabled
    String pattern = isMockEndpoints();
    if (pattern != null) {
      context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern));
    }

    postProcessTest();

    if (isUseRouteBuilder()) {
      RouteBuilder[] builders = createRouteBuilders();
      for (RouteBuilder builder : builders) {
        log.debug("Using created route builder: " + builder);
        context.addRoutes(builder);
      }
      startCamelContext();
      log.debug("Routing Rules are: " + context.getRoutes());
    } else {
      log.debug("Using route builder from the created context: " + context);
    }
    log.debug("Routing Rules are: " + context.getRoutes());
  }
コード例 #2
0
ファイル: ClientBean.java プロジェクト: mcelio/work-02
  public void pollCurrentLog() {
    try {
      CamelContext camelContext = new DefaultCamelContext();
      camelContext.addComponent(
          "jms",
          org.apache.activemq.camel.component.ActiveMQComponent.activeMQComponent(
              "tcp://localhost:61616"));
      ConsumerTemplate consumerTemplate = camelContext.createConsumerTemplate();
      Message message = consumerTemplate.receive("jms:queue:maven-logs").getIn();

      if (message != null && message.getBody() != null) {
        if (currentLog == null) {
          currentLog = message.getBody().toString();
        } else {
          currentLog += "\n" + message.getBody();
        }
      }
    } catch (Exception e) {
      logger.error("Error:", e);
    }
  }
コード例 #3
0
ファイル: KuraRouter.java プロジェクト: jblancoperez/camel
  @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("kura.camel");
      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;
    }
  }