gpt4 book ai didi

java - 如何使用FEIGN客户端发送SOAP对象?

转载 作者:行者123 更新时间:2023-12-01 19:38:13 26 4
gpt4 key购买 nike

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

客户端配置如下:

@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);

}

查看日志,我发现我确实发送了此内容:

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

当我确实应该发送以下消息时:

<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,如 here 中所述。 .

要将其与 FeignClient 集成,您应该为其定义一个自定义配置类,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);
}
}

关于java - 如何使用FEIGN客户端发送SOAP对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56621218/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com