Spring Integration入站Web服务WSDL生成

4

我试图评估Spring Integration,特别是将基于简单POJO的服务通过服务激活器暴露为基于SOAP的Web服务。目前我遇到了问题,无法生成动态WSDL。WSDL未加载,浏览器显示404错误。我尝试在本地使用以下URL进行访问:

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

以下是配置信息:
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是一个普通的pojo类,而EmployeeServiceResponder是一个服务激活器,它调用服务类上的方法。

用于动态wsdl生成。

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>

请告诉我还缺少哪些内容,以便将此服务作为Web服务通过SI访问。

另外,当我尝试使用WebService模板访问该服务时,我收到了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

感谢您的提前帮助。 - MS

你是否使用任何参考实现?例如,Apache CXF为使用Spring配置开发Web服务提供了出色的参考实现。 - Sujan
2个回答

0

你正在以一种更复杂的方式进行。通过简单的配置和使用一些基本的注释,您可以在短时间内开发Web服务。

我自己使用Apache CXF进行Web服务开发,对于基于Spring的配置非常好。您还可以查看此博客。它展示了所有步骤和图形,以生成wsdl并创建一个客户端来消耗Web服务。


感谢您的回复,我之前使用过Spring WS并且能够顺利地开发Web服务。但是SI是一种不同的企业消息开发方法。通过SI,应用程序可以根据各种EIP开发。消息可以来自任何来源,包括文件系统、JMS、JPA、WS、REST、Socket、批处理、TCP、HTTP、RMI、JDBC等。 - user2191296

0
要获取WSDL,请将web.xml url-pattern更改为<url-pattern>/*</url-pattern>
URL为http://localhost:8080/ws-inbound-gateway/echoService.wsdl
其他方面看起来都很好。
关于WebServiceTemplateQuestion,你正在发送什么?看起来你正在使用ws示例应用程序,它使用了一个WebServiceTemplate...
@Test
public void testWebServiceRequestAndResponse() {
    StringResult result = new StringResult();
    Source payload = new StringSource(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>");

    template.sendSourceAndReceiveToResult(WS_URI, payload, result);
    logger.info("RESULT: " + result.toString());
    assertThat(result.toString(), equalTo(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoResponse>"));
}

这个很好用。

看起来你的NPE是在服务器上发生的 - 查看服务器日志以了解发生了什么。


完美...现在它已经修好了..也解决了NPE的问题..那是由于不正确的自动装配..谢谢Gary.. - user2191296

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接