java - Websphere JNDI lookup fails in a Quartz job -


do can me ejb initialization in quartz job

i have quartz this:

@disallowconcurrentexecution public class testjob implements job{  private testejbservicelocal testejbservice;  private void initejb() {    this.testejbservice = new jndiutil()             .getbyjndiname("java:comp/env/ejb/testejbservice"); } @override public void execute(jobexecutioncontext arg0) throws jobexecutionexception {     // stuff } } 

in web xml have:

<ejb-local-ref>         <description />         <ejb-ref-name>ejb/testejbservice</ejb-ref-name>         <ejb-ref-type>session</ejb-ref-type>         <local-home />         <local>com.ibm.blue.ejb.testejbservicelocal</local>         <ejb-link>testejbservice</ejb-link>     </ejb-local-ref> 

was liberty profile can not initialize ejb exception:

2015-06-04 16:18:00 error jndiutil:38 - jndiutil lookup error; javax.naming.namingexception: cwnen1000e: jndi operation on java:comp/env name cannot completed because current thread not associated java enterprise edition application component. condition can occur when jndi client using java:comp/env name not occur on thread of server application request. make sure java ee application not run jndi operations on java:comp/env names within static code blocks or in threads created application. such code not run on thread of server application request , therefore not supported jndi operations on java:comp/env names.     @ com.ibm.ws.injectionengine.osgi.internal.naming.injectionjavacolonhelper.getinjectionscopedata(injectionjavacolonhelper.java:110)     @ com.ibm.ws.injectionengine.osgi.internal.naming.injectionjavacolonhelper.getobjectinstance(injectionjavacolonhelper.java:67)     @ com.ibm.ws.jndi.url.contexts.javacolon.internal.javaurlcontext.lookup(javaurlcontext.java:319)     @ com.ibm.ws.jndi.url.contexts.javacolon.internal.javaurlcontext.lookup(javaurlcontext.java:357)     @ org.apache.aries.jndi.delegatecontext.lookup(delegatecontext.java:161)     @ javax.naming.initialcontext.lookup(initialcontext.java:423)     @ jndiutil.lookup(jndiutil.java:36)     @ getbyjndiname(jndiutil.java:24)     @ job.initejb(job.java:52)     @ execute(job.java:68)     @ org.quartz.core.jobrunshell.run(jobrunshell.java:202)     @ org.quartz.simpl.simplethreadpool$workerthread.run(simplethreadpool.java:573) 2015-06-04 16:18:00 error jndiutil:38 - jndiutil lookup error; 

i running ibm liberty profile v. 8.5.5.5

update

i have tried update jndi lookup string (the global jndi printed during app startup in trace.log) still geting same exception. here updates in job:

private void initejb() {    context context;    string jndi = "java:global/testear/testejbs/testejbservice!com.ibm.blue.ejb.testejbservicelocal"    try{       context = new initialcontext();       this.testejbservice = (testejbservicelocal)context.lookup(jndi);         } catch (namingexception e) {         system.out.println("-->test initialcontext: error");         e.printstacktrace();     }   try {         this.testejbservice = new jndiutil().getbyjndiname(jndi);     } catch (exception e) {         system.err.println("-->test jndiutil: error");         e.printstacktrace();     }  } 

here output log:

[err] -->test initialcontext: error [err] javax.naming.namingexception: cwnen1000e: jndi operation on java:comp/env name cannot completed because current thread not associated java enterprise edition application component. condition can occur when jndi client using java:comp/env name not occur on thread of server application request. make sure java ee application not run jndi operations on java:comp/env names within static code blocks or in threads created application. such code not run on thread of server application request , therefore not supported jndi operations on java:comp/env names. [err]   @ com.ibm.ws.injectionengine.osgi.internal.naming.injectionjavacolonhelper.getinjectionscopedata(injectionjavacolonhelper.java:110) [err]   @ com.ibm.ws.injectionengine.osgi.internal.naming.injectionjavacolonhelper.getobjectinstance(injectionjavacolonhelper.java:67) [err]   @ com.ibm.ws.jndi.url.contexts.javacolon.internal.javaurlcontext.lookup(javaurlcontext.java:319) [err]   @ com.ibm.ws.jndi.url.contexts.javacolon.internal.javaurlcontext.lookup(javaurlcontext.java:357) [err]   @ org.apache.aries.jndi.delegatecontext.lookup(delegatecontext.java:161) [err]   @ javax.naming.initialcontext.lookup(initialcontext.java:423) [err]   @ job.initejb(job.java:38) [err]   @ execute(job.java:75) [err]   @ org.quartz.core.jobrunshell.run(jobrunshell.java:202) [err]   @ org.quartz.simpl.simplethreadpool$workerthread.run(simplethreadpool.java:573) [err] -->test jndiutil: error [err] java.lang.runtimeexception: cannot bean jndi name; jndi=java:global/testear/testejbs/testejbservice!com.ibm.blue.ejb.testejbservicelocal [err]   @ jndiutil.lookup(jndiutil.java:39) [err]   @ jndiutil.getbyjndiname(jndiutil.java:24) [err]   @ initejb(job.java:62) [err]   @ job.execute(job.java:75) [err]   @ org.quartz.core.jobrunshell.run(jobrunshell.java:202) [err]   @ org.quartz.simpl.simplethreadpool$workerthread.run(simplethreadpool.java:573) [err] caused by:  [err] javax.naming.namingexception: cwnen1000e: jndi operation on java:comp/env name cannot completed because current thread not associated java enterprise edition application component. condition can occur when jndi client using java:comp/env name not occur on thread of server application request. make sure java ee application not run jndi operations on java:comp/env names within static code blocks or in threads created application. such code not run on thread of server application request , therefore not supported jndi operations on java:comp/env names. [err]   @ com.ibm.ws.injectionengine.osgi.internal.naming.injectionjavacolonhelper.getinjectionscopedata(injectionjavacolonhelper.java:110) [err]   @ com.ibm.ws.injectionengine.osgi.internal.naming.injectionjavacolonhelper.getobjectinstance(injectionjavacolonhelper.java:67) [err]   @ com.ibm.ws.jndi.url.contexts.javacolon.internal.javaurlcontext.lookup(javaurlcontext.java:319) [err]   @ com.ibm.ws.jndi.url.contexts.javacolon.internal.javaurlcontext.lookup(javaurlcontext.java:357) [err]   @ org.apache.aries.jndi.delegatecontext.lookup(delegatecontext.java:161) [err]   @ javax.naming.initialcontext.lookup(initialcontext.java:423) [err]   @ jndiutil.lookup(jndiutil.java:36) [err]   ... 5 more 

quartz using unmanaged threads, java:comp/env namespace , reference not available there.

you can either:

  • use full jndi name of ejb <=== update2 cannot make running local interfaces unmanaged thread (i don't have time play more right now). either need use liberty beta, supports remote ejb , change bean have remote interface. or try configure quartz use managed thread factory provided liberty concurrent feature (in similar fashion here (but full was). didn't try it, don't know if possible).

  • or, better, instead of quartz use

    • concurrent-1.0 feature of websphere liberty, uses managed threads , has access java ee context, example managed scheduled executor
    • or use ejb timers , @schedule annotation.

update
can find full jndi name in message log when bound server this:

[info    ] cntr0167i: server binding test.hello interface of hello enterprise bean in helloejblocal.war module of helloejblocal application.   binding location is: java:global/helloejblocal/hello!test.hello 

then lookup using (this works java ee application component or managed thread):

ctx.lookup("java:global/helloejblocal/hello!test.hello"); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -