In my Camel (2.14.0) application I use Spring Web Services to trigger Camel routes. The artifact is built as an OSGi bundle and deployed in Karaf (3.0.2).
For the first version I configured spring-ws to use the JVM internal web server through the org.springframework.remoting.support.SimpleHttpServerFactoryBean
to expose the web service. This works just fine. But is not very OSGi-ish. So instead I would like to publish the org.springframework.ws.transport.http.MessageDispatcherServlet
as a service to the Karaf whiteboard extender like so:
<bean id="pas-ws-patient-servlet" class="org.springframework.ws.transport.http.MessageDispatcherServlet">
<property name="contextConfigLocation" value="/endpoint-mapping.xml" />
</bean>
<osgi:service ref="pas-ws-patient-servlet" interface="javax.servlet.http.HttpServlet">
<service-properties>
<entry key="alias" value="/${pas.ws.patient.contextroot}" />
</service-properties>
</osgi:service>
Which works like a charm for "regular" servlets. But the MessageDispatcherServlet
wants to build its own WebApplicationContext
and expects to find a bean of type org.springframework.ws.server.EndpointMapping
in that context. Camel provides an implementation of EndpointMapping
that has to be used with its spring-ws component.
The problem I am facing is that the same instance of the endpoint mapping bean must be shared between the OsgiBundleXmlApplicationContext
that creates the Camel context and the application context created by the MessageDispatcherServlet
. Which would be the case if my OsgiBundleXmlApplicationContext
was the parent of the WebApplicationContext
. Though how to set the parent context of the WebApplicationContext
to the "current" context from which I am publishing the servlet as a service eludes me.
Instantiating a WebApplicationContext
from within the OsgiBundleXmlApplicationContext
to pass it to the MessageDispatcherServlet gives me an exception:
java.lang.IllegalArgumentException: Cannot resolve ServletContextResource without ServletContext
Unfortunately the WebServiceMessageReceiver
(which encapsulates the EndpointMapping
) of the MessageDispatcherServlet
is a private member. So I cannot set the mapping bean either in a straight forward way.
Is there a way to create the context hierarchy? Or can a bean instance be shared across contexts in another way?