Q: How can i get access to the <noWiki>ServletContext</noWiki> from my code?
A: There are at least two ways. One is Axis Specific, and one is specified by the JAX-RPC standard.
This is the axis specific way.
HttpServlet srv = (HttpServlet) MessageContext.getCurrentContext().getProperty(HTTPConstants.MC_HTTP_SERVLET); ServletContext context = srv.getServletContext();
This is the JAX-RPC way. Since Axis is an implementaiton of JAX-RPC axis supports this as well. It's more verbose, but then again portable almost always means verbose.
...
import javax.servlet.ServletContext;
import javax.xml.rpc.server.ServiceLifecycle;
import javax.xml.rpc.server.ServletEndpointContext;
...
public class <service>BindingImpl implements <service>, ServiceLifecycle {
...
{{{ ServletContext servletContext; ... {{{ public void destroy() { ... }
public void init(Object context) throws javax.xml.rpc.ServiceException {
ServletEndpointContext soapContext = (ServletEndpointContext) context; servletContext = soapContext.getServletContext(); //serlvet context is now a member field for any soap invocation
...
- }}}