Timer (TimedObject) does not work in Web Application
Hi there,
we are trying to base a timer in some web application (created using Sun Studio Creator) on the procedure described in http://java.sun.com/j2ee/1.4/docs/tutorial/doc/Session5.html. As long as we follow the tutorial strictly (Thus calling upon the TimerService from a shell.) everything works fine.
Basically, we added the timersessionClient.jar to the web application. We moved the code in the client's main method into a (dedicated MyTimersessionClient) bean's constructor.
Now, instantiating the constructor from SessionBean1 doesn't seem to lead anywhere. When doing the same from Page1, at least the constructor is called. However, it fails for "javax.naming.NameNotFoundException: No object bound to name java:comp/env/ejb/SimpleTimerSession".
Interestingly enough, when we change the call initial.lookup("java:comp/env/ejb/SimpleTimerSession") to initial.lookup("java:comp/env/ejb") when running from the shell it returns com.sun.enterprise.naming.java.javaURLContext@99999 whereas the web application does return a similar value for initial.lookup("java:comp/env") and _fails_ for initial.lookup("java:comp/env/ejb"). (Am I right in supposing the (differing) values following the @ sign are not related to the problem at hand?)
How do we get reliable access to the TimerService from a web application?
Any suggestions more than welcome ;-)
diromic
[1416 byte] By [
diromic] at [2007-11-26 7:40:29]

# 1
You won't be able to access the EJB Timer Service directly from your WebApp:
1. Make sure that your are correctly adding the EJB Sets into Creator. Using the Client Jar generated by the Application Server and calling the context lookup() / PortableRemoteObject.narrow() won't work because of some other reasons (Creator will always remove any manually added ejb-ref in web.xml, that's why your lookup() call is failing). There is a tutorial on adding EJB Sets (client jar) into Creator 2. Once you have added the EJB Sets into Creator 2 and into your WebApp, you won't have to call any context lookup or narrow(), this will be done transparently to you. I strongly suggest to take a look at the EJB Tutorials.
2. The Creator app run in theApplication Server's Web Container, and the Timer will run in the EJB Container. So, you have to add a remote bussiness method into your EJB SessionBean who in turn internally will have access to SessionContext.getTimerService(), and then you will be able to create a task.
Hope this helps.
Antonio.
Message was edited by:
antoniovl
# 2
Hi Antonio,
thanks for the quick reply!
Basically you confirmed what we kind of guessed... Getting hands-on exposure to EJB for the very first time, we are looking through tutorials, for examples,... We don't seem to able, to dig up something, that works and we can digest at the same time...
Unfortunately, some of the examples rely for the (to us) most interesting parts on compiled code, for which no source is supplied... Are you aware of a site to download the sources for the EJB part, http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/ejb .html
counts on?
> 1. Make sure that your are correctly adding the EJB
> Sets into Creator.
We finally did that properly... ;-)
> 2. The Creator app run in theApplication Server's Web
> Container, and the Timer will run in the EJB
> Container. So, you have to add a remote bussiness
> method into your EJB SessionBean who in turn
> internally will have access to
> SessionContext.getTimerService(), and then you will
> be able to create a task.
This is probably, what we lack and thus prevents us from making the next step succesfully...
Have a nice weekend
diromic
# 3
>
> Are you aware of a
> site to download the sources for the EJB part,
> http://developers.sun.com/prodtech/javatools/jscreato
> /learning/tutorials/2/ejb.html
> counts on?
>
No, I don't. Sorry.
>Have a nice weekend
Have a nice weekend you too.
Antonio.