2 Replies Latest reply on May 3, 2011 5:50 AM by andi-g

    Invoke EJB method

    andi-g

      Hi all,

      are there any possibilities to invoke EJB method knowing only an ejb class name and a method name?

        • 1. Invoke EJB method
          wdfink

          It depends ...

           

          If you use EJB3.1 and try to call a bean from another you might use

          @EJB MyEJBClass;

          The reference will be injected with the local proxy.

           

          For EJB3 you have to know the interface class (remote or local) and use this for the @EJB

           

          With EJB2.1 you have to know the JNDI name and do a lookup.

           

          To answer in more detail you should provide the EJB and JBoss version and more details about what you try to do.

          • 2. Invoke EJB method
            andi-g

            I've created simple taks service as MBean (this is only a sample):

             

            @RemoteBinding(jndiBinding = "jboss/service/TaskService/remote")

            @Service(objectName = "pl.pazp.jboss:service=SimpleService")

            @Management(TaskQueueService.class)

            public class TaskServiceMBean implements TaskService {

             

                           public Task createTask(Serializable taskInfo) {

                           

                                          return new Task();

                           }

             

                    public void invokeTaskActionMethod(Task task) {

             

                                          invokeEjbMethod(task.getInvokerClass(), task.getOnTaskActionMethod());

                    }

            }

             

             

            class Task is simple POJO:

             

            public class Task implements Serializable{

                           private String invokerClass;

                           private String onTaskActionMethod;

            }

             

             

            and EJB component:

             

            @Stateless

            public class TestBean implements Test {

             

                           @Resource("jboss/service/TaskService/remote")

                           private TaskService taskService;

             

                           public void createTask() {

                                          taskService.createTask(new String(), new String());

                    }

             

                    @TaskAction

                           public void onTaskAction(Task task) {

                                          //do something

                           }

            }

             

             

            TestBean invokes createTask method. Then using AOP, I intercept a class, which has invoked the TaskServiceMBean.createTask(..), and I get a method name which is annotated as a @TaskAction. I put these information in Task and save it in DB. After some time I'd like to pick up the Task from DB and invoke onTaskAction method on TestBean EJB. I ' ve done everything except for the last thing - invokeEjbMethod.

             

            I'm using JBoss 6.0.0Final

             

             

            Thanks for any help.