4

我正在尝试评估 Spring Integration,特别是对通过服务激活器将基于 POJO 的简单服务公开到基于 SOAP 的 Web 服务感兴趣。目前我被困在生成动态 wsdl 时遇到问题。WSDL 未加载,浏览器显示 404 错误。我尝试在本地访问以下网址

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

下面是配置

入站网关-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>

请让我知道还缺少什么,以便通过 SI 将此服务作为 Web 服务访问。

此外,当我尝试使用 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

4

2 回答 2

0

您正在以更复杂的方式进行操作。通过简单的配置和一些基本的注解,您可以在短时间内开发出一个 Web 服务。

我自己使用Apache CXF进行 Web 服务开发,它非常适合基于 Spring 的配置。你也可以看看这个博客。它用数字显示了开发 Web 服务的所有步骤,生成 wsdl 和客户端来使用 Web 服务。

于 2013-03-22T08:57:08.650 回答
0

要获取 WSDL,请将 web.xml url-pattern 更改为<url-pattern>/*</url-pattern>.

网址是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>"));
}

这很好用。

Looks like your NPE is on the server - take a look at the server logs to see what happened.

于 2013-03-22T13:08:25.147 回答