Differences between revisions 2 and 3
Revision 2 as of 2005-01-12 02:27:01
Size: 1252
Comment: Fixing typo
Revision 3 as of 2009-09-20 22:48:34
Size: 1254
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 13: Line 13:
This is the [http://java.sun.com/xml/jaxrpc/ JAX-RPC] way. Since Axis is an implementation of JAX-RPC axis supports this as well. It's more verbose, but then again portable almost always means verbose. This is the [[http://java.sun.com/xml/jaxrpc/|JAX-RPC]] way. Since Axis is an implementation of JAX-RPC axis supports this as well. It's more verbose, but then again portable almost always means verbose.

Q: How can i get access to the ServletContext 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 implementation 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 
    } 
... 

FrontPage/Axis/ServletContext (last edited 2009-09-20 22:48:34 by localhost)