In Axis2 it has four different type of sessions and transport session is
one of them. So, you have access to the serveltContext only if you use
the transport session.

You can deploy the service in any scope and create the threads inside
the init method and write the code to stop them inside the destroy
method. When the session complete, Axis2 automatically calls the destroy
method and invoke your code. One thing you need to keep in mind is the
number of services instances, in Axis2 for each new session it creates a
new service impl class. And also use the following reference:

http://www.developer.com/db/article.php/3735771/Exposing-a-Database-as-a-Web-Service.htm
http://blogs.deepal.org/2009/06/axis2-tutorials-and-articles.html

Deepal

On 6/7/2011 6:11 PM, April Easton wrote:
>
> Good day,
>
>      I have almost successfully converted our axis service to an axis2
> service.  It all works, except stopping the threads that are created
> by this service.  With axis, we used the ServletContextListener
> destroy method to access the
> ServletContext.getAttribute("AxisServiceInstance") that was written in
> AxisService and then call the stopThread() method.  I have been having
> great difficulties in converting this small piece of the project.  I
> have tried to get the MessageContext in AxisService and write the
> ServletContext.setAttribute("AxisServiceInstance").  The
> MessageContext is always null.  I have placed this Listener in
> axis2/WEB-INF/lib.  The posts that I've been reading make this look so
> easy.  What am I overlooking?  Here is a snapshot of my code.
>
>  
>
> *public**class*AxisListener *implements*ServletContextListener {
>
>      
>
>       *public**void*contextInitialized(ServletContextEvent event){
>
>             System./out/.println(*this*.getClass().getName() +
> ":contextInitialized:context is "+
> event.getServletContext().getRealPath(""));
>
>       }//contextInitialized()
>
>      
>
>      
>
>       *public**void*contextDestroyed(ServletContextEvent event) {
>
>             System./out/.println(*this*.getClass().getName() +
> ":contextDestroyed:before destroyThread.");
>
>            
>
>             AxisService axisService = (AxisService)
> event.getServletContext().getAttribute("AxisServiceInstance");
>
>             axisService.stopThread();
>
>       }//contextDestroyed()
>
> }     //ServletContextListener
>
>  
>
>  
>
> *public**class*AxisService {   
>
>                  
>
>       *public*AxisService() {
>
>             *this*.init();
>
>       }//Constructor
>
>  
>
>       *private**void*init(){
>
>             .
>
>             .
>
>             .    
>
>             //This is the best that I've found using the posts to date:
>
>             //set Attributes to be used by
> AxisListener#contextDestroyed(ServletContextEvent event)
>
> MessageContext msgContext = MessageContext./getCurrentMessageContext/();
>
>             log.debug(*this*.getClass().getName() +
> ":init:messageContext:"+ msgContext);      //This is Always null  
>
>            
> //((ServletContext)msgContext.getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT)).setAttribute("AxisServiceInstance",
> axisService);
>
>  
>
>             //Here is what it was:
>
>             //set Attributes to be used by
> AxisListener#contextDestroyed(ServletContextEvent event)
>
>             _MessageContext_ msgContext=
> _MessageContext_.getCurrentContext();
>
>            
> (((HttpServlet)msgContext.getProperty(_HTTPConstants_.MC_HTTP_SERVLET)).getServletContext()).setAttribute("AxisServiceInstance",axisService);
>
>       }//init()
>
>  
>
> Thank you,
>
> April
>
>  
>

Reply via email to