Soap 使用SpringWS路由WS寻址响应
我对soapweb服务,尤其是WS-Addressing没有太多经验。我试图创建一个示例,根据WS-Addressing规范,服务器的响应路由到另一个服务器而不是客户端。但我面临一些问题,我将在下文中解释 因此,有3个服务:客户机、服务器和响应接收器 以下是客户端的配置: ClientConfiguration.java CountryWsClient.java 服务器的配置: WsConfiguration.java 响应接收器的配置与服务器的配置几乎相同,因为它们使用相同的xsd模式: WsConfiguration.java 完整的示例可以在 当我启动客户端的WS-Addressing请求(通过/kick-REST-controller)时,响应接收器接收来自服务器的响应,但由于一些“mustUnderstand-headers”问题,它无法处理该响应(我不太了解它是什么)。这是响应接收器的日志:Soap 使用SpringWS路由WS寻址响应,soap,spring-ws,ws-addressing,Soap,Spring Ws,Ws Addressing,我对soapweb服务,尤其是WS-Addressing没有太多经验。我试图创建一个示例,根据WS-Addressing规范,服务器的响应路由到另一个服务器而不是客户端。但我面临一些问题,我将在下文中解释 因此,有3个服务:客户机、服务器和响应接收器 以下是客户端的配置: ClientConfiguration.java CountryWsClient.java 服务器的配置: WsConfiguration.java 响应接收器的配置与服务器的配置几乎相同,因为它们使用相同的xsd模式: Ws
2019-12-12 10:45:01.433 TRACE 17188 --- [nio-8282-exec-1] o.s.ws.server.MessageTracing.received : Received request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:To SOAP-ENV:mustUnderstand="1">http://localhost:8282/ws</wsa:To><wsa:Action>http://www.rinat.my/country/getCountryResponse</wsa:Action><wsa:MessageID>urn:uuid:340c83d7-6470-444e-b845-cea844e57400</wsa:MessageID><wsa:RelatesTo>urn:uuid:25e481a1-887b-4b28-a921-8615e1a08d83</wsa:RelatesTo></SOAP-ENV:Header><SOAP-ENV:Body><ns2:getCountryResponse xmlns:ns2="http://www.rinat.my/country/gen"><ns2:country><ns2:name>Poland</ns2:name><ns2:population>38186860</ns2:population><ns2:capital>Warsaw</ns2:capital><ns2:currency>PLN</ns2:currency></ns2:country></ns2:getCountryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>]
2019-12-12 10:45:01.441 WARN 17188 --- [nio-8282-exec-1] o.s.w.soap.server.SoapMessageDispatcher : Could not handle mustUnderstand headers: {http://www.w3.org/2005/08/addressing}To. Returning fault
2019-12-12 10:45:01.450 TRACE 17188 --- [nio-8282-exec-1] o.s.ws.server.MessageTracing.sent : Sent response [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:MustUnderstand</faultcode><faultstring xml:lang="en">One or more mandatory SOAP header blocks not understood</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>] for request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:To SOAP-ENV:mustUnderstand="1">http://localhost:8282/ws</wsa:To><wsa:Action>http://www.rinat.my/country/getCountryResponse</wsa:Action><wsa:MessageID>urn:uuid:340c83d7-6470-444e-b845-cea844e57400</wsa:MessageID><wsa:RelatesTo>urn:uuid:25e481a1-887b-4b28-a921-8615e1a08d83</wsa:RelatesTo></SOAP-ENV:Header><SOAP-ENV:Body><ns2:getCountryResponse xmlns:ns2="http://www.rinat.my/country/gen"><ns2:country><ns2:name>Poland</ns2:name><ns2:population>38186860</ns2:population><ns2:capital>Warsaw</ns2:capital><ns2:currency>PLN</ns2:currency></ns2:country></ns2:getCountryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>]
2019-12-12 10:45:01.433跟踪17188---[nio-8282-exec-1]o.s.ws.server.MessageTracing.received:接收到的请求[http://localhost:8282/wshttp://www.rinat.my/country/getCountryResponseurn:uuid:340c83d7-6470-444e-b845-cea844e57400urn:uuid:25e481a1-887b-4b28-a921-8615E1A08D83波兰和38186860华沙国家电力公司]
2019-12-12 10:45:01.441警告17188---[nio-8282-exec-1]o.s.w.soap.server.SoapMessageDispatcher:无法处理mustUnderstand标头:{http://www.w3.org/2005/08/addressing}对。返回故障
2019-12-12 10:45:01.450跟踪17188---[nio-8282-exec-1]o.s.ws.server.MessageTracing.sent:发送请求的响应[SOAP-ENV:MustUnderstandondonone或更多未理解的强制SOAP头块][http://localhost:8282/wshttp://www.rinat.my/country/getCountryResponseurn:uuid:340c83d7-6470-444e-b845-cea844e57400urn:uuid:25e481a1-887b-4b28-a921-8615E1A08D83波兰和38186860华沙国家电力公司]
我将非常感谢您的帮助。路由消息的接收者应实现端点,路由器必须发送值等于接收者端点的
@action
注释值的操作头
您可以找到完整的示例。路由消息的接收者应该实现端点,并且路由器必须发送值等于接收者端点的
@action
注释值的操作头
你可以找到完整的例子
public class CountryWsClient extends WebServiceGatewaySupport {
public GetCountryResponse getCountry(String name) throws URISyntaxException {
GetCountryRequest request = new GetCountryRequest();
request.setName(name);
var callback = new ActionCallback(
new URI("http://www.rinat.my/country/getCountry"),
new Addressing10(),
new URI("http://localhost:8282/ws")
);
callback.setReplyTo(new EndpointReference(new URI("http://localhost:8282/ws")));
return (GetCountryResponse) getWebServiceTemplate().marshalSendAndReceive("http://localhost:8181/ws", request, callback);
}
}
@Configuration
public class WsConfiguration extends WsConfigurationSupport {
public static final String ACTION = "http://www.rinat.my/country/getCountry";
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet, "/ws/*");
}
@Bean(name = "country-ws")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema schema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("CountryPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://www.rinat.my/country/gen");
wsdl11Definition.setSchema(schema);
Properties actions = new Properties();
actions.setProperty("getCountry", ACTION);
wsdl11Definition.setSoapActions(actions);
return wsdl11Definition;
}
@Bean
@Override
public AnnotationActionEndpointMapping annotationActionEndpointMapping() {
var mapping = super.annotationActionEndpointMapping();
mapping.setMessageSender(new HttpComponentsMessageSender());
return mapping;
}
@Bean
public XsdSchema schema() {
return new SimpleXsdSchema(new ClassPathResource("xsd/countries.xsd"));
}
}
@Endpoint
public class CountryEndpoint {
private final Countries countries;
public CountryEndpoint(Countries countries) {
this.countries = countries;
}
@Action(WsConfiguration.ACTION)
@ResponsePayload
public GetCountryResponse getCountry(@RequestPayload final GetCountryRequest request) {
GetCountryResponse response = new GetCountryResponse();
response.setCountry(this.countries.findCountry(request.getName()));
return response;
}
}
@Configuration
public class WsConfiguration extends WsConfigurationSupport {
@Bean
public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean<>(servlet, "/ws/*");
}
@Bean(name = "country-ws")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema schema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("CountryPort");
wsdl11Definition.setLocationUri("/ws");
wsdl11Definition.setTargetNamespace("http://www.rinat.my/country/gen");
wsdl11Definition.setSchema(schema);
return wsdl11Definition;
}
@Bean
public XsdSchema schema() {
return new SimpleXsdSchema(new ClassPathResource("xsd/countries.xsd"));
}
}
@Slf4j
@Endpoint
public class CountryEndpoint {
@PayloadRoot(namespace = "http://www.rinat.my/country/gen", localPart = "getCountryResponse")
@ResponsePayload
public void getCountry(@RequestPayload final GetCountryResponse response) {
var country = response.getCountry();
log.info("Country {} with the capital {}, population {}, and currency {}", country.getName(),
country.getCapital(), country.getPopulation(), country.getCurrency());
}
}
2019-12-12 10:45:01.433 TRACE 17188 --- [nio-8282-exec-1] o.s.ws.server.MessageTracing.received : Received request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:To SOAP-ENV:mustUnderstand="1">http://localhost:8282/ws</wsa:To><wsa:Action>http://www.rinat.my/country/getCountryResponse</wsa:Action><wsa:MessageID>urn:uuid:340c83d7-6470-444e-b845-cea844e57400</wsa:MessageID><wsa:RelatesTo>urn:uuid:25e481a1-887b-4b28-a921-8615e1a08d83</wsa:RelatesTo></SOAP-ENV:Header><SOAP-ENV:Body><ns2:getCountryResponse xmlns:ns2="http://www.rinat.my/country/gen"><ns2:country><ns2:name>Poland</ns2:name><ns2:population>38186860</ns2:population><ns2:capital>Warsaw</ns2:capital><ns2:currency>PLN</ns2:currency></ns2:country></ns2:getCountryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>]
2019-12-12 10:45:01.441 WARN 17188 --- [nio-8282-exec-1] o.s.w.soap.server.SoapMessageDispatcher : Could not handle mustUnderstand headers: {http://www.w3.org/2005/08/addressing}To. Returning fault
2019-12-12 10:45:01.450 TRACE 17188 --- [nio-8282-exec-1] o.s.ws.server.MessageTracing.sent : Sent response [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:MustUnderstand</faultcode><faultstring xml:lang="en">One or more mandatory SOAP header blocks not understood</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>] for request [<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header xmlns:wsa="http://www.w3.org/2005/08/addressing"><wsa:To SOAP-ENV:mustUnderstand="1">http://localhost:8282/ws</wsa:To><wsa:Action>http://www.rinat.my/country/getCountryResponse</wsa:Action><wsa:MessageID>urn:uuid:340c83d7-6470-444e-b845-cea844e57400</wsa:MessageID><wsa:RelatesTo>urn:uuid:25e481a1-887b-4b28-a921-8615e1a08d83</wsa:RelatesTo></SOAP-ENV:Header><SOAP-ENV:Body><ns2:getCountryResponse xmlns:ns2="http://www.rinat.my/country/gen"><ns2:country><ns2:name>Poland</ns2:name><ns2:population>38186860</ns2:population><ns2:capital>Warsaw</ns2:capital><ns2:currency>PLN</ns2:currency></ns2:country></ns2:getCountryResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>]