Correct approach for configuring a WS wich is client and server at the same time.
Hello everybody.
I'm a newbie in both spring and ws, and so far, I like what I see in spring quite a lot.
I've been following the reference documentation, some tutorials, books, etc., and I managed to set up some services, and to make some clients for them.
I am currently in the situation where one ws (lets call it wsA) has to consume another ws (wsB), for which I already have a spring-ws client working . However, I am not able to configure the client inside wsA. The probable cause is that wsA is a rpc-style service that uses CXF.
This is the original wsA app-context:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"
default-dependency-check="none" default-lazy-init="false">
<!-- Load the needed resources that are present in the cxf* jars -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<!-- Hook up the web service -->
<jaxws:endpoint id="store" implementor="store.StoreService"
address="/store"/>
</beans>
..and web.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Tienda de JP</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:appContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
This is the wsB client app-context:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="loggingClient" class="com.mycompany.hr.logging.client.LoggingFacilityServiceImpl">
<property name="defaultUri" value="http://localhost:8080/logging/services/logging"/>
<property name="marshaller" ref="marshaller"/>
<property name="unmarshaller" ref="marshaller"/>
</bean>
<bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
<constructor-arg ref="marshaller" />
</bean>
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.mycompany.hr.types"/>
</bean>
</beans>
Both services and the client are working independently. However, when trying to insert the client into wsA app-context (as simple as copying the definitions of the loggingClient, GenericMarshallingMethodEndpointAdapter, and marshaller in the app-context, and injecting loggingClient into the store endpoint) I get a:
Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cxf.resource.ResourceManager' defined in class path resource [META-INF/cxf/cxf.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter] for bean with name 'org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter#0' defined in class path resource [appContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter
I believe is not a dependency issue, as I use maven for both projects and have the same dependencies.
If I remove the GenericMarshallingMethodEndpointAdapter bean, I get an InvocationTargetException (caused by a NullPointerException) at the createMarshaller() method of AbstractJaxbMarshaller class (jaxbContext is null).
I would really appreciate some help with this, as there are no examples or documentation on merging clients within endpoints. I thought on splitting the configuration files, but I don't know how to inject the client bean into the endpoint if they were defined in two different app-contexts.
All help will be very much appreciated!!.