未调用java Spring WS-EndpointInterceptor
我正在使用SpringWebServices3.0.1开发一个web服务端点
我已经开发了端点和客户端。两者都能正常工作
我的问题是我想向端点添加一个拦截器。我正试图按照spring文档中的解释来做
拦截器的代码:
@Component
public class CustomEndpointInterceptor implements EndpointInterceptor
{
private static final Log LOG = LogFactory.getLog(CustomEndpointInterceptor.class);
@Override
public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception
{
LOG.info("Endpoint Request Handling");
return true;
}
@Override
public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception
{
LOG.info("Endpoint Response Handling");
return true;
}
@Override
public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception
{
LOG.info("Endpoint Exception Handling");
return true;
}
@Override
public void afterCompletion(MessageContext messageContext, Object endpoint, Exception ex) throws Exception
{
LOG.info("Execute code after completion");
}
}
我定义了一个扩展WsConfigurationSupport的配置类。在这个类中,我添加了拦截器
@EnableWs
@Configuration
public class Config extends WsConfigurationSupport
{
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors)
{
interceptors.add(new CustomEndpointInterceptor());
super.addInterceptors(interceptors);
}
}
我的端点非常简单:
@Endpoint
public class SnsEndpoint
{
private static final String NAMESPACE_URI = "es.message";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "testMessage")
public void testMessage(@RequestPayload TestMessage request)
{
LOGGER.log (Level.INFO, "Noficiacion de alta recibida: " + (mensaje != null));
}
}
以及Spring配置文件:
?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/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config />
<context:component-scan
base-package="com.server.endpoint,com.server.endpoint.interceptors,com.server.endpoint.config" />
<sws:annotation-driven />
<sws:static-wsdl id="sns-ws" location="classpath:/mywsdl.wsdl" />
</beans>
我已在“addInterceptors”方法中设置了断点,但未被调用。因此,当我执行请求时,web服务会正确执行,但不会调用端点
为什么没有调用“addInterceptors”方法?我做错了什么
谢谢
# 1 楼答案
决心。从类“WsConfigurationSupport”扩展时,不需要注释@EnableWs。同时删除<;sws:注释驱动/>;从spring配置文件