【问题标题】:Java, RPC/encoded Axis 1.4 client cannot send null argumentJava、RPC/编码的 Axis 1.4 客户端无法发送空参数
【发布时间】:2016-06-26 22:47:21
【问题描述】:

我正在处理使用 RPC/编码的 WSDL 文件连接到我的 Java/Spring 服务的 Web 服务的问题。我无法更改此 WSDL。

我发现我必须使用 Apache Axis 1.4 来创建客户端(根据这个问题:https://dzone.com/articles/wsdltojava-error-rpcencoded)。

然后我在登录/密码/api_key 参数上遇到了这样的消息:

<message name="login_message">
   <part name="login" type="xsd:string"/>
   <part name="password" type="xsd:string"/>
   <part name="api_key" type="xsd:int"/>
</message>

错误Element 'api_key': '' is not a valid value of the atomic type 'xs:int'

我通过添加解决了这个问题:

webapi_locator.getEngine().setOption("sendMultiRefs", Boolean.FALSE);

现在我可以登录并从该服务获取一些数据,但我无法推送带有空参数的消息,例如:

<message name="add_offer_input">
   <part name="session" type="xsd:string"/>
   <part name="category_id" type="xsd:int"/>
   <part name="offer" type="tns:offer"/>
</message>

其中offer定义为:

<xsd:complexType name="offer">
   <xsd:all>
     <xsd:element name="price" type="xsd:float" minOccurs="0" maxOccurs="1"/>
     <xsd:element name="price_m2" type="xsd:int" minOccurs="0" maxOccurs="1"/>
   [...]
   </xsd:all>
</xsd:complexType>

现在我遇到了这样的异常:

org.apache.axis.AxisFault: Wrong parameters input xml
Element 'price': '' is not a valid value of the atomic type 'xs:int'. line: 1 column: 0'
        at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222) ~[axis-1.4.jar:na]

我已经尝试过设置

elemField.setNillable(false); 

到

elemField.setNillable(true); 

在 Offer.java 中。

我正在通过以下方式创建优惠消息:

Offer offer = new Offer(null,null);

我将非常感谢找到解决此错误的方法。我不需要坚持使用轴 1.4 - 任何其他让我通过 SOAP 连接到此服务的解决方案对我有用。非常感谢您的帮助!

【问题讨论】:

    标签: java soap axis soap-rpc-encoded


    【解决方案1】:

    您可能在 WSDL 中缺少 nillable="true" 属性。

    WSDL 应该类似于以下内容:

    ..
    <xsd:element name="price" type="xsd:float" nillable="true" minOccurs="0" maxOccurs="1"/>
    ..
    

    nillable="true" 允许传递空参数。使用 Axis 1.4 的 Java2WSDL 没有这样做,因为 org/apache/axis/wsdl/fromJava/Types.java 中的轴代码方法 writeWrappedParameter() 没有。

    有关错误的更多信息:https://issues.apache.org/jira/browse/AXIS-243

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-04
      • 2012-04-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      相关资源
      最近更新 更多