我已设法建立与沙盒服务器的 SSL 连接,并通过应用内容类型 MediaType.APPLICATION_XML 将对象作为序列化 XML 对象发送。但是,这还不够,因为目标服务仅支持 SOAP 并希望消息正确地包装在信封中。
final var webClient = WebClient.builder()
.baseUrl(fmdConfiguration.getSinglePackUrl())
.clientConnector(connector)
.exchangeStrategies(exchangeStrategies)
.filter(logResponseStatus())
.filter(logRequest())
.build();
return webClient
.method(GET)
.contentType(MediaType.APPLICATION_XML)
.body(BodyInserters.fromObject(request))
.retrieve()
.bodyToMono(SinglePackPingResponse.class);
这是来自服务的响应:
Unable to create envelope from given source because the root element is not named "Envelope"
不幸的是,WebClient 不支持媒体类型 application/soap+xml。当我尝试使用它时,WebClient 会抛出以下错误:
org.springframework.web.reactive.function.UnsupportedMediaTypeException: Content type 'application/soap+xml;charset=UTF-8' not supported for bodyType=eu.nmvs.SinglePackPingRequest
at org.springframework.web.reactive.function.BodyInserters.unsupportedError(BodyInserters.java:300)