I am trying to create a resource adapter (outbound) and deploy it in wildfly-preview-26.0.1.Final.
I have created a rar file which is deployed successfully (in the server logs I can see the tracking messages).
However, when I try to use it in a client, I get an error
@Path("ping")
public class JavaEE8Resource {
@Resource(name = "java:/eis/Barier")
private BarierConnectionFactory cf;
@GET
public Response ping(){
Map<String, Object> map = new HashMap<>();
map.put("origin", cf);
return Response
.ok(map.toString())
.build();
}
}
UT005023: Exception handling request to /test/api/v1/ping: org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalArgumentException: Can not set org.sample.test.api.BarierConnectionFactory field org.sample.test.war.resources.JavaEE8Resource.cf to org.sample.test.ra.out.BarierConnectionFactoryImpl
if change customer so
@Path("ping")
public class JavaEE8Resource {
@Resource(name = "java:/eis/Barier")
private Object cf;
@GET
public Response ping(){
Map<String, Object> map = new HashMap<>();
map.put("origin", cf);
return Response
.ok(map.toString())
.build();
}
}
I receive
{origin=org.sample.test.ra.out.BarierConnectionFactoryImpl@4f17b2db}
but when I try to cast from Object I get
@Path("ping")
public class JavaEE8Resource {
@Resource(name = "java:/eis/Barier")
private Object cf;
@GET
public Response ping(){
Map<String, Object> map = new HashMap<>();
map.put("origin", (BarierConnectionFactory) cf);
return Response
.ok(map.toString())
.build();
}
}
java.lang.ClassCastException: class org.sample.test.ra.out.BarierConnectionFactoryImpl cannot be cast to class org.sample.test.api.BarierConnectionFactory (org.sample.test.ra.out.BarierConnectionFactoryImpl is in unnamed module of loader 'deployment.barier.rar' @7cf3ac33; org.sample.test.api.BarierConnectionFactory is in unnamed module of loader 'deployment.test-war-1.0-SNAPSHOT.war' @412d2a9e)
The interface and implementation are separated into separate modules (jar files).
--- Update ---
The problem is that both modules include a module with the public interface (api) declarations.
I solved the problem by removing the corresponding module from the war file (which, logically, led to a ClassDefNotFoundException) so I used jboss-deployment-structure.xml in which I specified a dependency on the module with the resource adapter
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="deployment.barier.rar"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
However, this approach requires knowing the module name with the resource adapter. For now this is not a problem, but I wish I could find a cleaner solution. So, assume the question is relevant.