从Spring-WS的getWebServiceTemplate().marshalSendAndReceive()获取byte[]响应。

huangapple go评论62阅读模式
英文:

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&lt;SigningRequestType&gt; 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 = &quot;http://www.roskazna.ru/eb/sign/types/sgv&quot;, name = &quot;SigningResponseType&quot;)
    public JAXBElement&lt;byte[]&gt; createSigningResponseType(byte[] value) {
        return new JAXBElement&lt;byte[]&gt;(_SigningResponseType_QNAME, byte[].class, null, ((byte[]) value));
    }

XSD:

&lt;xs:element name=&quot;SigningResponseType&quot; type=&quot;cst:notEmptyB64Binary&quot;/&gt;

答案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&lt;SigningRequestType&gt; jAXBElement 
            = new ObjectFactory().createSigningRequestType(request);

        final Object o = getWebServiceTemplate().marshalSendAndReceive(jAXBElement,
                new SoapActionCallback(&quot;http://www.roskazna.ru/eb/sign/types/sgv/Sign&quot;));

        return (byte[]) ((JAXBElement) o).getValue();
    }

huangapple
  • 本文由 发表于 2020年5月5日 17:51:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/61610308.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定