@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");
  }
Esempio n. 2
0
  public static void main(String[] args) {
    try {
      String serverAddress = args[0];
      int port = Integer.parseInt(args[1]);
      String localAddress = args[2];

      /** create a httpServer */
      System.out.println("Starting HTTP server");
      HttpServer httpServer = HttpServer.create(new InetSocketAddress(80), 0);
      httpServer.createContext("/", new HttpFileHandler());
      httpServer.setExecutor(null);
      httpServer.start();

      System.out.println("Creating RMI Registry");
      Registry registry = LocateRegistry.createRegistry(1099);
      Reference reference =
          new javax.naming.Reference(
              "client.ExportObject", "client.ExportObject", "http://" + localAddress + "/");
      ReferenceWrapper referenceWrapper = new com.sun.jndi.rmi.registry.ReferenceWrapper(reference);
      registry.bind("Object", referenceWrapper);

      System.out.println("Connecting to server " + serverAddress + ":" + port);
      Socket socket = new Socket(serverAddress, port);
      System.out.println("Connected to server");
      String jndiAddress = "rmi://" + localAddress + ":1099/Object";

      org.springframework.transaction.jta.JtaTransactionManager object =
          new org.springframework.transaction.jta.JtaTransactionManager();
      object.setUserTransactionName(jndiAddress);

      System.out.println("Sending object to server...");
      ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
      objectOutputStream.writeObject(object);
      objectOutputStream.flush();
      /*
      while(true) {
      	Thread.sleep(1000);
      }
      */
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 /**
  * Set the Spring {@link JtaTransactionManager} or the JTA {@link TransactionManager} to be used
  * with Hibernate, if any. Allows for using a Spring-managed transaction manager for Hibernate 4's
  * session and cache synchronization, with the "hibernate.transaction.jta.platform" automatically
  * set to it. Also sets "hibernate.transaction.factory_class" to {@link CMTTransactionFactory},
  * instructing Hibernate to interact with externally managed transactions.
  *
  * <p>A passed-in Spring {@link JtaTransactionManager} needs to contain a JTA {@link
  * TransactionManager} reference to be usable here, except for the WebSphere case where we'll
  * automatically set {@code WebSphereExtendedJtaPlatform} accordingly.
  *
  * <p>Note: If this is set, the Hibernate settings should not contain a JTA platform setting to
  * avoid meaningless double configuration.
  */
 public LocalSessionFactoryBuilder setJtaTransactionManager(Object jtaTransactionManager) {
   Assert.notNull(jtaTransactionManager, "Transaction manager reference must not be null");
   if (jtaTransactionManager instanceof JtaTransactionManager) {
     boolean webspherePresent =
         ClassUtils.isPresent("com.ibm.wsspi.uow.UOWManager", getClass().getClassLoader());
     if (webspherePresent) {
       getProperties()
           .put(
               AvailableSettings.JTA_PLATFORM,
               ConfigurableJtaPlatform.getJtaPlatformBasePackage()
                   + "internal.WebSphereExtendedJtaPlatform");
     } else {
       JtaTransactionManager jtaTm = (JtaTransactionManager) jtaTransactionManager;
       if (jtaTm.getTransactionManager() == null) {
         throw new IllegalArgumentException(
             "Can only apply JtaTransactionManager which has a TransactionManager reference set");
       }
       getProperties()
           .put(
               AvailableSettings.JTA_PLATFORM,
               new ConfigurableJtaPlatform(
                       jtaTm.getTransactionManager(),
                       jtaTm.getUserTransaction(),
                       jtaTm.getTransactionSynchronizationRegistry())
                   .getJtaPlatformProxy());
     }
   } else if (jtaTransactionManager instanceof TransactionManager) {
     getProperties()
         .put(
             AvailableSettings.JTA_PLATFORM,
             new ConfigurableJtaPlatform((TransactionManager) jtaTransactionManager, null, null)
                 .getJtaPlatformProxy());
   } else {
     throw new IllegalArgumentException(
         "Unknown transaction manager type: " + jtaTransactionManager.getClass().getName());
   }
   getProperties().put(AvailableSettings.TRANSACTION_STRATEGY, new CMTTransactionFactory());
   return this;
 }