@Test
  public void testFilePollerB() throws Exception {
    String expected = "xxx";
    final MockEndpoint mockEndpoint = getMockEndpoint("mock:" + routeATo);
    cc.getRouteDefinitions()
        .get(0)
        .adviceWith(
            cc,
            new RouteBuilder() {
              @Override
              public void configure() throws Exception {
                // intercept sending to mock:foo and do something else
                interceptSendToEndpoint(routeATo).to(mockEndpoint);
              }
            });

    mockEndpoint.expectedBodiesReceived(expected);

    Endpoint ep = cc.getEndpoint(routeAFrom);
    Assert.assertNotNull(ep);
    ProducerTemplate pt = cc.createProducerTemplate();
    pt.start();
    pt.sendBody(ep, expected);

    assertMockEndpointsSatisfied();
  }
  @Test
  public void testNotTooOldFilter() throws Exception {
    fakeFtpServer.start();
    int port = fakeFtpServer.getServerControlPort();
    context
        .getRouteDefinitions()
        .get(0)
        .adviceWith(
            context,
            new AdviceWithRouteBuilder() {
              @Override
              public void configure() throws Exception {
                replaceFromWith(
                    "ftp://[email protected]:"
                        + port
                        + "?password=password&filter=#notTooOld&passiveMode=true");
                weaveByType(ToDefinition.class).selectFirst().replace().to("mock:end");
              }
            });
    MockEndpoint end = context.getEndpoint("mock:end", MockEndpoint.class);
    end.expectedMessageCount(1);

    end.assertIsSatisfied();

    // Make sure that the received file has the correct file name
    String fileName =
        (String) end.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_NAME_ONLY);
    assertEquals(fileName, "DMI1.nc");

    fakeFtpServer.stop();
  }
 private void dumpCamelContext(String msg) {
   LOGGER.debug("\n\n***************  START: " + msg + "  *****************");
   List<RouteDefinition> routeDefinitions = camelContext.getRouteDefinitions();
   if (routeDefinitions != null) {
     LOGGER.debug("Number of routes = " + routeDefinitions.size());
     for (RouteDefinition routeDef : routeDefinitions) {
       String routeId = routeDef.getId();
       LOGGER.debug("route ID = " + routeId);
       List<FromDefinition> routeInputs = routeDef.getInputs();
       if (routeInputs.isEmpty()) {
         LOGGER.debug("routeInputs are EMPTY");
       } else {
         for (FromDefinition fromDef : routeInputs) {
           LOGGER.debug("route input's URI = " + fromDef.getUri());
         }
       }
       ServiceStatus routeStatus = camelContext.getRouteStatus(routeId);
       if (routeStatus != null) {
         LOGGER.debug("Route ID " + routeId + " is started = " + routeStatus.isStarted());
       } else {
         LOGGER.debug("routeStatus is NULL for routeId = " + routeId);
       }
     }
   }
   LOGGER.debug("***************  END: " + msg + "  *****************\n\n");
 }
 private void startRoutes() {
   LOGGER.trace("ENTERING: startRoutes");
   List<RouteDefinition> routeDefinitions = camelContext.getRouteDefinitions();
   for (RouteDefinition routeDef : routeDefinitions) {
     startRoute(routeDef);
   }
   LOGGER.trace("EXITING: startRoutes");
 }
Example #5
0
  public String dumpRoutesAsXml() 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);
    return ModelHelper.dumpModelAsXml(context, def);
  }
  @Test
  public void testIdempotent() throws Exception {
    String uri = "file:target/test-classes/idempotent?idempotent=true&delay=10";
    context
        .getRouteDefinitions()
        .get(1)
        .adviceWith(
            context,
            new AdviceWithRouteBuilder() {
              @Override
              public void configure() throws Exception {
                replaceFromWith(uri);
                weaveByType(ToDefinition.class).selectFirst().replace().to("mock:endpoint");
              }
            });
    MockEndpoint end = context.getEndpoint("mock:endpoint", MockEndpoint.class);
    end.expectedMessageCount(1);

    producer.sendBodyAndHeader(
        "file://target/test-classes/idempotent", Exchange.FILE_NAME, "FCOO1.nc");

    end.assertIsSatisfied();

    String fileName =
        (String) end.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_NAME_ONLY);
    assertEquals(fileName, "FCOO1.nc");

    // reset the mock
    end.reset();
    end.expectedMessageCount(0);

    // move file back
    File file = new File("target/test-classes/idempotent/.camel/FCOO1.nc");
    File renamed = new File("target/test-classes/idempotent/FCOO1.nc");
    file.renameTo(renamed);

    producer.sendBodyAndHeader(
        "file://target/test-classes/idempotent", Exchange.FILE_NAME, "FCOO1.nc");

    // let some time pass to let the consumer try to consume even though it cannot
    Thread.sleep(100);
    end.assertIsSatisfied();

    FileEndpoint fe = context.getEndpoint(uri, FileEndpoint.class);
    assertNotNull(fe);

    // Make sure that there are no incoming messages
    MemoryIdempotentRepository repo = (MemoryIdempotentRepository) fe.getInProgressRepository();
    assertEquals("Should be no in-progress files", 0, repo.getCacheSize());
  }
  private void removeRoutes() {
    LOGGER.trace("ENTERING: stopRoutes");
    List<RouteDefinition> routeDefinitions = camelContext.getRouteDefinitions();
    for (RouteDefinition routeDef : routeDefinitions) {
      try {
        // Only remove routes that this Content Directory Monitor created
        // (since same camelContext shared across all ContentDirectoryMonitors
        // this is necessary)
        if (isMyRoute(routeDef.getId())) {
          LOGGER.trace("Stopping route with ID = " + routeDef.getId());
          camelContext.stopRoute(routeDef); // DEPRECATED
          //                    camelContext.stopRoute(routeDef.getId());
          boolean status = camelContext.removeRoute(routeDef.getId());
          LOGGER.trace("Status of removing route " + routeDef.getId() + " is " + status);
          camelContext.removeRouteDefinition(routeDef);
        }
      } catch (Exception e) {
        LOGGER.warn("Unable to stop Camel route with route ID = " + routeDef.getId(), e);
      }
    }

    LOGGER.trace("EXITING: stopRoutes");
  }
 public List<RouteDefinition> getRouteDefinitions() {
   return camelContext.getRouteDefinitions();
 }