public void testFromRestModel() throws Exception {
    assertEquals(getExpectedNumberOfRoutes(), context.getRoutes().size());

    assertEquals(2, context.getRestDefinitions().size());
    RestDefinition rest = context.getRestDefinitions().get(0);
    assertNotNull(rest);
    assertEquals("/say/hello", rest.getUri());
    assertEquals(1, rest.getVerbs().size());
    ToDefinition to =
        assertIsInstanceOf(
            ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(1));
    assertEquals("mock:hello", to.getUri());

    rest = context.getRestDefinitions().get(1);
    assertNotNull(rest);
    assertEquals("/say/bye", rest.getUri());
    assertEquals(2, rest.getVerbs().size());
    assertEquals("application/json", rest.getVerbs().get(0).getConsumes());
    to =
        assertIsInstanceOf(
            ToDefinition.class, rest.getVerbs().get(0).getRoute().getOutputs().get(1));
    assertEquals("mock:bye", to.getUri());

    // the rest becomes routes and the input is a seda endpoint created by the
    // DummyRestConsumerFactory
    getMockEndpoint("mock:update").expectedMessageCount(1);
    template.sendBody("seda:post-say-bye", "I was here");
    assertMockEndpointsSatisfied();

    String out = template.requestBody("seda:get-say-hello", "Me", String.class);
    assertEquals("Hello World", out);
    String out2 = template.requestBody("seda:get-say-bye", "Me", String.class);
    assertEquals("Bye World", out2);
  }
Ejemplo n.º 2
0
 public static String getExchangePattern(ToDefinition input) {
   String pattern = input.getPattern() != null ? input.getPattern().name() : null;
   if (Strings2.isEmpty(pattern)) {
     return null;
   }
   return pattern;
 }
Ejemplo n.º 3
0
 public static String getUri(ToDefinition input) {
   String key = input.getUri();
   if (Strings2.isEmpty(key)) {
     String ref = input.getRef();
     if (!Strings2.isEmpty(ref)) {
       return "ref:" + ref;
     }
   }
   return key;
 }
  public Processor wrap(RouteContext routeContext, Processor processor) {
    RouteDefinition routeDef = routeContext.getRoute();

    ToDefinition toDrools = getDroolsNode(routeDef);

    Processor returnedProcessor;
    if (toDrools != null) {
      returnedProcessor = new DroolsProcess(toDrools.getUri(), processor);
    } else {
      returnedProcessor = processor; // new DroolsClientProcessor( processor );
    }
    return returnedProcessor;
  }
 private static final void addNamespaceParameterTo(
     ProcessorDefinition<?> procDef, String namespace) {
   if (procDef instanceof ToDefinition) {
     ToDefinition toDef = (ToDefinition) procDef;
     String old_uri = toDef.getUri();
     String new_uri = addNamespaceParameter(old_uri, namespace);
     toDef.setUri(new_uri);
     setEndpointUri(toDef.getEndpoint(), namespace);
   }
   for (ProcessorDefinition<?> procDefChild : procDef.getOutputs()) {
     addNamespaceParameterTo(procDefChild, namespace);
   }
 }
 private ToDefinition getDroolsNode(ProcessorDefinition nav) {
   if (!nav.getOutputs().isEmpty()) {
     List<ProcessorDefinition> children = nav.getOutputs();
     for (ProcessorDefinition child : children) {
       if (child instanceof ToDefinition) {
         ToDefinition to = (ToDefinition) child;
         if (to.getUri().trim().startsWith("drools:")) {
           return to;
         }
       }
       getDroolsNode(child);
     }
   }
   return null;
 }
  public static void augmentNodes(
      RouteContext routeContext, ProcessorDefinition<?> nav, Set visited) {
    if (!nav.getOutputs().isEmpty()) {

      List<ProcessorDefinition> outputs = nav.getOutputs();
      for (int i = 0; i < outputs.size(); i++) {
        ProcessorDefinition child = outputs.get(i); // it.next();
        if (child instanceof ToDefinition) {
          ToDefinition to = (ToDefinition) child;
          if (to.getUri().startsWith("cxfrs") && !visited.contains(to)) {
            BeanDefinition beanDef = new BeanDefinition();
            beanDef.setBeanType(PreCxfrs.class.getName());
            outputs.add(i, beanDef); // insert before cxfrs
            beanDef = new BeanDefinition();
            beanDef.setBeanType(PostCxfrs.class.getName());
            outputs.add(i + 2, beanDef); // insert after cxfrs
            i = i + 2; // adjust for the two inserts
          } else if (to.getUri().startsWith("cxf") && !visited.contains(to)) {
            BeanDefinition beanDef = new BeanDefinition();
            beanDef.setBeanType(PreCxfSoapProcessor.class.getName());
            outputs.add(i, beanDef); // insert before cxf
            beanDef = new BeanDefinition();
            beanDef.setBeanType(PostCxfSoapProcessor.class.getName());
            outputs.add(i + 2, beanDef); // insert after cxf
            i = i + 2; // adjust for the two inserts
            augmented = true;
          }
        } else if (child instanceof MarshalDefinition) {
          MarshalDefinition m = (MarshalDefinition) child;
          DataFormatDefinition dformatDefinition = m.getDataFormatType();
          dformatDefinition = processDataFormatType(routeContext, m.getRef(), dformatDefinition);
          m.setDataFormatType(dformatDefinition); // repoint the marshaller, if it was cloned
        } else if (child instanceof UnmarshalDefinition) {
          UnmarshalDefinition m = (UnmarshalDefinition) child;
          DataFormatDefinition dformatDefinition = m.getDataFormatType();
          dformatDefinition = processDataFormatType(routeContext, m.getRef(), dformatDefinition);
          m.setDataFormatType(dformatDefinition); // repoint the marshaller, if it was cloned
        }
      }

      for (Iterator<ProcessorDefinition> it = nav.getOutputs().iterator(); it.hasNext(); ) {
        ProcessorDefinition child = it.next();
        augmentNodes(routeContext, child, visited);
      }
    }
  }