I hope you are well and can help me with the following problem.
I want to configure a SOAP webservice which offers several services, based on an example where I create the following file usuaridos.xsd ...
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.servicio.com/usuarios-ws"
targetNamespace="http://www.servicio.com/usuarios-ws" elementFormDefault="qualified">
//Defino la estructura de mi xsd
</xs:schema>
The class that corresponds to the Endpoint for my service is as follows.
@Endpoint
public class UsuariosEndpoint {
private static final String NAMESPACE_URI = "http://www.servicio.com/usuarios-ws";
@Autowired
private UsuarioService usuarioService;
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getUsuarioByIdRequest")
@ResponsePayload
public GetUsuarioByIdResponse getUsuario(@RequestPayload GetUsuarioByIdRequest request) {
GetUsuarioByIdResponse response = new GetUsuarioByIdResponse();
UsuarioInfo usuarioInfo = new UsuarioInfo();
BeanUtils.copyProperties(usuarioService.getUsuarioById(request.getIdUsuario()), UsuarioInfo);
response.setUsuarioInfo(usuarioInfo);
return response;
}
}
Finally, the configuration class.
@Configuration
@EnableWs
public class WSConfig extends WsConfigurerAdapter {
@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/soapws/*");
}
@Bean(name = "usuarios")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema studentsSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("UsuariosPort");
wsdl11Definition.setLocationUri("/soapws");
wsdl11Definition.setTargetNamespace("http://www.servicio.com/usuarios-ws");
wsdl11Definition.setSchema(usuariosSchema);
return wsdl11Definition;
}
@Bean
public XsdSchema usuariosSchema() {
return new SimpleXsdSchema(new ClassPathResource("xsds/usuarios.xsd"));
}
}
So far so good, I can get information that provides this service. What I want is to use a second xsd, with its respective endpoint, which would be the following.
The second xsd purchases.xsd ...
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.servicio.com/compras-ws"
targetNamespace="http://www.servicio.com/compras-ws" elementFormDefault="qualified">
//Defino la estructura de mi xsd
</xs:schema>
The class that corresponds to the Endpoint for my service is as follows.
@Endpoint
public class ComprasEndpoint {
private static final String NAMESPACE_URI = "http://www.servicio.com/compras-ws";
@Autowired
private ComprasService comprasService;
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "getCompraByIdRequest")
@ResponsePayload
public GetCompraByIdResponse getCompra(@RequestPayload GetCompraByIdRequest request) {
GetCompraByIdResponse response = new GetCompraByIdResponse();
CompraInfo compraInfo = new CompraInfo();
BeanUtils.copyProperties(compraService.getCompraById(request.getIdCompra()), CompraInfo);
response.setCompraInfo(compraInfo);
return response;
}
}
I do not know how to configure the two services in the same project because DefaultWsdl11Definition, which generates what the WSDL generates, only generates one, if you could help me please. Thank you very much in advance.