6 Replies Latest reply on Feb 5, 2015 7:59 AM by rafachies

    EJB call from JBPM

    biswajit.sarkar

      I am new to JBPM.

      Currently I am using jbpm version 6.1.

      I have a EJB project deployed in jboss server.

      I am trying to access that EJB from my JBPM process.

       

      I can access that from a custom workItem handler using JNDI lookup.

      But I don't know if there any other way to access EJB from JBPM.

      Does JBPM provide any inbuilt mechanism to call EJB from JBPM?

       

       

      Thanks in advance

        • 1. Re: EJB call from JBPM
          biswajit.sarkar

          I have created a EJB project and deploy it in JBOSS. I am able to llokup and call remote method from a standalone class.

           

          So I try to create a custom work handler "EJBTask"

           

          package com.sample;

           

          import java.util.Properties;

           

          import javax.naming.Context;

          import javax.naming.InitialContext;

          import javax.naming.NamingException;

           

          import org.kie.api.runtime.process.WorkItem;

          import org.kie.api.runtime.process.WorkItemHandler;

          import org.kie.api.runtime.process.WorkItemManager;

           

          import com.test.HelloWorldRemote;

           

          public class EJBTask implements WorkItemHandler{

           

              @Override

              public void abortWorkItem(WorkItem arg0, WorkItemManager arg1) {

                  // TODO Auto-generated method stub

              }

           

              @Override

              public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {

                  Properties props = new Properties();

                  props.put("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory" );

                  props.put("java.naming.provider.url", "remote://127.0.0.1:4447"); //4447 is JNDI port

                  props.put("java.naming.factory.url.pkgs", "org.jboss.naming");

                  props.put("jboss.naming.client.ejb.context",true);

                  Context ctx;

                  try {

                      ctx = new InitialContext(props);

                      HelloWorldRemote remote = (HelloWorldRemote) ctx.lookup("HelloEAR/HelloEJB/HelloWorld!com.test.HelloWorldRemote");

                      System.out.println(remote.sayHello());

                  } catch (NamingException e) {

                      e.printStackTrace();

                  }

              }

           

          }

           

           

          I added the EJB project jar in KIE Workbench as dependency of this project , then save and "build and deploy".

          I was successfully build and deployed.

          So when I try to start this process I am getting following error

           

          2015-02-05 00:37:02,891 INFO  [org.jboss.ejb.client.remoting] (Remoting "config-based-naming-client-endpoint" task-6) EJBCLIENT000017: Received server version 2 and marshalling strategies [river]

          2015-02-05 00:37:02,906 INFO  [org.jboss.ejb.client.remoting] (default task-33) EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@60620544, receiver=Remoting connection EJB receiver [connection=Remoting connection <3b6ace3a>,channel=jboss.ejb,nodename=biswajit-inspiron-3542]} on channel Channel ID d3cbbb60 (outbound) of Remoting connection 0c60448a to /127.0.0.1:4447

          2015-02-05 00:37:02,982 INFO  [org.jboss.ejb.client.remoting] (Remoting "config-based-naming-client-endpoint" task-11) EJBCLIENT000016: Channel Channel ID d3cbbb60 (outbound) of Remoting connection 0c60448a to /127.0.0.1:4447 can no longer process messages

          2015-02-05 00:37:03,014 INFO  [org.jboss.ejb.client.remoting] (Remoting "config-based-naming-client-endpoint" task-2) EJBCLIENT000017: Received server version 2 and marshalling strategies [river]

          2015-02-05 00:37:03,018 INFO  [org.jboss.ejb.client.remoting] (default task-33) EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@60620544, receiver=Remoting connection EJB receiver [connection=Remoting connection <5f2890>,channel=jboss.ejb,nodename=biswajit-inspiron-3542]} on channel Channel ID a28f364f (outbound) of Remoting connection 330ba516 to /127.0.0.1:4447

          2015-02-05 00:37:03,125 ERROR [stderr] (default task-33) org.jboss.naming.remote.protocol.NamingIOException: Failed to lookup [Root exception is java.io.IOException: java.lang.ClassNotFoundException: com.test.HelloWorldRemote from [Module "deployment.jbpm-console.war:main" from Service Module Loader]]

          2015-02-05 00:37:03,139 ERROR [stderr] (default task-33)     at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:49)

          2015-02-05 00:37:03,144 ERROR [stderr] (default task-33)     at org.jboss.naming.remote.protocol.v1.Protocol$1.execute(Protocol.java:104)

          2015-02-05 00:37:03,148 ERROR [stderr] (default task-33)     at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.lookup(RemoteNamingStoreV1.java:95)

          2015-02-05 00:37:03,151 ERROR [stderr] (default task-33)     at org.jboss.naming.remote.client.HaRemoteNamingStore$1.operation(HaRemoteNamingStore.java:276)

          2015-02-05 00:37:03,155 ERROR [stderr] (default task-33)     at org.jboss.naming.remote.client.HaRemoteNamingStore.namingOperation(HaRemoteNamingStore.java:137)

          2015-02-05 00:37:03,159 ERROR [stderr] (default task-33)     at org.jboss.naming.remote.client.HaRemoteNamingStore.lookup(HaRemoteNamingStore.java:272)

          2015-02-05 00:37:03,163 ERROR [stderr] (default task-33)     at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:87)

          2015-02-05 00:37:03,167 ERROR [stderr] (default task-33)     at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:129)

          2015-02-05 00:37:03,171 ERROR [stderr] (default task-33)     at javax.naming.InitialContext.lookup(InitialContext.java:411)

          2015-02-05 00:37:03,174 ERROR [stderr] (default task-33)     at javax.naming.InitialContext.lookup(InitialContext.java:411)

          2015-02-05 00:37:03,178 ERROR [stderr] (default task-33)     at com.sample.EJBTask.executeWorkItem(EJBTask.java:32)

          2015-02-05 00:37:03,182 ERROR [stderr] (default task-33)     at org.drools.persistence.jpa.processinstance.JPAWorkItemManager.internalExecuteWorkItem(JPAWorkItemManager.java:54)

          2015-02-05 00:37:03,187 ERROR [stderr] (default task-33)     at org.jbpm.workflow.instance.node.WorkItemNodeInstance.internalTrigger(WorkItemNodeInstance.java:133)

          2015-02-05 00:37:03,192 ERROR [stderr] (default task-33)     at org.jbpm.workflow.instance.impl.NodeInstanceImpl.trigger(NodeInstanceImpl.java:162)

          2015-02-05 00:37:03,196 ERROR [stderr] (default task-33)     at org.jbpm.workflow.instance.impl.NodeInstanceImpl.triggerNodeInstance(NodeInstanceImpl.java:354)

           

           

          though I have added the ejb project jar as dependency I am still getting "Classntfoundexception"

           

          Anyone please help me.

          Did I miss something. please help me

          • 2. Re: EJB call from JBPM
            sanjay05222

            I think technically if you want to make it work it is fine pursuit but as per me I would not tightly couple the ejb calls like this instead I would create a webservice which exposes the EJB services and in that way it is loosely coupled and it has more value to the system. just a thought.

            Is ejb deployed separately, I think you have to have client stubs packed along with the work item handler then it will work.

             

            thanks

            Sanjay Gautam

            • 3. Re: EJB call from JBPM
              biswajit.sarkar

              Thanks Sanjay.

              As our applications are quite old so I can't expose them as web service

              Instead I have to call them using JNDI lookup.

               

              Rafael Chies and Maciej Swiderski can you please help in this....

              • 4. Re: EJB call from JBPM
                rafachies

                Hi Biswajit,

                 

                I remember there were some bugzilla opened regarding that when using through dependencies in the project, but I remember there is one option that should work: Put your JAR under business-central.war/WEB-INF/lib.Register your WorkItem Handler in business-central.war/WEB-INF/classes/META-INF/CustomWorkItemHandlers.conf. It should work fine.

                1 of 1 people found this helpful
                • 5. Re: EJB call from JBPM
                  biswajit.sarkar

                  thanks Rafael Chies

                   

                  so I have to put that EJB client jar(dependency) in business-central.war/WEB-INF/lib.

                  and have to register my WorkItem Handler in business-central.war/WEB-INF/classes/META-INF/CustomWorkItemHandlers.conf.

                   

                  right?

                  • 6. Re: EJB call from JBPM
                    rafachies

                    You have to put "your" JAR under business-central.war/WEB-INF/lib. As "your" JAR I mean the JAR that holds your Custom Handler Class. Of course your handler depends on the EJB client library. In this case, you can also drop it under business-central.war/WEB-INF/lib, or create a module in EAP, and so use jboss-deployment-structure in your custom JAR to declare dependency to this module.