|
| Apache Geronimo > Discussion Forums | User List | Dev List | Wiki | Issue Tracker |
|
View:
New views
9 Messages
—
Rating Filter:
Alert me
|
|
|
JNDI Name for EJB3Hi,
I ran again into the problem of looking up an EJB3 from JNDI in a JSP (Ger 2.1.4) The bean is @Stateless(name="Secure3") public class Secured3Bean implements Secured3 Deployment log says 2009-06-17 17:31:22,989 INFO [startup] Assembling app: /projekte/geronimo-jetty6-javaee5-2.1.4/var/temp/geronimo-deployer4457332012373548807.tmpdir/Secured3Bean_ejb.jar 2009-06-17 17:31:22,993 INFO [startup] Jndi(name=Secure3Remote) --> Ejb(deployment-id=Secured3Bean/Secure3) So I guess JNDI name is Secure3Remote. but context.lookup("java:comp/env/Secure3Remote") throws an exeption, also context.lookup("Secure3Remote") and all other permutations I could think of. http://cwiki.apache.org/GMOxDEV/client-jndi-names.html did not help. Could someone please give a hint what name I should try. Thanks, Juergen |
|
|
Re: JNDI Name for EJB3On Jun 17, 2009, at 8:43 AM, Juergen Weber wrote: > > Hi, > > I ran again into the problem of looking up an EJB3 from JNDI in a > JSP (Ger > 2.1.4) > > The bean is > > @Stateless(name="Secure3") > public class Secured3Bean implements Secured3 > > Deployment log says > 2009-06-17 17:31:22,989 INFO [startup] Assembling app: > /projekte/geronimo-jetty6-javaee5-2.1.4/var/temp/geronimo- > deployer4457332012373548807.tmpdir/Secured3Bean_ejb.jar > 2009-06-17 17:31:22,993 INFO [startup] Jndi(name=Secure3Remote) --> > Ejb(deployment-id=Secured3Bean/Secure3) > > So I guess JNDI name is Secure3Remote. > but context.lookup("java:comp/env/Secure3Remote") throws an > exeption, also > context.lookup("Secure3Remote") and all other permutations I could > think of. > > http://cwiki.apache.org/GMOxDEV/client-jndi-names.html did not help. > > Could someone please give a hint what name I should try. For phiosophical reasons I would not recommend using an ejb directly from a jsp, rather I'd suggest a servlet that constructs an easily rendered data model; in the servlet you can use annotations. If you use a jsp you need to mention the ejb-ref in your web.xml and that should give you the name to look up. thanks david jencks > > Thanks, > Juergen > > -- > View this message in context: http://www.nabble.com/JNDI-Name-for-EJB3-tp24076429s134p24076429.html > Sent from the Apache Geronimo - Users mailing list archive at > Nabble.com. > |
|
|
Re: JNDI Name for EJB3http://cwiki.apache.org/GMOxDEV/client-jndi-names.html will use a RemoteInitialContextFactory.
Like: Properties p = new Properties(); p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.RemoteInitialContextFactory"); p.setProperty(Context.PROVIDER_URL, "ejbd://localhost:4201"); Context initialContext=null; try { initialContext=new InitialContext(p); Object object1 = initialContext.lookup("Secure3Remote"); Secure3Remote s3r=(Secure3Remote)object1; } catch (NamingException e) { e.printStackTrace(); } -- Best Regards, Rodger. |
|
|
Re: JNDI Name for EJB3And <geronimo_home>/repository/org/apache/openejb/openejb-client/3.0.1/openejb-client-3.0.1.jar is necessary.
2009/6/18 Rodger <eternaljian@...> http://cwiki.apache.org/GMOxDEV/client-jndi-names.html will use a RemoteInitialContextFactory. -- Best Regards, Rodger. |
|
|
Re: JNDI Name for EJB3That may go over tcp/ip rather than in-vm. The jndi names are printed out in var/log/geronimo.log as the ejbs start.
You can also use the in-vm javaee jndi context if you set it up with ejb refs in web.xml. david jencks On Jun 17, 2009, at 6:17 PM, Rodger wrote: And <geronimo_home>/repository/org/apache/openejb/openejb-client/3.0.1/openejb-client-3.0.1.jar is necessary. |
|
|
Re: JNDI Name for EJB3Rodger, thanks you, that works.
8-) Juergen
|
|
|
Re: JNDI Name for EJB3I only wanted to try some security thing (which will be my next post ;-), so I used a JSP for a quick test (which took rather long ;-)
I had had just a glance at http://cwiki.apache.org/GMOxDOC21/mytime-very-simple-session-ejb-example.html and there is neither web.xml nor ejb-ref. My original Exception without ejb-ref was javax.naming.NotContextException: ejb/Secured3Bean at org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:171) at org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:611) at javax.naming.InitialContext.lookup(InitialContext.java:392) I think this Exception is misleading, there should be a message like "ejb-ref" is missing. Throwing a NotContextException in this case is like if you are searching something in a database and throwing an EntryNotFoundException when the database is down. On your suggestion I tried <ejb-local-ref> <ejb-ref-name>ejb/Secured3</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local>ejb3.Secured3</local> <ejb-link>Secure3</ejb-link> </ejb-local-ref> but this gives the exception below. Thanks, Juergen java.lang.NullPointerException at org.apache.openejb.util.LinkResolver.resolveLink(LinkResolver.java:69) at org.apache.openejb.assembler.classic.EjbResolver.resolveLink(EjbResolver.java:121) at org.apache.openejb.assembler.classic.EjbResolver.resolve(EjbResolver.java:180) at org.apache.openejb.config.JndiEncInfoBuilder.buildEjbRefs(JndiEncInfoBuilder.java:172) at org.apache.openejb.config.JndiEncInfoBuilder.build(JndiEncInfoBuilder.java:129) at org.apache.geronimo.openejb.deployment.EjbRefBuilder.buildNaming(EjbRefBuilder.java:153) at org.apache.geronimo.j2ee.deployment.NamingBuilderCollection.buildNaming(NamingBuilderCollection.java:53) at org.apache.geronimo.web25.deployment.AbstractWebModuleBuilder.configureBasicWebModuleAttributes(AbstractWebModuleBuilder.java:842) at org.apache.geronimo.jetty6.deployment.JettyModuleBuilder.addGBeans(JettyModuleBuilder.java:365) at org.apache.geronimo.j2ee.deployment.SwitchingModuleBuilder.addGBeans(SwitchingModuleBuilder.java:165) at org.apache.geronimo.j2ee.deployment.EARConfigBuilder.buildConfiguration(EARConfigBuilder.java:647) at org.apache.geronimo.deployment.Deployer.deploy(Deployer.java:255) at org.apache.geronimo.deployment.Deployer.deploy(Deployer.java:134) at sun.reflect.GeneratedMethodAccessor496.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.geronimo.gbean.runtime.ReflectionMethodInvoker.invoke(ReflectionMethodInvoker.java:34) at org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:124) at org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:867) at org.apache.geronimo.kernel.basic.BasicKernel.invoke(BasicKernel.java:239) at org.apache.geronimo.deployment.plugin.local.AbstractDeployCommand.doDeploy(AbstractDeployCommand.java:116) at org.apache.geronimo.deployment.plugin.local.RedeployCommand.redeploySameConfiguration(RedeployCommand.java:225) at org.apache.geronimo.deployment.plugin.local.RedeployCommand.run(RedeployCommand.java:101) at java.lang.Thread.run(Thread.java:619)
|
|
|
Re: JNDI Name for EJB3OK, I got it to run with <ejb-local-ref> using the sample from
http://cwiki.apache.org/GMOxDOC20/very-simple-session-ejb-example.html (which does contain a web.xml) <ejb-local-ref> <ejb-ref-name>ejb/Secured3</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <local>ejb3.Secured3</local> </ejb-local-ref> context = new InitialContext(); Secured3 secured3 = (Secured3) context.lookup("java:comp/env/ejb/Secured3"); I also needed a sys:dependency from geronimo-web.xml to openejb-jar.xml to make the remote interface known to the JSP (this is missing in the above sample). First I simply included the ejb.jar into WEB-INF/lib, but this results in ClassCastException on JNDI lookup (I guess because the Remote interface in JNDI is from a different (the ejb) classloader than the cast target which is from the web application). Thanks, Juergen |
|
|
Re: JNDI Name for EJB3hi Juergen,
Here is my note.. EJB Project================================================= @Remote interface Converter @stateless public class ConverterBean implements Converter Web Project================================================= 1 Add dependency in geronimo-web.xml <sys:dependency> <sys:groupId>default</sys:groupId> <sys:artifactId>CurrencyConvertEJB</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>car</sys:type> </sys:dependency> 2 Ref the EJB (1) Method 1 in web.xml-------------- <ejb-ref> <ejb-ref-name>ConverterBean</ejb-ref-name> <!--actually Convert, ConvertBeanRemote are also ok--> <ejb-ref-type>Session</ejb-ref-type> <remote>ejb.Converter</remote> </ejb-ref> in jsp------------------ <%@ page import="javax.naming.*" %> <%@ page import="ejb.Converter" %> <% Context ctx = new InitialContext(); Converter ref = (Converter)ctx.lookup("java:comp/env/ConverterBean"); %> (2) Method 2 in geronimo-web.xml------- <name:ejb-ref> <name:ref-name>ejb/SessionBean</name:ref-name> <name:ejb-link>ConverterBean</name:ejb-link> </name:ejb-ref> in web.xml---------------- <ejb-ref> <ejb-ref-name>ejb/SessionBean</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <remote>ejb.Converter</remote> </ejb-ref> in jsp-------------------- <%@ page import="javax.naming.*" %> <%@ page import="ejb.Converter" %> <% Context ctx = new InitialContext(); Converter ref = (Converter)ctx.lookup("java:comp/env/ejb/SessionBean"); %> HTH. Rex 2009/6/18 Juergen Weber <weberjn@...>
|
| Free embeddable forum powered by Nabble | Forum Help |
