|
From: <jue...@we...> - 2003-12-19 12:15:36
|
This is very similar to what I use and recommend: keeping the business =
objects that your Web Services access in the root application context, =
if appropriate in a separate definition file.
=20
In contrast to the Axis-specific MessageContext, you can also use the =
JAX-RPC ServiceLifecycle interface: The passed in context object will be =
of type ServletEndpointContext, allowing access to the ServletContext =
and thus to the root WebApplicationContext. This is exactly what =
Spring's new ServletEndpointSupport convenience base class is for: It =
pre-implements that lookup.
=20
Implementing an Axis handler to keep your Web Service implementations =
independent from the Servlet API is not a bad idea. But of course, you =
depend on Axis then, which might be even less desirable. By implementing =
javax.rpc.server.ServiceLifecycle or deriving from =
ServletEndpointSupport, you can deploy your Web Services to any JAX-RPC =
compliant solution as a JAX-RPC "Servlet endpoint".
=20
Juergen
=20
________________________________
Von: spr...@li... im Auftrag =
von Alastair Rodgers
Gesendet: Fr 19.12.2003 12:48
An: spr...@li...
Betreff: RE: [Springframework-developer] Spring and axis
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/applicationCon=
text-web.xml</param-value>
</context-param>
<listener>
=
<listener-class>org.springframework.web.context.ContextLoaderListener</li=
stener-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 =3D =
(HttpServlet)MessageContext.getCurrentContext().getProperty(HTTPConstants=
.MC_HTTP_SERVLET);
ApplicationContext springContext =3D =
WebApplicationContextUtils.getWebApplicationContext(servlet.getServletCon=
text());
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 =3D =
(HttpServlet)context.getProperty(HTTPConstants.MC_HTTP_SERVLET);
if (servlet !=3D null) {
// Get the Spring context from web app context and add it to the =
Axis message context
ApplicationContext springContext =3D =
WebApplicationContextUtils.getWebApplicationContext(servlet.getServletCon=
text());
context.setProperty("MySpringContextProperty", springContext);
}
}
}
Add this to the HTTP request flow in your Axis WSDD file:
<transport name=3D"http">
<requestFlow>
...
<handler type=3D"java:com.blah.HTTPSpringContextHandler"/>
...
</requestFlow>
</transport>
Then in your web service POJO you can retrieve the Spring context from =
the Axis MessageContext:
MessageContext msgContext =3D MessageContext.getCurrentContext();
ApplicationContext springContext =3D =
(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_id=1278&alloc_id371&op=3Dick
_______________________________________________
Springframework-developer mailing list
Spr...@li...
https://lists.sourceforge.net/lists/listinfo/springframework-developer
|