axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From April Easton <AEas...@shawneecourt.org>
Subject [Axis2] - Migrating axis to axis2 and lost servletContext
Date Tue, 07 Jun 2011 22:11:45 GMT
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


Mime
View raw message