-
1. Re: calling ejb from servlet/jsp
joelvogt Jul 9, 2002 8:34 PM (in response to ku916)you'll have to do something like this to get a reference to the home interface of your ejb
Object object = initialContext.lookup(YOUR_EJB_JNDI_NAME);
YourEJBHome home = (YourEJBHome)
PortableRemoteObject.narrow(object, YourEJBHome.class);
Then do home.findAll() etc...
Where you do this lookup is up to you. I would recommend using a framework such as struts, from jakarta.apache.org -
-
3. Re: calling ejb from servlet/jsp
ku916 Jul 10, 2002 3:43 PM (in response to ku916)Thanks for the info. I've found an exmaple online to tryout a first EJB with JSP client. The EJB referencing in the JSP code is similar to your comments
long t1 = System.currentTimeMillis();
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(Context.PROVIDER_URL, "http://w2p-clo:1099");
Context ctx = new InitialContext(props);
FirstHome home = (FirstHome)ctx.lookup("ejb/First");
First bean = home.create();
String time = bean.getTime();
bean.remove();
ctx.close();
However, I went into a different problem when trying to access the JSP.
javax.servlet.ServletException: Receive timed out
javax.naming.CommunicationException: Receive timed out. Root exception is java.net.SocketTimeoutException: Receive timed out
I'm running JBoss 3.0.1 with Tomcat 4.0.4 bundle and JDK 1.4 -
4. Re: calling ejb from servlet/jsp
ku916 Jul 10, 2002 3:45 PM (in response to ku916)now I run into a new problem
javax.servlet.ServletException: Receive timed out
javax.naming.CommunicationException: Receive timed out. Root exception is java.net.SocketTimeoutException: Receive timed out
here is my JSP code (example found online)
<%@ page import="javax.naming.InitialContext,
javax.naming.Context,
java.util.Properties,
com.stardeveloper.ejb.session.First,
com.stardeveloper.ejb.session.FirstHome"%>
<%
long t1 = System.currentTimeMillis();
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
props.put(Context.PROVIDER_URL, "http://w2p-clo:1099");
Context ctx = new InitialContext(props);
FirstHome home = (FirstHome)ctx.lookup("ejb/First");
First bean = home.create();
String time = bean.getTime();
bean.remove();
ctx.close();
long t2 = System.currentTimeMillis();
%> -
5. Re: calling ejb from servlet/jsp
ku916 Jul 10, 2002 4:36 PM (in response to ku916)OK! I made a mistake on the Context.PROVIDER_URL "http://w2p-clo:1099" Now I've changed it to "jnp://w2p-clo:1099"
but I get this error instead
java.rmi.MarshalException: error marshalling arguments; nested exception is:
java.net.SocketException: Software caused connection abort: socket write error -
6. Re: calling ejb from servlet/jsp
gongqin Oct 15, 2002 1:19 PM (in response to ku916)I am having the exact same problem. The ejb can be invoked from a standalone client (diff jvm) without problem. But it called from a servlet in within tomcat, it fails.
Any help is appreciated. -
7. Re: calling ejb from servlet/jsp
pol.leleux Jan 17, 2003 5:14 AM (in response to ku916)I have exactly the same problem running Tomcat 4.0.4 as Standalone when I try to instanciate a bean within JBoss 3.0.4. (I also use JAAS).
Has anybody found a solution ? Any help would be greatly, greatly appreciated ! -
8. Re: calling ejb from servlet/jsp
thoennes Jan 28, 2003 12:11 PM (in response to ku916)> OK! I made a mistake on the Context.PROVIDER_URL
> "http://w2p-clo:1099" Now I've changed it to
> "jnp://w2p-clo:1099"
If your Tomcat is running in the same JVM, i.e. deployed as
a container inside JBoss, it is sufficient to use
Context = new InitialContext();
without any further arguments. In this way, you get a
reference to the current JBoss JNDI service, which also
has all EJBs registered.
Your approach differs in the way that you try to access
the JBoss JNDI as an external service from inside JBoss.
Since JBoss has some optimized stacks for Intra-JVM calls,
this does not match.
Perhaps my technical explanation above it not quite
correct (some developer please comment), but it works
for us as described above.
Cheers, Jörg -
9. Re: calling ejb from servlet/jsp
seemanto Jan 31, 2003 11:18 AM (in response to ku916)hi
i have my tomcat and jboss running in seperate jvm's.I do get the home object in the servlet but when i call create() on it, there's an exception.I really don't have any clue what going wrong. -
10. Re: calling ejb from servlet/jsp
booojum Mar 19, 2003 5:04 PM (in response to ku916)the manual referred to was for ejb to ejb not servlet to ejb...please help