gpt4 book ai didi

jaxb - Spring WS WebServiceTemplate : access to the content of the response or customising the unmarshaller

转载 作者:行者123 更新时间:2023-12-04 23:38:30 25 4
gpt4 key购买 nike

我正在向外部 SOAP 服务发送一条消息,该服务应该使用包含图像等内容的 soap 消息进行回复。
这是我写的发送消息的代码:

@Bean
Jaxb2Marshaller jaxb2Marshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setContextPath("myContextPath");

return jaxb2Marshaller;
}

@Bean
public WebServiceTemplate webServiceTemplate() {
WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
webServiceTemplate.setMessageSender(webServiceMessageSender());
webServiceTemplate.setMarshaller(jaxb2Marshaller());
webServiceTemplate.setUnmarshaller(jaxb2Marshaller());
webServiceTemplate.setDefaultUri(defaultUri);
return webServiceTemplate;
}

public ProcessDocumentResponse sendRequest(MyRequest myRequest) {
MyResponse response = (MyResponse) webServiceTemplate.marshalSendAndReceive(
myRequest,
message -> ((SoapMessage) message).setSoapAction(theAction));
return response;
}

这是从日志中得到的响应:
Receiving response: HTTP/1.1 200 OK
HTTP/1.1 200 OK
Cache-Control: private
Content-Type: multipart/related; type="application/xop+xml";start="<http://tempuri.org/0>";boundary="uuid:_someUUID_";start-info="text/xml"
Server: Microsoft-IIS/10.0
MIME-Version: 1.0
X-AspNet-Version: ...
X-Powered-By: ...
Date: Wed, 11 Oct 2017 09:10:36 GMT
Content-Length: 228346
Connection can be kept alive indefinitely
"[\r][\n]"
"--uuid:_someUUID_[\r][\n]"
"Content-ID: <http://tempuri.org/0>[\r][\n]"
"Content-Transfer-Encoding: 8bit[\r][\n]"
"Content-Type: application/xop+xml;charset=utf-8;type="text/xml"[\r][\n]"
"[\r][\n]"
"<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body>
<here a long response and at some point:><OutputImages><ImageData><xop:Include href="cid:http://tempuri.org/1/636433219150087850" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></ImageData><Metadata i:nil="true"/></OutputImages>
</s:Body></s:Envelope>[\r][\n]"
"--uuid:_someUUID_[\r][\n]"
"Content-ID: <http://tempuri.org/1/636433098360776690>[\r][\n]"
"Content-Transfer-Encoding: binary[\r][\n]"
"Content-Type: application/octet-stream[\r][\n]"
"[\r][\n]"
"[0xff][0xd8][0xff][0xe0][0x0]_here a long sequence o bytes representing an image_
<< "--uuid:_someUUID_[\r][\n]"

如您所见,有两个多部分内容。在第一个多部分内容中有 ImageData 包含:
<OutputImages><ImageData><xop:Include href="cid:http://tempuri.org/1/636433219150087850" xmlns:xop="http://www.w3.org/2004/08/xop/include"/></ImageData><Metadata i:nil="true"/></OutputImages>

该链接cid: http://tempuri.org/1/636433219150087850是第二个多部分内容的 ID。

问题是在解码消息后,我的响应包含一个 byte[] imageData 是空的,但应该包含第二个多部分内容中的字节。
所以我不完全知道如何面对这个问题,我应该将一些配置更改为解码器吗? (如何?)
我是否应该访问 HttpResponse(如何访问?),但是如何在响应中填充 byte[] 值?

最佳答案

经过一番挣扎,我找到了解决方案。
关键是要了解这个机制是如何调用的,我忽略了它,我感到羞耻。

它被称为 MTOM,我的问题的解决方案只是在编码器创建中多出一行:

    @Bean
Jaxb2Marshaller jaxb2Marshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setContextPath("myContextPath");
jaxb2Marshaller.setMtomEnabled(true); //that's it!!

return jaxb2Marshaller;
}

当我遇到 this 时,我找到了解决方案发帖,然后找 MTOM的意思最后在 Spring WS Documentation中解决了

关于jaxb - Spring WS WebServiceTemplate : access to the content of the response or customising the unmarshaller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46685609/

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