【问题标题】:JAX-WS Null Param Not Included in SOAP RequestSOAP 请求中不包含 JAX-WS Null 参数
【发布时间】:2013-03-11 13:57:35
【问题描述】:

我的问题是,当通过 SOAP UI(JAX-WS 客户端)从 Java 生成的代码发送请求时,空参数包含在 SOAP 生成的请求中。

我正在从第三方 WSDL 生成soap客户端,所以对 WSDL 修改没有任何控制权。

来自 Java 生成客户端的消息,没有具有空值的参数。我必须有空元素,即<authId> & <reserved>

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <BillPayment xmlns="http://action.one.worldnet.org">
        <userName>test</userName>
        <password>testing2</password>
        <AccountNumber>10385699</AccountNumber>
        <amount>0000000002300</amount>
        <tranDate>20130311</tranDate>
        <tranTime>064536</tranTime>
        <bankMnemonic>TIMEPAY</bankMnemonic>
        </BillPayment>
    </S:Body>
</S:Envelope>

来自 SOAPUI 的消息,其中包含值为 null 的元素。

<soap:Body>
    <soap:Envelope>"
      <act:BillPayment>
         <act:userName>test</act:userName>
         <act:password>testing2</act:password>
         <act:AccountNumber>9132388</act:AccountNumber>
         <act:authId></act:authId>
         <act:amount>0000000010000</act:amount>
         <act:tranDate>20130311</act:tranDate>
         <act:tranTime>172345</act:tranTime>
         <act:bankMnemonic>THIRDParty</act:bankMnemonic>
         <act:reserved></act:reserved>
      </act:BillPayment>
   </soap:Body>
</soap:Envelope>"

以下是我生成的 BillPayment 类

@XmlAccessorType(XmlAccessType.FIELD)

@XmlType(name = "", propOrder = { "userName", "password", "accountNumber", "authId", "amount", "tranDate", "tranTime", "bankMnemonic", "reserved" } ) @XmlRootElement(name = "BillPayment") 公共类 BillPayment {

@XmlElementRef(name = "userName", namespace = "http://action.wirelessnet.org", type = JAXBElement.class)
protected JAXBElement<String> userName;
@XmlElementRef(name = "password", namespace = "http://action.wirelessnet.org", type = JAXBElement.class)
protected JAXBElement<String> password;
@XmlElementRef(name = "AccountNumber", namespace = "http://action.wirelessnet.org", type = JAXBElement.class)
protected JAXBElement<String> accountNumber;
@XmlElementRef(name = "authId", namespace = "http://action.wirelessnet.org", type = JAXBElement.class)
protected JAXBElement<String> authId;
@XmlElementRef(name = "amount", namespace = "http://action.wirelessnet.org", type = JAXBElement.class)
protected JAXBElement<String> amount;
@XmlElementRef(name = "tranDate", namespace = "http://action.wirelessnet.org", type = JAXBElement.class)
protected JAXBElement<String> tranDate;
@XmlElementRef(name = "tranTime", namespace = "http://action.wirelessnet.org", type = JAXBElement.class)
protected JAXBElement<String> tranTime;
@XmlElementRef(name = "bankMnemonic", namespace = "http://action.wirelessnet.org", type = JAXBElement.class)
protected JAXBElement<String> bankMnemonic;
@XmlElementRef(name = "reserved", namespace = "http://action.wirelessnet.org", type = JAXBElement.class)
protected JAXBElement<String> reserved;

/**
 * Gets the value of the userName property.
 * 
 * @return possible object is {@link JAXBElement }{@code <}{@link String }
 *         {@code >}
 * 
 */
public JAXBElement<String> getUserName() {
    return userName;
}

/**
 * Sets the value of the userName property.
 * 
 * @param value
 *            allowed object is {@link JAXBElement }{@code <}{@link String }
 *            {@code >}
 * 
 */
public void setUserName(JAXBElement<String> value) {
    this.userName = ((JAXBElement<String>) value);
}

/**
 * Gets the value of the password property.
 * 
 * @return possible object is {@link JAXBElement }{@code <}{@link String }
 *         {@code >}
 * 
 */
public JAXBElement<String> getPassword() {
    return password;
}

/**
 * Sets the value of the password property.
 * 
 * @param value
 *            allowed object is {@link JAXBElement }{@code <}{@link String }
 *            {@code >}
 * 
 */
public void setPassword(JAXBElement<String> value) {
    this.password = ((JAXBElement<String>) value);
}

/**
 * Gets the value of the accountNumber property.
 * 
 * @return possible object is {@link JAXBElement }{@code <}{@link String }
 *         {@code >}
 * 
 */
public JAXBElement<String> getAccountNumber() {
    return accountNumber;
}

/**
 * Sets the value of the accountNumber property.
 * 
 * @param value
 *            allowed object is {@link JAXBElement }{@code <}{@link String }
 *            {@code >}
 * 
 */
public void setAccountNumber(JAXBElement<String> value) {
    this.accountNumber = ((JAXBElement<String>) value);
}

/**
 * Gets the value of the authId property.
 * 
 * @return possible object is {@link JAXBElement }{@code <}{@link String }
 *         {@code >}
 * 
 */
public JAXBElement<String> getAuthId() {
    return authId;
}

/**
 * Sets the value of the authId property.
 * 
 * @param value
 *            allowed object is {@link JAXBElement }{@code <}{@link String }
 *            {@code >}
 * 
 */
public void setAuthId(JAXBElement<String> value) {
    this.authId = ((JAXBElement<String>) value);
}

/**
 * Gets the value of the amount property.
 * 
 * @return possible object is {@link JAXBElement }{@code <}{@link String }
 *         {@code >}
 * 
 */
public JAXBElement<String> getAmount() {
    return amount;
}

/**
 * Sets the value of the amount property.
 * 
 * @param value
 *            allowed object is {@link JAXBElement }{@code <}{@link String }
 *            {@code >}
 * 
 */
public void setAmount(JAXBElement<String> value) {
    this.amount = ((JAXBElement<String>) value);
}

/**
 * Gets the value of the tranDate property.
 * 
 * @return possible object is {@link JAXBElement }{@code <}{@link String }
 *         {@code >}
 * 
 */
public JAXBElement<String> getTranDate() {
    return tranDate;
}

/**
 * Sets the value of the tranDate property.
 * 
 * @param value
 *            allowed object is {@link JAXBElement }{@code <}{@link String }
 *            {@code >}
 * 
 */
public void setTranDate(JAXBElement<String> value) {
    this.tranDate = ((JAXBElement<String>) value);
}

/**
 * Gets the value of the tranTime property.
 * 
 * @return possible object is {@link JAXBElement }{@code <}{@link String }
 *         {@code >}
 * 
 */
public JAXBElement<String> getTranTime() {
    return tranTime;
}

/**
 * Sets the value of the tranTime property.
 * 
 * @param value
 *            allowed object is {@link JAXBElement }{@code <}{@link String }
 *            {@code >}
 * 
 */
public void setTranTime(JAXBElement<String> value) {
    this.tranTime = ((JAXBElement<String>) value);
}

/**
 * Gets the value of the bankMnemonic property.
 * 
 * @return possible object is {@link JAXBElement }{@code <}{@link String }
 *         {@code >}
 * 
 */
public JAXBElement<String> getBankMnemonic() {
    return bankMnemonic;
}

/**
 * Sets the value of the bankMnemonic property.
 * 
 * @param value
 *            allowed object is {@link JAXBElement }{@code <}{@link String }
 *            {@code >}
 * 
 */
public void setBankMnemonic(JAXBElement<String> value) {
    this.bankMnemonic = ((JAXBElement<String>) value);
}

/**
 * Gets the value of the reserved property.
 * 
 * @return possible object is {@link JAXBElement }{@code <}{@link String }
 *         {@code >}
 * 
 */
public JAXBElement<String> getReserved() {
    return reserved;
}

/**
 * Sets the value of the reserved property.
 * 
 * @param value
 *            allowed object is {@link JAXBElement }{@code <}{@link String }
 *            {@code >}
 * 
 */
public void setReserved(JAXBElement<String> value) {
    this.reserved = ((JAXBElement<String>) value);
}

}

