Configuring Quartz job to call EJb with EJBInvokerJob
Asked Answered
M

1

6

I need to call an ejb method from a quartz job an I'm having trouble with locating the ejb job. I have defined a Local interface and an stateless implementation. When deploying on websphere 7, the EjbInvokerJob is unable to find my component in my jndi tree. This is my quartz job definition (this is loaded via the quartz init servlet)

JobDetail jd = JobBuilder//
                    .newJob(EJBInvokerJob.class)//
                    .withIdentity("job", "group")//
                    .usingJobData(EJBInvokerJob.EJB_JNDI_NAME_KEY, "ejb/myBean")//
                    .usingJobData(EJBInvokerJob.EJB_METHOD_KEY, "update")//
                    .build();
            String cronExpr = getInitParameter("cronExpr");
            Trigger cronTrigger = TriggerBuilder//
                    .newTrigger() //
                    .forJob(jd) //
                    .startNow() //
                    .withSchedule(CronScheduleBuilder.cronSchedule(cronExpr))//
                    .build();

            Scheduler sched = StdSchedulerFactory.getDefaultScheduler();
            sched.scheduleJob(jd, cronTrigger);
            sched.start();

And my bean has this annotation on top of it

@Stateless(name = "myBean")

How should I bind my EJB_JNDI_NAME_KEY? in websphere or should I be able to do this via this configuration. I think the problem is with my lack of jndi tree knowledge. Since the servlet which starts the job runs in the same jvm, so a local interface should be enough

Medicine answered 26/6, 2013 at 13:26 Comment(0)
D
0

Since portable global JNDI names (java:global namespace) were not available until Java EE 6, you should bind EJB into component's namespace (servlet in this case). Then lookup can be performed using java:comp/env/ejb/myBean name.

The following entry is required in web.xml:

<ejb-local-ref>
  <ejb-ref-name>ejb/myBean</ejb-ref-name>
  <ejb-ref-type>Session</ejb-ref-type>
  <local>LOCAL_EJB_INTERFACE</local>
</ejb-local-ref>
Delaware answered 26/6, 2013 at 14:52 Comment(7)
The LOCAL_EJB_INTERFACE, is that the FQN of my ejb interface or the value I can give to the @Local annotation?Medicine
This still generates an error. Name [ejb/myBean] is not bound in this Context. Unable to find [ejb]Medicine
@Medicine It should be FQN of local EJB interface. In WAS console, is this EJB shown as bound into web application (Enterprise Applications/your app/References/EJB references)?Killebrew
When I look it is defined together with another bean I got injected into a servlet. should I define a jndi name and reference that one?Medicine
@Medicine The bean that is looked up from within servlet must be bound into web module. I am not familiar with EJBInvokerJob and don't know if it prepends 'java:comp/env' to the bean reference. You can try both 'java:comp/env/ejb/myBean' and 'ejb/myBean'.Killebrew
So I have my websphere where it says under 'EJB References' ejb/myBean. i tried looking up my bean via java:comp/env/ejb/myBean and via ejb/myBean. 2 times it failed. Error: Name "comp/env/ejb/myBean" not found in context "java:"Medicine
I think because of quartz running in a new threadpool instead of the threadpool of websphere, It is unable to find my ejb when I'm using the local interface...Medicine

© 2022 - 2024 — McMap. All rights reserved.