Spring Integration inbound webservices wsdl generation

user2191296 picture user2191296 · Mar 22, 2013 · Viewed 8.1k times · Source

I am trying to evaluate Spring Integration specially interested in exposing a simple POJO based service into a SOAP based webservice via service activator. Currently I am stuck & have issue generating dynamic wsdl. The WSDL is not loaded & browser shows 404 error. I try to access with the following url on my local

http://localhost:8080/ws-inbound-gateway/echoService
http://localhost:8080/ws-inbound-gateway/echoService/echoService.wsdl

Below is the configuration

inbound-gateway-config.xml

<int:channel id="inbound" />

    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
        <property name="contextPath" value="com.manish.schema.generated" />
    </bean>

    <int-ws:inbound-gateway id="empServiceGateway"
        request-channel="inbound" marshaller="marshaller"
        unmarshaller="marshaller" />

    <int:service-activator input-channel="inbound"
        requires-reply="true" ref="employeeServiceActivator" method="getEmployeeDetails">

    </int:service-activator>

    <bean id="employeeServiceActivator"
        class="org.springframework.integration.samples.ws.EmployeeServiceResponder" />

    <bean id="employeeService" class="com.manish.service.EmployeeService" />

EmployeeService is just a pojo class while EmployeeServiceResponder is a service activator that invokes method on a service class.

For dynamic wsdl generation

spring-ws-config.xml

<import resource="classpath:/META-INF/spring/integration/inbound-gateway-config.xml" />

<sws:dynamic-wsdl id="echoService" portTypeName="empServiceGateway" locationUri="/echoService" targetNamespace="http://manish.niyati.com/echo">
    <sws:xsd location="/WEB-INF/echo.xsd"/>
</sws:dynamic-wsdl>

<bean
    class="org.springframework.ws.server.endpoint.mapping.UriEndpointMapping">
    <property name="defaultEndpoint" ref="empServiceGateway"></property>
</bean>

web.xml

<servlet>
    <servlet-name>spring-ws</servlet-name>
    <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/spring-ws-config.xml</param-value>
    </init-param>
    <init-param>
        <param-name>transformWsdlLocations</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>spring-ws</servlet-name>
    <url-pattern>/echoService</url-pattern>
</servlet-mapping>

Kindly let me know what else is missing in order to make this service accessible as web-service via SI.

Also when I try to access the service from using WebService template I get the SOAPFAULT

02:18:59.436 INFO  [main][org.springframework.ws.soap.saaj.SaajSoapMessageFactory] Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
02:18:59.437 DEBUG [main][org.springframework.ws.soap.saaj.SaajSoapMessageFactory] Using MessageFactory class [com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl]
02:18:59.484 DEBUG [main][org.springframework.ws.client.core.WebServiceTemplate] Opening [org.springframework.ws.transport.http.HttpUrlConnection@249fa95c] to [http://localhost:8080/ws-inbound-gateway/echoService]
02:18:59.519 TRACE [main][org.springframework.ws.soap.saaj.support.SaajUtils] SOAPElement [com.sun.xml.internal.messaging.saaj.soap.ver1_1.Envelope1_1Impl] implements SAAJ 1.3
02:18:59.535 TRACE [main][org.springframework.ws.soap.saaj.support.SaajUtils] SOAPElement [com.sun.xml.internal.messaging.saaj.soap.ver1_1.Body1_1Impl] implements SAAJ 1.3
02:18:59.562 TRACE [main][org.springframework.ws.client.MessageTracing.sent] Sent request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ed:employeeRequest xmlns:ed="http://manish.niyati.com/echo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ed:empid>100</ed:empid> </ed:employeeRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>]
02:18:59.604 TRACE [main][org.springframework.ws.client.MessageTracing.received] Received response [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring xml:lang="en">**java.lang.NullPointerException**</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>] for request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><ed:employeeRequest xmlns:ed="http://manish.niyati.com/echo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ed:empid>100</ed:empid> </ed:employeeRequest></SOAP-ENV:Body></SOAP-ENV:Envelope>]
02:18:59.605 DEBUG [main][org.springframework.ws.client.core.WebServiceTemplate] Received Fault message for request [SaajSoapMessage {http://manish.niyati.com/echo}employeeRequest]
02:18:59.607 TRACE [main][org.springframework.ws.soap.saaj.support.SaajUtils] SOAPElement [com.sun.xml.internal.messaging.saaj.soap.ver1_1.Fault1_1Impl] implements SAAJ 1.3

Thanks in Advance -MS

Answer

Sujan picture Sujan · Mar 22, 2013

You are doing it in a much more complex way. With a simple configuration and using some basic annotations, you can develop a web service in a short time.

I have myself used Apache CXF for web service development and it is quite good for spring based configuration. You can also take a look at this blog. It has shown all the steps with figures to develop a web service with the generation of wsdl and a client to consume the web service.