寻求专家建议。提前致谢。

【问题讨论】:

    标签: jax-ws


    【解决方案1】:

    您没有发布您的 WSDL。我怀疑您的&lt;authId&gt; 在架构定义中有minOccurs=0。我不确定您是在进行自上而下还是自下而上的设计。如果您使用自顶向下,您可以简单地在 WSDL 模式定义部分添加minOccurs=1。如果您使用的是自底向上的设计方法,您可以在 Web 服务代码中使用以下注释

    @XmlElement(nillable=true, required=true)
    String authId;
    

    请注意,此注释需要 Metro 2.0 (JAXB 2.2) 或更高版本。

    基于 cmets 编辑:

    如果您可以升级到 JDK 7,它应该包含 JAX-WS 2.2。但是,如果由于任何原因无法升级整个 JDK,您可以按照说明 here 使用名为 Endorsed Standards Override Mechanism 的功能,只需升级 jaxws-api.jarjaxb-api.jar 文件即可。

    【讨论】:

    • 添加上述注释后,出现以下异常
    • 引起:com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:2个IllegalAnnotationExceptions计数com.integration.wireless.BillPayment#authId有互斥注解@javax.xml.bind.annotation .XmlElement 和 [at]javax.xml.bind.annotation.XmlElementRef 这个问题与以下位置有关:在 [at]javax.xml.bind.annotation.XmlElement(nillable=true, name=##default, required=真,默认值=
    • 正如我所说,注释需要 Metro 2.0,其中包括 JAXB 2.2。您使用的是什么 Web 服务运行时?是否支持 JAXB 2.2?
    • 好的,我当前的运行时是 JAX-WS 2.1,所以我应该将它升级到最新的 JAX-WS 2.2.7 吗?并且必须单独包含 JAXB 运行时。
    • Lan... 我删除了 XmlElementRef 并用 XmlElement(nillable=true, required=true) 替换它开始工作。你能告诉我这两者之间的区别吗,仅供参考。我真的很感谢你。
    猜你喜欢
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-26
    • 2023-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多