Hi, I don't understand all your issue, but about the message context null, there is an easy way to get access to Servlet context of Axis2 :
In your AxisService class, in init(ServiceContext sc){ ServletContext sc = (ServletContext) sc.getConfigurationContext().getProperty("transport.http.servletContext"); } Then, you should be able to store/read your thread in this context and stop it if necessary. Tony. Subject: AW: [Axis2] - Migrating axis to axis2 and lost servletContext Date: Thu, 9 Jun 2011 11:19:32 +0200 From: josef.stadelm...@axa-winterthur.ch To: java-user@axis.apache.org But in scope="soapsession" I have to define a time-out to get long-lasting-sessions and a state-full-object. If the time-out hits before the next request is made by the session-thread, my service-object (instance-of-the-service-class) (addressed by the servicegroupId), does no longer exists. And as we have our time-out set to about 8hours, real long lasting sessions, the time-out is only hit after 8h. Hence the destroy() method called when the same service-class gets a request then triggers only the destroy-method after 8h, when the service-object timed-out for this-service-object is occurred. We do normally not see the destroy() method being called. This time-out is a very annoying issue in fact! If we would be able to set this time-out programmatically by something like a prepare-to-stop-call(), to let's say 5 seconds, then we could observe how our destroy() method gets called. So initiating threads in the init() method is OK. Keeping threads for a long time is a different issue in scope="soapsession", and the time-out-facility makes the thing not better. Or does somebody know a way how I can call to destruct my service-providing-object, and prove that the destroy() method is then called? Josef Von: Deepal Jayasinghe [mailto:dee...@opensource.lk] Gesendet: Mittwoch, 8. Juni 2011 01:23 An: java-user@axis.apache.org Betreff: Re: [Axis2] - Migrating axis to axis2 and lost servletContext 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