On 12/14/2011 03:39 PM, forums_at_java.net wrote:
> The preferrred way is to declare portable ejb-ref (via web.xml,
> ejb-jar.xml,
> etc, or with annotation), and map the ejb-ref to its target in
> sun-ejb-jar.xml/sun-web.xml (GlassFish 2.x) or
> glassfish-ejb-jar.xml/glassfish-web.xml (GlassFish 3.x). Avoid directly
> looking up GlassFish-specific global names, or corba interop names with
> location info.
Thanks for the pointers Cheng.
I tried what you have suggested ... however it seems I did not do it in
a correct way.
Components involded
Stateless Session Bean...
...
@Stateless(mappedName="ejb/Calc")
public class CalcBean implements CalcBeanRemote {
public int sumItUp(int i, int j) {
return i + j;
}
}
...
Utility class
public class Calculator {
public static int doTotal(int i, int j) {
int sum = 0;
CalcBeanRemote calculator;
InitialContext ic = null;
try {
ic = new InitialContext();
calculator =
(CalcBeanRemote)ic.lookup("java:comp/env/ejb/Calculator");
sum = calculator.sumItUp(i, j);
return sum;
} catch (Exception ex) {
ex.printStackTrace(System.out);
return sum;
}
}
}
Servlet which uses the utility class
...
int sum = Calculator.doTotal(i, j);
out.println("Sum: " + sum );
...
Descriptors for Web-App:
web.xml
...
<ejb-ref>
<ejb-ref-name>ejb/Calculator</ejb-ref-name>
</ejb-ref>
...
glassfish-web.xml
...
<ejb-ref>
<ejb-ref-name>ejb/Calculator</ejb-ref-name>
<jndi-name>corba:iiop:localhost:3700#ejb/Calc</jndi-name>
</ejb-ref>
...
This leads to
[#|2011-12-16T16:37:42.756+0100|INFO|glassfish3.1.1|javax.enterprise.system.std.com.sun.enterprise.server.logging|_ThreadID=24;_ThreadName=Thread-2;|javax.naming.NamingException:
Lookup failed for 'java:comp/env/ejb/Calculator' in
SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory,
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.NamingException: Exception resolving Ejb for 'Remote
ejb-ref name=ejb/Calculator,Remote 3.x interface
=null,ejb-link=null,lookup=,mappedName=,jndi-name=corba:iiop:localhost:3700#ejb/Calc,refType=Session'
. Actual (possibly internal) Remote JNDI name used for lookup is
'corba:iiop:localhost:3700#ejb/Calc#null' [Root exception is
java.lang.NullPointerException]]
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:392)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at com.painstakingminds.math.Calculator.doTotal(Calculator.java:14)
at com.painstakingminds.web.EjbTest.processRequest(EjbTest.java:44)
at com.painstakingminds.web.EjbTest.doGet(EjbTest.java:72)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
Listing the jndi ejb context shows ..
./asadmin list-jndi-entries --context ejb
Calc: javax.naming.Reference
mgmt: com.sun.enterprise.naming.impl.TransientContext
Calc__3_x_Internal_RemoteBusinessHome__: javax.naming.Reference
Calc#com.painstakingminds.ejb.CalcBeanRemote: javax.naming.Reference
Unfortunately I'm still some kind of 'newbie' with regards to this EJB
stuff :-(.
Could you please shed some light?
TIA,
Bernhard
>
> The mapping can be portable global jndi name, GlassFish-specific global
> jndi
> name, or corba interop names.
>
> -Cheng
>
>
> --
>
> [Message sent by forum member 'cf126330']
>
> View Post: http://forums.java.net/node/873593
>
>
>
--
Painstaking Minds
IT-Consulting Bernhard Thalmayr
Herxheimer Str. 5, 83620 Vagen (Munich area), Germany
Tel: +49 (0)8062 7769174
Mobile: +49 (0)176 55060699
bernhard.thalmayr_at_painstakingminds.com - Solution Architect
This e-mail may contain confidential and/or privileged information.If
you are not the intended recipient (or have received this email in
error) please notify the sender immediately and delete this e-mail. Any
unauthorized copying, disclosure or distribution of the material in this
e-mail is strictly forbidden.