|
From: Michael Y. <sp...@on...> - 2003-12-22 18:19:06
|
That's a nice idea. I guess this will be in m4 build in the next
few days?
Regarding why I would like to have some specific context associated
with Axis servlet, I guess my idea was more along the line of the
way that Spring allows us to have different DispatcherServlet's
with different context associations. I think it'll be more flexible.
However, I still think the following idea is possible:
Get rid of Axis servlet, and integrate Axis (or other WS providers)
more tightly into Spring so that we can have Web Services controllers
that invoke Axis etc.
Does it make sense for other people?
Thanks! --Pinghua
On Friday, Dec-19-2003 04:14 AM (PST) jue...@we... (j=FCrgen=
h=F6ller [werk3AT]) wrote:
> This is very similar to what I use and recommend: keeping the business ob=
jects that your Web Services access in the root application context, if app=
ropriate 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 ty=
pe ServletEndpointContext, allowing access to the ServletContext and thus t=
o the root WebApplicationContext. This is exactly what Spring's new Servlet=
EndpointSupport convenience base class is for: It pre-implements that looku=
p.
> =20
> Implementing an Axis handler to keep your Web Service implementations ind=
ependent 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 d=
eploy your Web Services to any JAX-RPC compliant solution as a JAX-RPC "Ser=
vlet endpoint".
> =20
> Juergen
> =20
>=20
> ________________________________
>=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
>=20
>=20
>=20
> Regarding wanting to have an axis servlet specific Spring application con=
text, I recently had the same problem. Here's how I got round it.
>=20
> 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 ContextLoaderLis=
tener. This will initialise the Spring context and store it in your servlet=
context. For example:
>=20
> <context-param>
> <param-name>contextConfigLocation</param-name>
> <param-value>/WEB-INF/applicationContext-core.xml,/WEB-INF/applicatio=
nContext-web.xml</param-value>
> </context-param>
>=20
> <listener>
> <listener-class>org.springframework.web.context.ContextLoaderListener=
</listener-class>
> </listener>
>=20
> Now your POJOs which you expose as Axis web services need to be able to g=
et 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 somet=
hing like:
>=20
> 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().g=
etProperty(HTTPConstants.MC_HTTP_SERVLET);
>=20
> ApplicationContext springContext =3D WebApplicationContextUtils.getWebApp=
licationContext(servlet.getServletContext());
>=20
>=20
> This is the simplest approach, and is OK provided your web services are o=
nly 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 cre=
ated an Axis Handler (HTTPSpringContextHandler extends org.apache.axis.hand=
lers.BasicHandler) which I attach to the HTTP request flow. This handler's =
invoke() method is along the lines of:
>=20
> public final void invoke(MessageContext oContext) throws AxisFault
> {
> if (oContext.isClient()) {
> throw new AxisFault("Cannot use server-only handler in a client con=
text");
> }
>=20
> /* This handler only deals with SOAP requests, not responses */
> if (!context.getPastPivot()) {
>=20
> HttpServlet servlet =3D (HttpServlet)context.getProperty(HTTPConsta=
nts.MC_HTTP_SERVLET);
>=20
> if (servlet !=3D null) {
> // Get the Spring context from web app context and add it to the =
Axis message context
> ApplicationContext springContext =3D WebApplicationContextUtils.g=
etWebApplicationContext(servlet.getServletContext());
> context.setProperty("MySpringContextProperty", springContext);
> }
> }
> }
>=20
> Add this to the HTTP request flow in your Axis WSDD file:
>=20
> <transport name=3D"http">
> <requestFlow>
> ...
> <handler type=3D"java:com.blah.HTTPSpringContextHandler"/>
> ...
> </requestFlow>
> </transport>
>=20
> Then in your web service POJO you can retrieve the Spring context from th=
e Axis MessageContext:
>=20
> MessageContext msgContext =3D MessageContext.getCurrentContext();
> ApplicationContext springContext =3D (ApplicationContext)msgContext.g=
etProperty("MySpringContextProperty");
>=20
>=20
> Also, my web service POJOs are just thin wrappers around Spring beans whi=
ch implement all the functionality, so really the POJOs just become 'adapto=
rs' for Axis.
>=20
> Hope this helps.
>=20
> Regards,
> Al.
>=20
>=20
>=20
> > -----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.
> >
>=20
>=20
> -------------------------------------------------------
> 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
>=20
>=20
>=20
>=20
> -------------------------------------------------------
> 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=3Dclick
> _______________________________________________
> Springframework-developer mailing list
> Spr...@li...
> https://lists.sourceforge.net/lists/listinfo/springframework-developer
|