【问题标题】:Axis 1.4 doesn't deserialize arrays rightAxis 1.4 不能正确反序列化数组
【发布时间】:2016-05-04 15:04:58
【问题描述】:

我有一个 web 服务,它返回一个包含数组的对象。我用 wsdl4j 生成的 Bean 类。如果我调用服务,对象总是返回正确的字段,但数组总是只有一个条目。 Web 服务响应有两个条目,但在 Axis 的某个地方,第二个条目将丢失。服务好像没问题,只是Axis代码里面的处理好像有问题。

这是响应正文的内容

[<projectDataReturn xsi:type="ns4:ProjectDataResult" xmlns:ns4="http://results.ws.appserver.secutrial.de" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <errorCode xsi:type="xsd:int">0</errorCode>
    <message xsi:type="soapenc:string" xsi:nil="true" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
    <statusCode xsi:type="xsd:int">1</statusCode>
    <project xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">HAHA</project>
    <centres xsi:type="ns5:CentreBean" xmlns:ns5="http://beans.eo.secutrial.de"><name xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Center1</name></centres>
    <centres xsi:type="ns6:CentreBean" xmlns:ns6="http://beans.eo.secutrial.de"><name xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Center2</name></centres>
</projectDataReturn>]

所以最后我只在 ProjectDataResult 的 CentreBean 数组中得到“Center2”。我尝试过单步调试,但没有成功。

我发现RPCElement.publishToHandler()方法,之后RPCElement的参数是错误的。该方法重放一些 SAX 事件 (org.apache.axis.message.SAX2EventRecorder),两个 CentreBean 都被处理,但只有最后一个是结果的一部分。

有人解决了吗?

【问题讨论】:

    标签: java arrays web-services axis


    【解决方案1】:

    我想问题在于网络服务的设计方式。

    Centers 应该是一个可以发送多个 Center 数据的复杂类型。 (数组类型)

    所以理想情况下,Web 服务应该已经返回

    [<projectDataReturn xsi:type="ns4:ProjectDataResult" xmlns:ns4="http://results.ws.appserver.secutrial.de" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <errorCode xsi:type="xsd:int">0</errorCode>
    <message xsi:type="soapenc:string" xsi:nil="true" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"/>
    <statusCode xsi:type="xsd:int">1</statusCode>
    <project xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">HAHA</project>
    <centres xsi:type="ns5:CentreBean" xmlns:ns5="http://beans.eo.secutrial.de">
        <centre>
            <name xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Center1</name>
        </centre>
        <centre>
            <name xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Center1</name>
        </centre>
    </centres>
    

    ]

    所以我在这里想说的是,“Centres”应该是一个具有“Centre”bean 数组类型的 bean,每个 Center 都将具有字符串类型名称。

    如果 web 服务以这种方式设计以返回数据,则轴将生成我上面提到的存根,您将能够以数组的形式获取中心。

    现在发生的情况是它通过两个中心运行,并且由于它不是数组类型,因此 Centre1 的值将在读取第二个值时被 Centre2 覆盖。

    【讨论】:

    • 可以,但是我不能更改服务,它是由外部站点管理的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-10
    • 1970-01-01
    相关资源
    最近更新 更多