英文:
Get byte[] response from getWebServiceTemplate().marshalSendAndReceive() in Spring-WS
问题
在目标 WebService 中,响应中只有 xs:base64binary 数据类型,而 JAXB 并没有生成相应的响应类型。
在我的调用中:
public Object signMessage(SigningRequestType request) {
JAXBElement<SigningRequestType> jAXBElement = new ObjectFactory().createSigningRequestType(request);
return getWebServiceTemplate().marshalSendAndReceive(jAXBElement,
new SoapActionCallback(SIGN_METHOD_ACTION));
}
返回一个 Object,我无法简单地将其转换为 byte[] 或进行序列化。
我该如何从响应中提取一个 byteArray 结果?
UDP: 添加一些额外信息。
ObjectFactory() 方法:
@XmlElementDecl(namespace = "http://www.roskazna.ru/eb/sign/types/sgv", name = "SigningResponseType")
public JAXBElement<byte[]> createSigningResponseType(byte[] value) {
return new JAXBElement<byte[]>(_SigningResponseType_QNAME, byte[].class, null, ((byte[]) value));
}
XSD:
<xs:element name="SigningResponseType" type="cst:notEmptyB64Binary"/>
英文:
In target WebService in response is only xs:base64binary and JAXB does not generate a response type.
In my invoke:
public Object signMessage(SigningRequestType request) {
JAXBElement<SigningRequestType> jAXBElement = new ObjectFactory().createSigningRequestType(request);
return getWebServiceTemplate().marshalSendAndReceive(jAXBElement,
new SoapActionCallback(SIGN_METHOD_ACTION));
}
returns an Object and I can't simply cast to byte[] or serialize it.
How can I extract a byteArray result from the response?
UDP: Add a little more information.
ObjectFactory() method:
@XmlElementDecl(namespace = "http://www.roskazna.ru/eb/sign/types/sgv", name = "SigningResponseType")
public JAXBElement<byte[]> createSigningResponseType(byte[] value) {
return new JAXBElement<byte[]>(_SigningResponseType_QNAME, byte[].class, null, ((byte[]) value));
}
XSD:
<xs:element name="SigningResponseType" type="cst:notEmptyB64Binary"/>
答案1
得分: 0
帮助了我的同事Senior。
在这种情况下,marshalSendAndReceive() 实际上返回了 JAXBElement。因此:
public byte[] signMessage(SigningRequestType request) throws IOException {
JAXBElement<SigningRequestType> jAXBElement
= new ObjectFactory().createSigningRequestType(request);
final Object o = getWebServiceTemplate().marshalSendAndReceive(jAXBElement,
new SoapActionCallback("http://www.roskazna.ru/eb/sign/types/sgv/Sign"));
return (byte[]) ((JAXBElement) o).getValue();
}
英文:
Helped my colleague Senior.
In this case marshalSendAndReceive() returns JAXBElement in fact. So:
public byte[] signMessage(SigningRequestType request) throws IOException {
JAXBElement<SigningRequestType> jAXBElement
= new ObjectFactory().createSigningRequestType(request);
final Object o = getWebServiceTemplate().marshalSendAndReceive(jAXBElement,
new SoapActionCallback("http://www.roskazna.ru/eb/sign/types/sgv/Sign"));
return (byte[]) ((JAXBElement) o).getValue();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论