I am working on an application which is running on Glassfish. I am supposed to convert the servlets to proper restful stuff, by using jax-rs and jersey.
I have been trying to find a workaround for init() method, but till now i failed.
Here is the original part, using servlets:
import javax.servlet.*
public void init(ServletConfig config) throws ServletException {
super.init(config);
if (!isRunning() == true)) {
/* Do some stuff here*/
}
logger.info("Deamon has started");
}
and this one which i am trying to use jax-rs
import javax.ws.rs.*
import javax.servlet.*
public void init(@Context ServletConfig config) throws ServletException {
//uper.init(config);
if (!isRunning() == true)) {
/* Do some stuff here*/
}
logger.info("Deamon has started");
}
I have checked mailing lists and googled around but couldnt find a way which could work for this case.
any ideas how to achieve the same behaviour with servlets for init method?
finally, after googling a little bit more, i found a proper solution.
basically, i have extended
public class ContextListener implements ServletContextListener
class and implemented the abstract method public void contextInitialized(ServletContextEvent sce)
which is called when the application is loaded. I have moved the logic from the servlet to here for doing the initialization and other config settings, then it was smooth.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With