I've found some solutions for this on the net, all of them trying to access
current message context with MessageContext.getCurrentMessageContext(), then
retrieve the ServletContext, then call spring's
WebApplicationContextUtils.getWebApplicationContext(servletContext). This
worked well with axis1 and can work in axis2 handlers, since they have
MessageContext as input parameter for invoke(), but cannot work in
CallbackHandler because it cannot access current message context
(MessageContext.getCurrentMessageContext() returns null). I need spring
beans inside CallbackHandler to access the DB and retrieve the pass for the
given user. 

 

Has anyone solved this problem?

 

I had one not-best-practise idea to store the ApplicationContext in a static
field in some class just upon its creation. For instance in
ContextLoaderListener replace the method contextInitialized with:

 

            public void contextInitialized(ServletContextEvent event) {

                        this.contextLoader = createContextLoader();

                        this.webApplicationContext =
this.contextLoader.initWebApplicationContext(event.getServletContext());

            }

 

And provide field and getter for this context:

 

            private static WebApplicationContext webApplicationContext;

 

            public static WebApplicationContext getWebApplicationContext()
{

        return webApplicationContext;

}

 

Then anywhere in application (including axis2 handlers and CallbackHandler)
I can call MyContextLoaderListener.getWebApplicationContext() and the spring
beans can be accessed.

 

Is this so bad solution? Any better ideas?

Reply via email to