来自Play应用程序的EJB查找 [英] EJB lookup from Play application

查看:152
本文介绍了来自Play应用程序的EJB查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Play应用程序(我正在使用Play 2.1.0),我想从中调用在GlassFish服务器上运行的EJB。因此,我已经尝试在我的Play应用程序中添加gf-client.jar作为依赖关系,并以与在独立应用程序中所做的相同的方式获取对EJB的引用:

  Hashtable< String,String> properties = new Hashtable< String,String>(); 
properties.put(java.naming.factory.initial,com.sun.enterprise.naming.impl.SerialInitContextFactory);
properties.put(java.naming.factory.url.pkgs,com.sun.enterprise.naming);
properties.put(java.naming.factory.state,com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl);
properties.put(org.omg.CORBA.ORBInitialHost,localhost);
properties.put(org.omg.CORBA.ORBInitialPort,3700);
properties.put(java.naming.provider.url,iiop:// localhost:3700);
上下文ctx = new InitialContext(properties);
ctx.lookup(java:global / MyApplication / MyEJB / MyBean);

执行查找时我得到以下异常:

  play.api.Application $$ anon $ 1:执行异常[[RuntimeException:javax.naming.NotContextException:global is not a subcontext]] 
在播放。 api.Application $ class.handleError(Application.scala:289)〜[play_2.10.jar:2.1.0]
在play.api.DefaultApplication.handleError(Application.scala:383)[play_2.10。 jar:2.1.0]
play.orever.rar
在play.core.server.netty.PlayDefaultUpstreamHandler $$ anon $ 2 $$ anonfun $ handle $ 1.apply(PlayDefaultUpstreamHandler.scala:128)[play_2.10.jar:2.1.0]
在播放.api.libs.concurrent.PlayPromise $$ anonfun $ extend1 $ 1.apply(Promise.scala:113)[play_2.10.jar:2.1.0]
在play.api.libs.concurrent.PlayPromise $$ anonfun $ extend1 $ 1.apply(Promise.scala:113)[play_2。 10.jar:2.1.0]
java.lang.RuntimeException:javax.naming.NotContextException:global is not a subcontext
at play.libs.F $ Promise $ 6.apply(F.java:401 )〜[play_2.10.jar:2.1.0]
at scala.concurrent.Future $$ anonfun $ map $ 1.liftedTree2 $ 1(Future.scala:253)〜[scala-library.jar:na]
at scala.concurrent.Future $$ anonfun $ map $ 1.apply(Future.scala:249)〜[scala-library.jar:na]
at scala.concurrent.Future $$ anonfun $ map $ 1 .apply(Future.scala:249)〜[scala-library.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29)〜[scala-library.jar:na]
at akka.dispatch.BatchingExecutor $ Batch $$ anonfun $ run $ 1.liftedTree1 $ 1(BatchingExecutor.scala:67)〜[akka-actor_2.10.jar:na]
导致:javax.naming .NotContextException:tyrex.naming.EnvContext.internalLookup(Unknown Source)〜[tyrex.jar:1.0.1 2003年11月11日1703]在tyrex.naming.EnvContext.lookup上的
全局不是子上下文
(未知来源)〜[tyrex .jar:1.0.1 November 11 2003 1703]
at tyrex.naming.java.JavaContext.lookup(Unknown Source)〜[tyrex.jar:1.0.1 November 11 2003 1703]
在javax。 naming.InitialContext.lookup(InitialContext.java:411)〜[na:1.7.0_10]
在controllers.Application.index(Application.java:36)〜[na:na]
在路由$ $ anonfun $ routes $ 1 $$ anonfun $ applyOrElse $ 1 $$ anonfun $ apply $ 1.apply(routes_routing.scala:77)〜[na:na]

与独立应用程序相同的gf-client.jar依赖关系的完全相同的代码工作正常。
事实上,我实际获得的是一个NotContextException,在异常stacktrace中我看到以下行

  tyrex.naming.EnvContext.lookup(未知来源)

让我相信,由于某些原因,InitialContext我得到的不是正确的,因为如果我指定不存在的JNDI名称,我在独立应用程序中的堆栈跟踪有一点不同:

 线程中的异常mainjavax.naming.NamingException:SerialContext中的java:global / Test / MyBean查找失败[myEnv = {org.omg.CORBA.ORBInitialPort = 3700,java.naming .factory.initial = com.sun.enterprise.naming.SerialInitContextFactory,org.omg.CORBA.ORBInitialHost = localhost,java.naming.factory.state = com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl,java .naming.factory.url.pkgs = com.sun.enterprise.naming} [根异常是javax.naming.NameNotFoundException:Test] 
在com.sun.enterprise.namin g.impl.SerialContext.lookup(SerialContext.java:518)
在com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
在javax.naming.InitialContext。 lookup(InitialContext.java:411)
在com.eurodyn.testmavenjavaapp.App.main(App.java:24)
导致:javax.naming.NameNotFoundException:测试
在com。 sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:310)
在com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:218)
在com。 sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:219)
在com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
在com。 sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcc essorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
在java.lang.reflect.Method.invoke(Method.java:601)
在com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:144)
at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie。 java:174)
在com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:528)
在com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl。 dispatch(CorbaServerRequestDispatcherImpl.java:199)
在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1624)
在com.sun.corba.ee.impl。 protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1486)
在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:9 90)
在com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:214)
在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl。 handleRequest(CorbaMessageMediatorImpl.java:742)
在com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:539)
在com.sun.corba.ee.impl。 protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2324)
在com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl $ WorkerThread.performWork(ThreadPoolImpl.java:497)
在com。 sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl $ WorkerThread.run(ThreadPoolImpl.java:540)



