I'm developing an web service endpoint using spring web services 3.0.1.
I've developed the endpoint and a client. Both works properly.
My problem is that I want to add an interceptor to my endpoint. I'm trying to do it as is explained in the spring documentation.
The code of the interceptor:
@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");
}
}
I've defined a configuration class that extends WsConfigurationSupport. In this class I add my interceptor.
@EnableWs
@Configuration
public class Config extends WsConfigurationSupport
{
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors)
{
interceptors.add(new CustomEndpointInterceptor());
super.addInterceptors(interceptors);
}
}
My endpoint in really simple:
@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));
}
}
And the Spring config file:
?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>
I've set a breakpoint in the 'addInterceptors' method, but is not being invoked. So when I do a request, the web service is executed properly, but the endpoint is not being called.
Why 'addInterceptors' method is not being invoked? What I am doing wrong?
Thanks
Resolved. It is not necesary the annotation @EnableWs when extending from class "WsConfigurationSupport". Also remove <sws:annotation-driven /> from spring configuration file.