1 year ago
#70528

Marco Domenicano
Spring WS error on define two endpoint with same Namespace and localPart
i'm trying to update a project and merge two different module into one. I actually have to define a Spring WS with two @Endpoint which map same @PayloadRoot but they're invoke by different endpoint but i get an error:
Caused by: org.springframework.context.ApplicationContextException: Cannot map endpoint [..omissis..] on registration key [..omissis..]: there's already endpoint [..omissis..] mapped
EndpointA:
@Endpoint
public class EndpointA {
private static final String NAMESPACE_URI = "http://example.com";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "sendSomething")
@ResponsePayload
public Response sendSomething(@RequestPayload Request message) {
methodA();
}
EndpointB:
@Endpoint
public class EndpointB {
private static final String NAMESPACE_URI = "http://example.com";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "sendSomething")
@ResponsePayload
public Response sendSomething(@RequestPayload Request message) {
methodB();
}
WebService:
@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet,"/endpointA/services/*","/endpointB/services/*");
}
How can i relate with this configuration without changing WSDL definition?
UPDATE #1:
After M.Denium help i've tried to register two endpoint separately with two applicationContext like this:
import ...
//@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurationSupport {
@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
interceptors.add(new EndpointInterceptor());
}
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServletA(ApplicationContext applicationContext) {
AnnotationConfigWebApplicationContext annotationConfigApplicationContext=new AnnotationConfigWebApplicationContext();
annotationConfigApplicationContext.register(EndpointA.class);
annotationConfigApplicationContext.setParent(applicationContext);
annotationConfigApplicationContext.refresh();
MessageDispatcherServlet servlet = new MessageDispatcherServlet(annotationConfigApplicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet,"/clientA/services/*");
}
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServletB(ApplicationContext applicationContext) {
AnnotationConfigWebApplicationContext annotationConfigApplicationContext=new AnnotationConfigWebApplicationContext();
annotationConfigApplicationContext.register(EndpointB.class);
annotationConfigApplicationContext.setParent(applicationContext);
annotationConfigApplicationContext.refresh();
MessageDispatcherServlet servlet = new MessageDispatcherServlet(annotationConfigApplicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet,"/clientB/services/*");
}
And excluding this class from component-scan:
ComponentScan(basePackages = "com.example",excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,value = EndpointA.class),@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,value = EndpointB.class)})
public class ExampleApplication {
public static void main(String[] args) {
SpringApplication.run(ExampleApplication.class, args);
}
}
But i'm getting an error:
|| WARN | EndpointNotFound.dispatch:237 | No endpoint mapping found for [SaajSoapMessage
I've tried without splitting applicationContext and removing exclude two endpoint and it worked (obviously with only one @Endpoint annotation). Am I making some mistakes?
java
spring
spring-boot
soap
spring-ws
0 Answers
Your Answer