我做错了什么?有没有其他方法可以从Play应用程序执行JNDI查找?我从这个Stackoverflow答案了解到,这是一些东西

解决方案

我已经为我修复了这个问题(播放2.1.3和Glassfish 3.1.2.2),添加gf-client-module到项目/ Build.scala中的依赖关系,而不是直接链接jar:

  gb-client-module 

当解析依赖关系时,它错过了我能够找到的模块org.eclipse.persistence#javax.persistence; 2.0.4.v201112200901:

  resolvers + =opencastprojectathttp://repository.opencastproject.org/nexus/content/groups/public/

为了确定要查找的名称,我查看了这个上下文中的名称:

  InitialContext ic = getInitialContext(); 
System.out.println(ic.getEnvironment());
NamingEnumeration< NameClassPair> childList = ic.list();
while(childList.hasMore()){
NameClassPair ncPair =(NameClassPair)childList.next();
if(ncPair.getName()。contains(Job)== false){
System.out.println(ncPair.getName()+(type+ ncPair.getClassName()+ ));
}
}

我使用的名称与列出的名称完全相同。



关心


I have a Play application (I am using Play 2.1.0) from which I would like to invoke EJBs running on a GlassFish server. Therefore, I have tried adding gf-client.jar as a dependency in my Play application and getting a reference to the EJBs the same way I would do in a standalone application:

Hashtable<String, String> properties = new Hashtable<String, String>();
properties.put("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
properties.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
properties.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
properties.put("org.omg.CORBA.ORBInitialHost", "localhost");
properties.put("org.omg.CORBA.ORBInitialPort", "3700");
properties.put("java.naming.provider.url", "iiop://localhost:3700");
Context ctx = new InitialContext(properties);
ctx.lookup("java:global/MyApplication/MyEJB/MyBean");

I get however the following exception when executing the lookup:

play.api.Application$$anon$1: Execution exception[[RuntimeException: javax.naming.NotContextException: global is not a subcontext]]
        at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.0]
        at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.0]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:132) [play_2.10.jar:2.1.0]
        at play.core.server.netty.PlayDefaultUpstreamHandler$$anon$2$$anonfun$handle$1.apply(PlayDefaultUpstreamHandler.scala:128) [play_2.10.jar:2.1.0]
        at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.0]
        at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.0]
