I've the following problem:
I need to use an EJB Remote from a class that implements JavaDelegate of Activity (alfresco).
This happens when my Work Flow arrives at a ServiceTask (I'm using "Task Type": ExpressionDelegate but it also happens with "Task Type": Class), this task uses a FooDelegate and in this class it contains an EJB that I can not use it, it always gives me the NullPointerException error when I use the EJB.
In Properties of the Service Task is:
But also used "Task Type: Class"
My code of HelloWorldBean is:
@Stateless
public class DemoImpl implements JavaDelegate {
@EJB(name = "FooServ")
private FooInterface fooServ;
@Override
public void execute(DelegateExecution execute) throws Exception {
System.out.println(">>>> hello world my name is " + fooServ.getNameDefault() + " <<<<");
}
}
in my file "Activiti.cfg.xml" it has this:
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
...
..
<bean id="HelloWordBean" class="com.development.workflow.HelloWordClass"/>
<jee:remote-slsb id="FooServ" resource-ref="false" business-interface="com.production.FooInterface" jndi-name="java:global/production-ejb/FooServ" />
..
...
</beans>
I also declare my remote ejb in the jboss-web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="8.0" xmlns="http://www.jboss.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/schema/jbossas/jboss-web_8_0.xsd">
<context-root>/demo</context-root>
<virtual-host>demo-host</virtual-host>
<security-domain>demo-realm</security-domain>
<resource-ref>
<res-ref-name>jdbc/demo</res-ref-name>
<jndi-name>java:/platform/jdbc/demo-flow</jndi-name>
</resource-ref>
<ejb-ref-name>FooServ</ejb-ref-name>
<jndi-name>java:/production/FooServ</jndi-name>
</ejb-ref>
</jboss-web>
As you can see, declare in the two xml files the FooServ Remote EJB, but I can not get it to work, I always get the JavaNullPointerException error in the line where I use the Remote EJB.
The code of my EJB Remote is:
package com.production;
public interface FooInterface {
String getNameDefault();
}
package com.production.Impl;
import javax.ejb.Local;
import javax.ejb.Stateless;
@Stateless
@Local(FooInterface.class)
public class FooImplement implements FooInterface {
@Override
public String getNameDefault() {
return "I am EJB remote";
}
}
I am using wildfly 10, jee7, activiti 5.2.2.
How can I use that EJB in my project? Thanks in advance :D
Thank you very much @Philippe, I implemented an explicit lookup (using the JNDI) and this worked for me correctly. The code that I use is:
public FooService getEJB() {
try {
Context ctx = new InitialContext();
Object obj = ctx.lookup("java:/production/FooServ");
return (FooService) obj;
} catch (NamingException e) {
e.printStackTrace();
}
}