Servlet-aware service POJOs

From: Aron Gombas <aron.gombas@xxx.com>
Date: Wed Jul 20 2005 - 08:30:38 PDT

 Hi!

 First thank you for this cool piece of software!

I have been using Hessian for some weeks with great success,
but today in order to be able to implement a feature, I needed the
ServetContext in my service POJO. For this, the POJO
should be aware of the HessianServlet instance which
"controls" it.
 My question: how to do it?

 My first idea was the following in short:

/**
 * Each service which must be aware of the HessianServlet
 * instance, must implement this interface.
 */
public interface HessianServletAware {
    void setHessianServlet(HessianServlet hessianServlet);
}

// ...

/**
 * This will inject itself to the service object if
 * that implements the HessianServletAware interface.
 */
public class InjectorHessianServlet extends HessianServlet {
//... here I have overriden the init() method and all the setters to
// write a line to the log to see what happens
}

 And then I changed the <servlet-class> lines to my new class
in the web.xml.
 System restarted, everything works fine, init() called, but
the setters are NEVER called. I guess everything happens in init()
and then the servlet object doesn't call its setters, but access
its member variables simply with the . operator.
 Since all those members are private, I can't get their value
in an overridden init(), either. :(

 My other idea was wiring things together through the Spring
IoC container, where I could have Spring instantiate the objects
and call the setters on both sides (servlet object <-> service
object), but the servlet should be instantiated by the container
I guess...

 Or am I missing something?
 What's the right way to do it?
 Thanks a lot.

 Aron Gombas
 3NF Corporation
 www.3nf.com
Received on Wed 20 Jul 2005 08:30:38 -0700

This archive was generated by hypermail 2.1.8 : Thu Sep 28 2006 - 20:16:41 PDT