java.lang.RuntimeException: javax.naming.NotContextException: global is not a subcontext
        at play.libs.F$Promise$6.apply(F.java:401) ~[play_2.10.jar:2.1.0]
        at scala.concurrent.Future$$anonfun$map$1.liftedTree2$1(Future.scala:253) ~[scala-library.jar:na]
        at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249) ~[scala-library.jar:na]
        at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:249) ~[scala-library.jar:na]
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:29) ~[scala-library.jar:na]
        at akka.dispatch.BatchingExecutor$Batch$$anonfun$run$1.liftedTree1$1(BatchingExecutor.scala:67) ~[akka-actor_2.10.jar:na]
Caused by: javax.naming.NotContextException: global is not a subcontext
        at tyrex.naming.EnvContext.internalLookup(Unknown Source) ~[tyrex.jar:1.0.1  November 11 2003 1703]
        at tyrex.naming.EnvContext.lookup(Unknown Source) ~[tyrex.jar:1.0.1  November 11 2003 1703]
        at tyrex.naming.java.JavaContext.lookup(Unknown Source) ~[tyrex.jar:1.0.1  November 11 2003 1703]
        at javax.naming.InitialContext.lookup(InitialContext.java:411) ~[na:1.7.0_10]
        at controllers.Application.index(Application.java:36) ~[na:na]
        at Routes$$anonfun$routes$1$$anonfun$applyOrElse$1$$anonfun$apply$1.apply(routes_routing.scala:77) ~[na:na]

The exact same code with the same gf-client.jar dependency works fine from a standalone application. The fact that what I actually get is a NotContextException and that in the exception stacktrace I see the following line

at tyrex.naming.EnvContext.lookup(Unknown Source)

leads me to believe that for some reason the InitialContext I am getting is not "correct", since the stacktrace I get in my standalone application if I specify a JNDI name that does not exist is a bit different:

Exception in thread "main" javax.naming.NamingException: Lookup failed for 'java:global/Test/MyBean' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: Test]
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:518)
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:455)
    at javax.naming.InitialContext.lookup(InitialContext.java:411)
    at com.eurodyn.testmavenjavaapp.App.main(App.java:24)
Caused by: javax.naming.NameNotFoundException: Test
    at com.sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:310)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:218)
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:219)
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:77)
    at com.sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:109)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:144)
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:174)
    at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatchToServant(CorbaServerRequestDispatcherImpl.java:528)
    at com.sun.corba.ee.impl.protocol.CorbaServerRequestDispatcherImpl.dispatch(CorbaServerRequestDispatcherImpl.java:199)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequestRequest(CorbaMessageMediatorImpl.java:1624)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:1486)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleInput(CorbaMessageMediatorImpl.java:990)
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:214)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.handleRequest(CorbaMessageMediatorImpl.java:742)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.dispatch(CorbaMessageMediatorImpl.java:539)
    at com.sun.corba.ee.impl.protocol.CorbaMessageMediatorImpl.doWork(CorbaMessageMediatorImpl.java:2324)
    at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497)
    at com.sun.corba.ee.impl.orbutil.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540)

What am I doing wrong? Is there some other way to perform JNDI lookup from a Play application? I understand from this Stackoverflow answer that this is something that can be done.

解决方案

I have fixed this problem for me (Play 2.1.3 and Glassfish 3.1.2.2) by adding the gf-client-module to the dependencies in the project/Build.scala instead of trying to link the jar directly:

"org.glassfish.main.appclient.client" % "gf-client-module" % "3.1.2.2" 

When resolving the dependencies it missed the module org.eclipse.persistence#javax.persistence;2.0.4.v201112200901 which I was able to locate here:

 resolvers += "opencastproject" at "http://repository.opencastproject.org/nexus/content/groups/public/" 

To be sure what name to lookup I checked the names availabe in that context:

InitialContext ic = getInitialContext();
System.out.println(ic.getEnvironment());
NamingEnumeration<NameClassPair> childList = ic.list("");
while (childList.hasMore()) {
NameClassPair ncPair = (NameClassPair) childList.next();
    if (ncPair.getName().contains("Job") == false) {
        System.out.println(ncPair.getName() + " (type " + ncPair.getClassName() + ")");
    }
}

I used the names exactly as the were listed there.

Regards

这篇关于来自Play应用程序的EJB查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