【问题标题】:How can SOAP be used with Spring Reactor's WebClient?SOAP 如何与 Spring Reactor 的 WebClient 一起使用?
【发布时间】:2019-09-08 19:31:34
【问题描述】:

我已成功建立与沙盒服务器的 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)

【问题讨论】:

  • 你能发一个mcve吗? “为什么我的代码不起作用”类型的问题很难用上面的 sn-ps 来回答。
  • @Andras,你成功了吗?
  • @AmosKosgei 不,我应用了blog.godatadriven.com/jaxws-reactive-client中描述的方法

标签: spring soap spring-webflux project-reactor reactor-netty


【解决方案1】:

我用:

private void acceptedCodecs(ClientCodecConfigurer clientCodecConfigurer) {
    clientCodecConfigurer.customCodecs().encoder(new Jackson2JsonEncoder(new ObjectMapper(), TEXT_XML));
    clientCodecConfigurer.customCodecs().decoder(new Jackson2JsonDecoder(new ObjectMapper(), TEXT_XML));
}

和:

  webClient = webClientBuilder
                .baseUrl(baseUrL)
                .filter(logRequest())
                .exchangeStrategies(ExchangeStrategies.builder().codecs(this::acceptedCodecs).build()).build();

【讨论】:

    猜你喜欢
    • 2019-02-14
    • 1970-01-01
    • 2018-04-11
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多