Spring WS似乎忽略了映射端点

时间:2014-01-09 11:52:42

标签: spring soap wsdl spring-ws

我想在Spring MVC应用程序中添加一个可消耗合同优先的Web服务 - 该应用程序是Web服务提供者。在web.xml中,我添加了第二个应该处理请求的servlet:

<servlet>
    <servlet-name>webservices</servlet-name>
    <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:/webservices-servlet.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>webservices</servlet-name>
    <url-pattern>/services/*</url-pattern>
</servlet-mapping>

webservices-servlet.xml包含:

<context:component-scan base-package="de.y.application" />

<sws:static-wsdl id="yAdaptorService" location="/WEB-INF/wsdl/yAdapterService.wsdl" />

<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
    <property name="interceptors">
        <list>
            <bean
                class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
            <bean
                class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
                <property name="schema" value="/WEB-INF/wsdl/ResourceAdapter.xsd" />
                <property name="validateRequest" value="true" />
                <property name="validateResponse" value="true" />
            </bean>
        </list>
    </property>
    <property name="order" value="1" />
</bean>

在Tomcat 7中部署和启动应用程序时,将部署WSDL http://localhost:8080/application/services/yAdapterService.wsdl

相关的WSDL片段:

<message name="pingRequest">
</message>
<message name="pingResponse">
</message>
<portType name="yAdaptor">
    <operation name="ping">
        <input message="tns:pingRequest"></input>
        <output message="tns:pingResponse"></output>
    </operation>
</portType>
<binding name="SoapBinding" type="tns:yAdapter">
    <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <operation name="ping">
        <wsdlsoap:operation soapAction="urn:webservice.y.x.com:wsdl/ping"/>
        <input>
            <wsdlsoap:body use="literal"/>
        </input>
        <output>
            <wsdlsoap:body use="literal"/>
        </output>
    </operation>
</binding>
<service name="yAdapterService">
    <port binding="tns:SoapBinding" name="yAdapterSoapPort">
        <wsdlsoap:address location="http://localhost:8080/application/services/yAdapterService"/>
    </port>
</service>

将logger设置为调试级别,Tomcat在启动时告诉我:

09 Jan 2014 12:20:49,247 DEBUG org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping:105 - Mapped [{urn:webservice.x.com:wsdl}ping] onto endpoint [public void de.y.yAdapterService.ping()]

但是当谈到通过SOAP-UI的简单ping请求时

SOAPAction: urn:webservice.x.com:wsdl/ping

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body/>
</soapenv:Envelope>

到此端点

private static final String NAMESPACE_URI   = "urn:webservice.x.com:wsdl";

@Override
@PayloadRoot(localPart = "ping", namespace = NAMESPACE_URI)
public void ping()
{
    System.out.println("ping pong");
}

无法找到映射的端点

/* SOAP-UI REQUEST ON urn:webservice.x.com:wsdl/ping */
09 Jan 2014 12:21:44,808 DEBUG     org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter:136 - Opening JPA EntityManager in OpenEntityManagerInViewFilter
09 Jan 2014 12:21:44,818 DEBUG org.springframework.security.util.FilterChainProxy:205 - Converted URL to lowercase, from: '/services/yadapterservice'; to: '/services/yadapterservice'
09 Jan 2014 12:21:44,818 DEBUG org.springframework.security.util.FilterChainProxy:212 - Candidate is: '/services/yadapterservice'; pattern is /services/**; matched=true
09 Jan 2014 12:21:44,818 DEBUG org.springframework.security.util.FilterChainProxy:165 -  has an empty filter list
09 Jan 2014 12:21:44,827 DEBUG org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter:114 - Accepting incoming [org.springframework.ws.transport.http.HttpServletConnection@63a595be] at [http://localhost:8080/application/services/yAdapterService]
09 Jan 2014 12:21:44,864 DEBUG org.springframework.ws.server.MessageTracing.received:171 - Received request [SaajSoapMessage]
09 Jan 2014 12:21:44,875 DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher:278 - Endpoint mapping [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping@b64f867] has no mapping for request
09 Jan 2014 12:21:44,876  WARN org.springframework.ws.server.EndpointNotFound:241 - No endpoint mapping found for [SaajSoapMessage]
09 Jan 2014 12:21:44,877 DEBUG org.springframework.ws.transport.http.MessageDispatcherServlet:966 - Successfully completed request
09 Jan 2014 12:21:44,877 DEBUG org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter:154 - Closing JPA EntityManager in OpenEntityManagerInViewFilter
09 Jan 2014 12:21:44,878 DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils:338 - Closing JPA EntityManager

我错过了什么?为什么找不到最初映射的端点?

1 个答案:

答案 0 :(得分:0)

最后我发现SOAP-UI在解析WSDL时使用了错误的命名空间。正确的请求消息是:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:webservice.x.com:wsdl">
    <soapenv:Header/>
    <soapenv:Body>
        <urn:ping/>
    </soapenv:Body>
</soapenv:Envelope>