I am developing a webservice using spring soap implementation and hence my service class is annotated with @Endpoint annotation. Now, I want to use SPRING AOP for application logging which I have already implemented. However, as I have noticed, until I execlude my service class from the pointcut expression, I get no endpoint mapping found exception when my webservice is invoked. When I exclude the service classes from AOP's scope, things work fine again. Any idea on this?
UPDATE:
My logger class
package com.cps.arch.logging;
@Component
@Aspect
public class LoggerAspect {
private static final Logger logger = LoggerFactory.getLogger("Centralized Payment System");
@Before("(execution(* com.cps..*.*(..)) and not execution(* com.cps.service..*.*(..)))")
public void logBefore(JoinPoint joinPoint) {
logger.info("Execution Start : "+"Class: "+joinPoint.getTarget().getClass().getName()+
"Method: "+joinPoint.getSignature().getName());
}
}
My Service Endpoint:
package com.cps.service.impl;
@Endpoint
public class EndpointIntegrationServiceImpl implements EndpointIntegrationService
{
private static final String NAMESPACE_URI = "http://www.example.com/cps/model";
@Autowired
public MYBO myBO ;
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "SaveDataRequest")
public void saveData(@RequestPayload
SaveDataRequest data) {
//business layer invocation
}
}
My WS Configuration
@EnableWs
@Configuration
@ComponentScan(basePackages={"com.cps"})
public class WebServiceConfig extends WsConfigurerAdapter
{
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/ws/*");
}
@Bean(name = "MyWsdl")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema schema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("MyPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://www.example.com/micro/payment/PaymentManagement");
wsdl11Definition.setSchema(reconciliationSchema);
return wsdl11Definition;
}
@Bean
public XsdSchema schema() {
return new SimpleXsdSchema(new ClassPathResource("XSD/MySchema.xsd"));
}
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
interceptors.add(validationInterceptor());
}
@Bean
ValidationInterceptor validationInterceptor() {
final ValidationInterceptor payloadValidatingInterceptor = new ValidationInterceptor();
payloadValidatingInterceptor.setSchema(new ClassPathResource(
"XSD/MySchema.xsd"));
return payloadValidatingInterceptor;
}
}
Sorry but I had to change few of the variable/class names to adhere to company policy. So as you can see I had to put the "not execution" part in the AOP to make my webservice work. If I remove that part, I get 404 error.
Try configuring a
PayloadLoggingInterceptor
Check out section "5.5.2.1. PayloadLoggingInterceptor and SoapEnvelopeLoggingInterceptor" in the Spring Reference Docs
So below is the code you shared
You mentioned that it doesn't works with
But works with
The issues when you call
config
manually, the bean is initiated by you and not by Spring and it somehow interferes. You should not initiate the class using the bean methodconfig()
instead use the class directoryAnd it work fine
@Tarun is right, though I also found it necessary to delay the initialization of the
AppConfig config
bean.Because the
CustomValidatingInterceptor
bean in your (@hudi's) example is anEndpointInterceptor
, it is needed early in the Spring initialization sequence. This means it is being instantiated before the Aop weaving against theconfig
bean has taken effect. Note how there is also anEndpointInterceptor
in the original question here.One way to avoid this is to use an
ObjectFactory
. This can be wired in from the start, but enables Spring to delay the actual instantiation of theconfig
bean, until after the interceptor and Aop proxy are both well initialized.There's an example of this back on your question. This tested fine from SoapUI.