如何使用 FEIGN 客户端发送 SOAP 对象? [英] How to send a SOAP object with FEIGN client?

查看:77
本文介绍了如何使用 FEIGN 客户端发送 SOAP 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过 FEIGN 客户端发送 SOAP 消息.问题是当我发送java对象时,实际发送的是xml格式的请求,而不是SOAP格式.

I'm trying to send a SOAP message via a FEIGN client. The problem is that when I send the java object, what is actually being sent is a request with an xml format, instead of a SOAP format.

客户端配置如下:

@FeignClient(name = "calculatorServer", url = "http://www.dneonline.com/calculator.asmx")
public interface AEMWebServiceFeignClient{

    @PostMapping(value = "", consumes = MediaType.TEXT_XML, produces = MediaType.TEXT_XML)
    AddResponse calculate(@RequestBody Add addRequest);

}

查看日志我发现我真的在发送这个:

Looking at the log I see that I am really sending this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Add xmlns="http://tempuri.org/">
    <intA>2</intA>
    <intB>0</intB>
</Add>

当我真的应该发送以下消息时:

When I really should be sending the following message:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <tem:Add>
         <tem:intA>2</tem:intA>
         <tem:intB>0</tem:intB>
      </tem:Add>
   </soapenv:Body>
</soapenv:Envelope>

欢迎任何帮助,谢谢!

推荐答案

您必须定义自定义 Feign 编解码器才能使用 SOAP,如 这里.

You must define a custom Feign codec to use SOAP, as described in here.

要将其与 FeignClient 集成,您应该为其定义一个自定义配置类,参考.

To integrate it with FeignClient, you should define a custom configuration class for it, reference.

@FeignClient(
  name = "calculatorServer", 
  url = "http://www.dneonline.com/calculator.asmx"
  configuration = MySoapClientConfiguration.class)
public interface AEMWebServiceFeignClient{

    @PostMapping(value = "", consumes = MediaType.TEXT_XML, produces = MediaType.TEXT_XML)
    AddResponse calculate(@RequestBody Add addRequest);

}

@Configuration
public class MySoapClientConfiguration {

    private static final JAXBContextFactory jaxbFactory = new JAXBContextFactory.Builder()
       .withMarshallerJAXBEncoding("UTF-8")
       .withMarshallerSchemaLocation("http://apihost http://apihost/schema.xsd")
       .build();

    @Bean
    public Encoder feignEncoder() {
        return new SOAPEncoder(jaxbFactory);
    }
    @Bean
    public Decoder feignDecoder() {
        return new SOAPDecoder(jaxbFactory);
    }
}

这篇关于如何使用 FEIGN 客户端发送 SOAP 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