|
From: Michael Y. <sp...@on...> - 2003-12-22 18:18:31
|
Al, this is very good. Thanks! I used the same trick of using
the Axis's static get property method of MessageContext to get hold
of the (Spring) web application context, but I was hoping for more
tighter integration of Axis (or others) into Spring.
/Michael.
On Friday, Dec-19-2003 03:48 AM (PST) ala...@ph... (Alastair Rodgers) wrote:
> Regarding wanting to have an axis servlet specific Spring application context, I recently had the same problem. Here's how I got round it.
>
> In your web.xml, declare the Spring config(s) you want to be available to your web app in a context param and also declare a Spring ContextLoaderListener. This will initialise the Spring context and store it in your servlet context. For example:
>
> <context-param>
> <param-name>contextConfigLocation</param-name>
> <param-value>/WEB-INF/applicationContext-core.xml,/WEB-INF/applicationContext-web.xml</param-value>
> </context-param>
>
> <listener>
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
> </listener>
>
> Now your POJOs which you expose as Axis web services need to be able to get access to the servlet context so they can get at the Spring context. You can do this using the Axis MessageContext. In your POJO you would do something like:
>
> import org.apache.axis.MessageContext;
> import org.apache.axis.transport.http.HTTPConstants;
> import org.springframework.context.ApplicationContext;
> import org.springframework.web.context.support.WebApplicationContextUtils;
> ...
> HttpServlet servlet = (HttpServlet)MessageContext.getCurrentContext().getProperty(HTTPConstants.MC_HTTP_SERVLET);
>
> ApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(servlet.getServletContext());
>
>
> This is the simplest approach, and is OK provided your web services are only ever accessed by HTTP. However, I don't like the fact this exposes the servlet API to your web service object. So to remove this dependency, I created an Axis Handler (HTTPSpringContextHandler extends org.apache.axis.handlers.BasicHandler) which I attach to the HTTP request flow. This handler's invoke() method is along the lines of:
>
> public final void invoke(MessageContext oContext) throws AxisFault
> {
> if (oContext.isClient()) {
> throw new AxisFault("Cannot use server-only handler in a client context");
> }
>
> /* This handler only deals with SOAP requests, not responses */
> if (!context.getPastPivot()) {
>
> HttpServlet servlet = (HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
>
> if (servlet != null) {
> // Get the Spring context from web app context and add it to the Axis message context
> ApplicationContext springContext = WebApplicationContextUtils.getWebApplicationContext(servlet.getServletContext());
> context.setProperty("MySpringContextProperty", springContext);
> }
> }
> }
>
> Add this to the HTTP request flow in your Axis WSDD file:
>
> <transport name="http">
> <requestFlow>
> ...
> <handler type="java:com.blah.HTTPSpringContextHandler"/>
> ...
> </requestFlow>
> </transport>
>
> Then in your web service POJO you can retrieve the Spring context from the Axis MessageContext:
>
> MessageContext msgContext = MessageContext.getCurrentContext();
> ApplicationContext springContext = (ApplicationContext)msgContext.getProperty("MySpringContextProperty");
>
>
> Also, my web service POJOs are just thin wrappers around Spring beans which implement all the functionality, so really the POJOs just become 'adaptors' for Axis.
>
> Hope this helps.
>
> Regards,
> Al.
>
>
>
> > -----Original Message-----
> > From: spr...@li...
> > [mailto:spr...@li...]
> > On Behalf Of Michael Young
> > Sent: 18 December 2003 21:27
> > To: Spr...@li...;
> > Spr...@li...
> > Subject: [Springframework-developer] Spring and axis
> >
> >
> > I wonder if anyone has integrated axis into Spring Framework,
> > or if the gurus can shed some lights on this?
> >
> > We are building a web application with some UI components,
> > but most of the interfaces are Web Services. We are using
> > Spring and Axis. The problem is Axis needs its own servlet so
> > that it knows which web services classes to call when a web
> > services request comes in.
> >
> > So for the axis servlet (and my web services classes that get
> > called it), I can only get hold of the application wide
> > application context from Spring framework. I can't seem to
> > have an axis servlet specific Spring application context.
> >
> > It seems one should be able to use Spring to handle web
> > services requests as well. Spring can just delegate the
> > requests to some controllers, and the controllers will invoke Axis?
> >
> > Any thoughts? Thanks! /Michael.
> >
>
>
> -------------------------------------------------------
> This SF.net email is sponsored by: IBM Linux Tutorials.
> Become an expert in LINUX or just sharpen your skills. Sign up for IBM's
> Free Linux Tutorials. Learn everything from the bash shell to sys admin.
> Click now! http://ads.osdn.com/?ad_id78&alloc_id371&op=click
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|