You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Renato Barros <re...@gmail.com> on 2017/10/21 18:57:37 UTC

Camel JPA + Wildfly Swarm

Hello,

I'm trying to use Camel in Wildfly Swarm and i get the follow exception
when use Camel JPA endpoint:

java.lang.ClassCastException:
com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple
cannot be cast to javax.transaction.TransactionManager


How can i configure the JTA in Swarm to be compatible with Camel JPA.

Here is my code, the project example is here
<https://github.com/renalexster/wildfly-swarm-camel-jpa>:



================== pom.xml ==================

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.swarm_cdi</groupId>
  <artifactId>swarm_cdi</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <build>
    <finalName>swarm_cdi</finalName>
    <plugins>
      <plugin>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>wildfly-swarm-plugin</artifactId>
        <version>${version.wildfly-swarm}</version>
        <executions>
          <execution>
            <goals>
              <goal>package</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  <properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <version.wildfly-swarm>2017.10.0</version.wildfly-swarm>
  </properties>
  <dependencies>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>camel-cdi</artifactId>
    </dependency>
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>camel-undertow</artifactId>
    </dependency>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <version>1.4.196</version>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>org.wildfly.swarm</groupId>
      <artifactId>camel-jpa</artifactId>
    </dependency>
  </dependencies>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.wildfly.swarm</groupId>
        <artifactId>bom-all</artifactId>
        <version>${version.wildfly-swarm}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
</project>

=============================================




================ RESTRoute.java ===============
package org.swarm_cdi.beans;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.cdi.ContextName;
import org.slf4j.Logger;

@ApplicationScoped
@ContextName("rest")
public class RESTRoute extends RouteBuilder {
private static final long serialVersionUID = 1L;
@Inject
private Logger logger;

@Override
public void configure() throws Exception {
// TODO Auto-generated method stub
logger.info("############### CONFIGURE CAMEL ROUTE ###############");
restConfiguration().component("undertow").contextPath("/hello");
rest("/ping").get().produces("text/plain").route().setBody()
.constant("Hello");
rest("/person").get().produces("application/json").
route().enrich("jpa://org.swarm_cdi.model.Person").endRest();
}
}
=============================================




=============== persistence.xml =================
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <persistence xmlns="
http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/
2001/XMLSchema-instance" version="2.1" xsi:schemaLocation="http://
xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/
persistence/persistence_2_1.xsd"> <persistence-unit name="camel"
transaction-type="JTA"> <description>Forge Persistence Unit</description>
<jta-data-source>java:jboss/datasources/MyDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes> <properties>
<property name="javax.persistence.schema-generation.database.action"
value="drop-and-create"/> <property name="javax.persistence.
schema-generation.scripts.action" value="drop-and-create"/> <property
name="javax.persistence.schema-generation.scripts.create-target"
value="swarm_cdiCreate.ddl"/> <property name="javax.persistence.
schema-generation.scripts.drop-target" value="swarm_cdiDrop.ddl"/>
</properties> </persistence-unit> </persistence>
=============================================

Re: Camel JPA + Wildfly Swarm

Posted by Zoran Regvart <zo...@regvart.com>.
Hi Renato,
this looks to me like your archive contains classes that are already
present on the servers classpath. Perhaps you can try comparing your
code with one of the examples from the wildfly-camel, there is a JPA
example in the GitHub repository[1], and one in the in the
wildfly-swarm[2] repository,

zoran

[1] https://github.com/wildfly-extras/wildfly-camel-examples/tree/master/camel-jpa
[2] https://github.com/wildfly-swarm/wildfly-swarm-examples/tree/master/camel/camel-jpa

On Sat, Oct 21, 2017 at 8:57 PM, Renato Barros <re...@gmail.com> wrote:
> Hello,
>
> I'm trying to use Camel in Wildfly Swarm and i get the follow exception
> when use Camel JPA endpoint:
>
> java.lang.ClassCastException:
> com.arjuna.ats.internal.jta.transaction.jts.TransactionManagerImple
> cannot be cast to javax.transaction.TransactionManager
>
>
> How can i configure the JTA in Swarm to be compatible with Camel JPA.


-- 
Zoran Regvart