我在尝试让端点映射适用于我的 Web 服务时遇到问题。我使用 Tomcat 来托管我的 Web 服务,并使用soapUI 向其发送测试消息。
Tomcat 日志中的以下消息显示了端点映射 bean 的创建:
6458 [http-apr-8080-exec-6] DEBUG org.springframework.ws.soap.server.endpoint.mapping.SoapActionEndpointMapping - Mapped key [{http://endpoint.ws.example.com}pushAbcToXyzOperation] onto endpoint [com.abc.xc.model.PushAbcToXyzRequest@131ebb3[...]]
但是,端点映射 bean 一定不正确,因为我收到以下“未找到端点映射”消息:
6739 [http-apr-8080-exec-6] WARN org.springframework.ws.server.EndpointNotFound - No endpoint mapping found for [SaajSoapMessage {http://endpoint.ws.example.com}pushAbcToXyzOperation]
这是 web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="2.4">
<display-name>abc2xyzWS</display-name>
<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-context.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>spring-ws</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
这是 spring-ws-context.xml
<?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:sws="http://www.springframework.org/schema/web-services"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd">
<sws:annotation-driven/>
<context:annotation-config />
<import resource="classpath:/xyz-endpoint-context.xml" />
<!--==========================================================
*
* Spring Web Service Configuration
*
=============================================================-->
<bean name="loadPayload" class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
<description>
Detects @PayloadRoot annotations on @Endpoint bean methods.
</description>
<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="classpath:/AbcAPI.xsd"/>
<property name="validateRequest" value="true"/>
<property name="validateResponse" value="true"/>
</bean>
</list>
</property>
<property name="order" value="1"/>
</bean>
<bean id="pushService" class="com.abc.xc.model.PushAbcToXyzRequest"/>
<bean id="endpointMapping" class="org.springframework.ws.soap.server.endpoint.mapping.SoapActionEndpointMapping">
<property name="mappings">
<props>
<prop key="{http://endpoint.ws.example.com}pushAbcToXyzOperation">pushService</prop>
</props>
</property>
</bean>
</beans>
这是 xyz-endpoint-context.xml
<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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<import resource="classpath:/applicationContext.xml" />
<context:component-scan base-package="com.abc.ws.endpoint"/>
</beans>
这是 applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<!--===========================================================================
*
* opis2pips service module configuration.
*
=============================================================================-->
<context:property-placeholder location="classpath:/applicationContext.properties"/>
<context:component-scan base-package="com.abc.xc.service"/>
<bean id="serviceURL" class="java.lang.String">
<constructor-arg><value>${serviceURL}</value></constructor-arg>
</bean>
...
<bean id="emailerrormessage" class="java.lang.String">
<constructor-arg><value>${emailerrormessage}</value></constructor-arg>
</bean>
</beans>
这是端点
package com.abc.ws.endpoint.endpoint;
import com.abc.xc.model.WSstatusType;
import com.abc.xc.model.PushAbcToXyzRequest;
import com.abc.xc.model.QueryXyzRequest;
import com.abc.xc.model.XyzResponse;
import com.abc.xc.service.XyzClient;
import com.abc.xc.service.WSemailService;
import com.abc.xc.service.AbcToXyzTranslationService;
import com.abc.xc.exception.WSexception;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ws.server.endpoint.annotation.Endpoint;
import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
import org.springframework.ws.server.endpoint.annotation.RequestPayload;
import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
import contracts.xyz.GetTicketResponse;
import contracts.xyz.PostTicketResponse;
import contracts.xyz.Ticket;
import contracts.xyz.TicketMessageProcessingResult;
@Endpoint
public class XyzWebServiceController {
@Autowired
private XyzClient XyzClientservice;
@Autowired
private AbcToXyzTranslationService translationservice;
@Autowired
WSemailService mailservice;
protected static final String NAMESPACE_URI = "http://www.example.com/schema";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "PushAbcToXyzRequest")
@ResponsePayload
public XyzResponse PushAbcToXyzOperation(@RequestPayload PushAbcToXyzRequest PushAbcToXyzRequest){
XyzResponse XyzResponse = null;
Ticket ticket = null;
try {
ticket = translationservice.abcInputToXyzTicket(PushAbcToXyzRequest);
PostTicketResponse response = XyzClientservice.postTicket(ticket);
Long transactionid = response.getInteractionId();
if(transactionid != null){
GetTicketResponse gtresponse = XyzClientservice.getTicket();
Ticket gtresponseTicket = gtresponse.getTicket().getValue();
XyzResponse = translationservice.XyzTicketToXyzResponse(gtresponseTicket);
}
XyzResponse.setWSstatus(WSstatusType.SUCCESS);
mailservice.sendEmail(true, PushAbcToXyzRequest, transactionid);
...
这是 SOAP 请求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:end="http://endpoint.ws.example.com" xmlns:mod="http://model.xc.example.com">
<soapenv:Header/>
<soapenv:Body>
<end:pushAbcToXyzOperation>
<end:pushAbcToXyzRequest>
...
</end:pushAbcToXyzRequest>
</end:pushAbcToXyzOperation>
</soapenv:Body>
</soapenv:Envelope>
以下是 Tomcat 日志的一部分,从端点映射 bean 的创建到“未找到端点映射”消息:
6349 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'loadPayload'
6349 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'pushService'
6349 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'pushService'
6365 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'pushService' to allow for resolving potential circular references
6427 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'pushService'
6427 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating shared instance of singleton bean 'endpointMapping'
6427 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Creating instance of bean 'endpointMapping'
6427 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Eagerly caching bean 'endpointMapping' to allow for resolving potential circular references
6443 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'pushService'
6458 [http-apr-8080-exec-6] DEBUG org.springframework.ws.soap.server.endpoint.mapping.SoapActionEndpointMapping - Mapped key [{http://endpoint.ws.example.com}pushAbcToXyzOperation] onto endpoint [com.abc.xc.model.PushAbcToXyzRequest@131ebb3[requestID=<null>, ...]]
6458 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Finished creating instance of bean 'endpointMapping'
6458 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor$ImportAwareBeanPostProcessor#0'
6474 [http-apr-8080-exec-6] DEBUG org.springframework.web.context.support.XmlWebApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@13a0067]
6474 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
6505 [http-apr-8080-exec-6] INFO org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Creating SAAJ 1.3 MessageFactory with SOAP 1.1 Protocol
6505 [http-apr-8080-exec-6] DEBUG org.springframework.ws.soap.saaj.SaajSoapMessageFactory - Using MessageFactory class [com.sun.xml.internal.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl]
6505 [http-apr-8080-exec-6] DEBUG org.springframework.ws.transport.http.MessageDispatcherServlet - No WebServiceMessageFactory found in servlet 'spring-ws': using default
6505 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter#0'
6521 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.ws.soap.server.endpoint.SoapFaultAnnotationExceptionResolver#0'
6521 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver#0'
6521 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping#0'
6521 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.ws.soap.server.endpoint.mapping.SoapActionAnnotationMethodEndpointMapping#0'
6521 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.ws.soap.addressing.server.AnnotationActionEndpointMapping#0'
6521 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'loadPayload'
6521 [http-apr-8080-exec-6] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'endpointMapping'
6521 [http-apr-8080-exec-6] DEBUG org.springframework.ws.transport.http.MessageDispatcherServlet - No MessageDispatcher found in servlet 'spring-ws': using default
6521 [http-apr-8080-exec-6] DEBUG org.springframework.ws.transport.http.MessageDispatcherServlet - Published WebApplicationContext of servlet 'spring-ws' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.spring-ws]
6521 [http-apr-8080-exec-6] INFO org.springframework.ws.transport.http.MessageDispatcherServlet - FrameworkServlet 'spring-ws': initialization completed in 6053 ms
6521 [http-apr-8080-exec-6] DEBUG org.springframework.ws.transport.http.MessageDispatcherServlet - Servlet 'spring-ws' configured successfully
6583 [http-apr-8080-exec-6] DEBUG org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter - Accepting incoming [org.springframework.ws.transport.http.HttpServletConnection@7ac6c] at [http://localhost:8080/abc2xyzWS/services/XyzWebServiceController]
6677 [http-apr-8080-exec-6] DEBUG org.springframework.ws.server.MessageTracing.received - Received request [SaajSoapMessage {http://endpoint.ws.example.com}pushAbcToXyzOperation]
6723 [http-apr-8080-exec-6] DEBUG org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping - Looking up endpoint for [{http://endpoint.ws.example.com}pushAbcToXyzOperation]
6723 [http-apr-8080-exec-6] DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Endpoint mapping [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping@14481bb] has no mapping for request
6723 [http-apr-8080-exec-6] DEBUG org.springframework.ws.soap.server.endpoint.mapping.SoapActionAnnotationMethodEndpointMapping - Looking up endpoint for []
6723 [http-apr-8080-exec-6] DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Endpoint mapping [org.springframework.ws.soap.server.endpoint.mapping.SoapActionAnnotationMethodEndpointMapping@a14fed] has no mapping for request
6723 [http-apr-8080-exec-6] DEBUG org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping - Looking up endpoint for [{http://endpoint.ws.example.com}pushAbcToXyzOperation]
6723 [http-apr-8080-exec-6] DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Endpoint mapping [org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping@868c6d] has no mapping for request
6723 [http-apr-8080-exec-6] DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Endpoint mapping [org.springframework.ws.soap.addressing.server.AnnotationActionEndpointMapping@45484a] has no mapping for request
6723 [http-apr-8080-exec-6] DEBUG org.springframework.ws.soap.server.SoapMessageDispatcher - Endpoint mapping [org.springframework.ws.soap.server.endpoint.mapping.SoapActionEndpointMapping@8d00c6] has no mapping for request
6739 [http-apr-8080-exec-6] WARN org.springframework.ws.server.EndpointNotFound - No endpoint mapping found for [SaajSoapMessage {http://endpoint.ws.example.com}pushAbcToXyzOperation]
如果您需要查看任何其他信息,请告诉我,并提前感谢您为解决此问题提供的任何帮助。
请您参考如下方法:
我们遇到了类似的问题,在我们的例子中,EndPoint 未包含在 spring 配置的组件扫描指令中。
在您表示正在使用的配置中:
<context:component-scan base-package="com.abc.ws.endpoint"/>
但是您的端点位于下一个包中:
package com.abc.ws.endpoint.endpoint;
所以你必须更改组件扫描标签,例如:
<context:component-scan base-package="com.abc.ws.endpoint.endpoint"/>
或者将端点重构为另一个包。