Пример #1
0
 public void start() throws Exception {
   if (context.isSuspended()) {
     context.resume();
   } else {
     context.start();
   }
 }
Пример #2
0
  @Before
  public void setUp() throws Exception {

    // We replace the 'from' web service endpoint with a direct endpoint we call in our test
    context
        .getRouteDefinition("CriminalHistoryUpdateReportingServiceHandlerRoute")
        .adviceWith(
            context,
            new AdviceWithRouteBuilder() {
              @Override
              public void configure() throws Exception {
                // The line below allows us to bypass CXF and send a message directly into the route
                replaceFromWith("direct:criminalHistoryUpdatedReportingService");
                mockEndpoints("log:org.ojbc.intermediaries.crimhistoryupdate*");
              }
            });

    // We mock the web service endpoints here
    context
        .getRouteDefinition("callNotificationBrokerRoute")
        .adviceWith(
            context,
            new AdviceWithRouteBuilder() {
              @Override
              public void configure() throws Exception {

                // We mock the notification broker endpoint
                mockEndpointsAndSkip("cxf:bean:notificationBrokerService*");
              }
            });

    context.start();
  }
  @Test
  public void shouldDLQOrginalHandler() throws Exception {

    ModelCamelContext context = new DefaultCamelContext();
    context.setTracing(true);
    ProducerTemplate pt = context.createProducerTemplate();
    context.addRoutes(
        new RouteBuilder() {

          @Override
          public void configure() throws Exception {
            // will use original
            ErrorHandlerBuilder a =
                deadLetterChannel("seda:dead")
                    .maximumRedeliveries(1)
                    .redeliveryDelay(300)
                    .logStackTrace(false)
                    .useOriginalMessage()
                    .logHandled(false);

            from("seda:start")
                .errorHandler(a)
                .log(LoggingLevel.INFO, "myCamel", "==== ${body}")
                .bean(SampleErrorBean.class)
                .bean(ChangeBody.class)
                .bean(ErrorBean.class)
                .bean(SampleErrorBean.class)
                .transform(constant("ok"));
            from("seda:dead")
                .bean(FailureBean.class)
                .process(
                    exchange -> {
                      counterA.incrementAndGet();
                      Throwable e =
                          exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Throwable.class);
                      log.info("+++  properties :  {}", exchange.getProperties());
                      log.info("+++  body :  {}", exchange.getIn().getBody());
                      log.info("+++  headers  :  {}", exchange.getIn().getHeaders());
                      log.info("+++  exception Processor : {}", e);
                      log.info(
                          "+++ counterA :  {} , header : {}",
                          counterA.get(),
                          exchange.getProperty("CamelExceptionCaught"));
                    })
                .convertBodyTo(String.class)
                .bean(SampleErrorBean.class);
          }
        });
    context.start();
    String result = (String) pt.requestBody("seda:start", "test");
    Assertions.assertThat(result).isEqualTo("test");
    Thread.sleep(3000);
  }
  @Test
  public void shouldDLQHandler() throws Exception {

    ModelCamelContext context = new DefaultCamelContext();

    ProducerTemplate pt = context.createProducerTemplate();
    context.addRoutes(
        new RouteBuilder() {

          @Override
          public void configure() throws Exception {
            ErrorHandlerBuilder b =
                deadLetterChannel("direct:dead")
                    .maximumRedeliveries(3)
                    .redeliveryDelay(300)
                    .logStackTrace(true)
                    .logHandled(true);
            from("seda:start")
                .errorHandler(b)
                .log(LoggingLevel.INFO, "myCamel", "==== ${body}")
                .bean(SampleErrorBean.class)
                .bean(ChangeBody.class)
                .bean(ErrorBean.class)
                .bean(SampleErrorBean.class)
                .transform(constant("ok"));
            from("direct:dead")
                .bean(FailureBean.class)
                .process(new ErrorLogProcessor())
                .convertBodyTo(String.class)
                .bean(SampleErrorBean.class);
          }
        });
    context.start();
    String result = (String) pt.requestBody("seda:start", "test");
    Assertions.assertThat(result).isEqualTo("change  :: test");
    Thread.sleep(3000);
  }
Пример #5
0
 public void restart() throws Exception {
   context.stop();
   context.start();
 }