@Override
  public void configure() throws Exception {

    // [ENTESB-3281] Wildfly-Camel build fails on OpenJDK
    String vmname = System.getProperty("java.vm.name");
    if (vmname.contains("OpenJDK")) return;

    // Configure our JaxbDataFormat to point at our 'model' package
    JaxbDataFormat jaxbDataFormat = new JaxbDataFormat();
    jaxbDataFormat.setContextPath(Customer.class.getPackage().getName());

    EntityManagerFactory entityManagerFactory = em.getEntityManagerFactory();

    // Configure a JtaTransactionManager by looking up the JBoss transaction manager from JNDI
    JtaTransactionManager transactionManager = new JtaTransactionManager();
    transactionManager.setUserTransaction(userTransaction);
    transactionManager.afterPropertiesSet();

    // Configure the JPA endpoint to use the correct EntityManagerFactory and JtaTransactionManager
    JpaEndpoint jpaEndpoint = new JpaEndpoint();
    jpaEndpoint.setCamelContext(getContext());
    jpaEndpoint.setEntityType(Customer.class);
    jpaEndpoint.setEntityManagerFactory(entityManagerFactory);
    jpaEndpoint.setTransactionManager(transactionManager);

    /*
     *  Simple route to consume customer record files from directory input/customers,
     *  unmarshall XML file content to a Customer entity and then use the JPA endpoint
     *  to persist the it to the 'ExampleDS' datasource (see standalone.camel.xml for datasource config).
     */
    from("file://{{jboss.server.data.dir}}/customers")
        .unmarshal(jaxbDataFormat)
        .to(jpaEndpoint)
        .to("log:input?showAll=true");
  }
  @Override
  public void configure() throws Exception {
    /**
     * Create an instance of the Camel JmsComponent and configure it to support JMS transactions.
     */
    JmsComponent jmsComponent =
        JmsComponent.jmsComponentTransacted(connectionFactory, transactionManager);
    getContext().addComponent("jms", jmsComponent);

    /** Create an instance of the Camel JpaComponent and configure it to support transactions. */
    JpaComponent jpaComponent = new JpaComponent();
    jpaComponent.setEntityManagerFactory(entityManager.getEntityManagerFactory());
    jpaComponent.setTransactionManager(transactionManager);
    getContext().addComponent("jpa", jpaComponent);

    /** Configure JAXB so that it can discover model classes. */
    JaxbDataFormat jaxbDataFormat = new JaxbDataFormat();
    jaxbDataFormat.setContextPath(Order.class.getPackage().getName());

    /**
     * Configure a simple dead letter strategy. Whenever an IllegalStateException is encountered
     * this takes care of rolling back the JMS and JPA transactions. The problem message is sent to
     * the WildFly dead letter JMS queue (DLQ).
     */
    onException(IllegalStateException.class)
        .maximumRedeliveries(1)
        .handled(true)
        .to("jms:queue:DLQ")
        .markRollbackOnly();

    /**
     * This route consumes XML files from JBOSS_HOME/standalone/data/orders and sends the file
     * content to JMS destination OrdersQueue.
     */
    from("file:{{jboss.server.data.dir}}/orders").transacted().to("jms:queue:OrdersQueue");

    /**
     * This route consumes messages from JMS destination OrdersQueue, unmarshalls the XML message
     * body using JAXB to an Order entity object. The order is then sent to the JPA endpoint for
     * persisting within an in-memory database.
     *
     * <p>Whenever an order quantity greater than 10 is encountered, the route throws an
     * IllegalStateException which forces the JMS / JPA transaction to be rolled back and the
     * message to be delivered to the dead letter queue.
     */
    from("jms:queue:OrdersQueue")
        .unmarshal(jaxbDataFormat)
        .to("jpa:Order")
        .choice()
        .when(simple("${body.quantity} > 10"))
        .log("Order quantity is greater than 10 - rolling back transaction!")
        .throwException(new IllegalStateException())
        .otherwise()
        .log("Order processed successfully");
  }
  /**
   * Clones the passed JaxbDataFormat and then augments it with with Drools related namespaces
   *
   * @param jaxbDataFormat
   * @return
   */
  public static JaxbDataFormat augmentJaxbDataFormatDefinition(JaxbDataFormat jaxbDataFormat) {
    Set<String> set = new HashSet<String>();

    for (String clsName : DroolsJaxbHelperProviderImpl.JAXB_ANNOTATED_CMD) {
      set.add(clsName.substring(0, clsName.lastIndexOf('.')));
    }

    StringBuilder sb = new StringBuilder();
    sb.append(jaxbDataFormat.getContextPath());
    sb.append(":");
    for (String pkgName : set) {
      sb.append(pkgName);
      sb.append(':');
    }

    jaxbDataFormat.setContextPath(sb.toString());
    return jaxbDataFormat;
  }
Пример #4
0
  @Override
  public void configure() throws Exception {

    JaxbDataFormat jaxbPatient = new JaxbDataFormat();
    jaxbPatient.setContextPath("com.customer.app");
    jaxbPatient.setPrettyPrint(false);

    from("direct:inbound")
        .marshal(jaxbPatient)
        .convertBodyTo(String.class)
        .to("log:inboundRoute?showAll=true&multiline=true")
        .log(LoggingLevel.DEBUG, "Sending person to JMS: ${body}")
        .to(
            "mq:q.empi.deim.in") // Let's make a sync route here, just see what we get back from the
                                 // integration-test-server
        // .setBody(simple("<response>OK</response>"))
        .transform(body());
    ;
  }