将参数从java发送到jax-ws源

时间:2012-11-26 12:27:44

标签: java web wsdl jax-ws

我正在开发一个Java Web服务客户端项目。在其中,我必须将参数从java发送到wsdl实现者的相关java类。我必须使用的代码是:

private static SendSMSOutput sendSMS(tr.com.SomeProvider.sdp.mapping.generated.SendSMSInput requestPart) {
    tr.com.SomeProvider.sdp.wsdl.generated.SendMessage service = new tr.com.SomeProvider.sdp.wsdl.generated.SendMessage();
    tr.com.SomeProvider.sdp.wsdl.generated.SendMessagePort port = service.getSendMessagePort();
    return port.sendSMS(requestPart);
}

我必须将主类中的参数发送到此方法。

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"expirydate",
"messageclass",
"sdate",
"sender",
"shortnumber",
"srcmsisdn",
"nreq",
"toreceivers",
"messagebody"})

@XmlRootElement(name = "SendSMSInput")
public class SendSMSInput {

@XmlElement(name = "EXPIRY_DATE")
protected String expirydate;
@XmlElement(name = "MESSAGE_CLASS")
protected String messageclass;
@XmlElement(name = "S_DATE")
protected String sdate;
@XmlElement(name = "SENDER")
protected String sender;
@XmlElement(name = "SHORT_NUMBER", required = true)
protected String shortnumber;
@XmlElement(name = "SRC_MSISDN")
protected String srcmsisdn;
@XmlElement(name = "NREQ")
protected String nreq;
@XmlElement(name = "TO_RECEIVERS", required = true)
protected SendSMSInput.TORECEIVERS toreceivers;
@XmlElement(name = "MESSAGE_BODY", required = true)
protected SendSMSInput.MESSAGEBODY messagebody;

/**
 * Gets the value of the expirydate property.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getEXPIRYDATE() {
    return expirydate;
}

/**
 * Sets the value of the expirydate property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setEXPIRYDATE(String value) {
    this.expirydate = value;
}

/**
 * Gets the value of the messageclass property.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getMESSAGECLASS() {
    return messageclass;
}

/**
 * Sets the value of the messageclass property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setMESSAGECLASS(String value) {
    this.messageclass = value;
}

/**
 * Gets the value of the sdate property.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getSDATE() {
    return sdate;
}

/**
 * Sets the value of the sdate property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setSDATE(String value) {
    this.sdate = value;
}

/**
 * Gets the value of the sender property.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getSENDER() {
    return sender;
}

/**
 * Sets the value of the sender property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setSENDER(String value) {
    this.sender = value;
}

/**
 * Gets the value of the shortnumber property.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getSHORTNUMBER() {
    return shortnumber;
}

/**
 * Sets the value of the shortnumber property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setSHORTNUMBER(String value) {
    this.shortnumber = value;
}

/**
 * Gets the value of the srcmsisdn property.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getSRCMSISDN() {
    return srcmsisdn;
}

/**
 * Sets the value of the srcmsisdn property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setSRCMSISDN(String value) {
    this.srcmsisdn = value;
}

/**
 * Gets the value of the nreq property.
 * 
 * @return
 *     possible object is
 *     {@link String }
 *     
 */
public String getNREQ() {
    return nreq;
}

/**
 * Sets the value of the nreq property.
 * 
 * @param value
 *     allowed object is
 *     {@link String }
 *     
 */
public void setNREQ(String value) {
    this.nreq = value;
}

/**
 * Gets the value of the toreceivers property.
 * 
 * @return
 *     possible object is
 *     {@link SendSMSInput.TORECEIVERS }
 *     
 */
public SendSMSInput.TORECEIVERS getTORECEIVERS() {
    return toreceivers;
}

/**
 * Sets the value of the toreceivers property.
 * 
 * @param value
 *     allowed object is
 *     {@link SendSMSInput.TORECEIVERS }
 *     
 */
public void setTORECEIVERS(SendSMSInput.TORECEIVERS value) {
    this.toreceivers = value;
}

/**
 * Gets the value of the messagebody property.
 * 
 * @return
 *     possible object is
 *     {@link SendSMSInput.MESSAGEBODY }
 *     
 */
public SendSMSInput.MESSAGEBODY getMESSAGEBODY() {
    return messagebody;
}

/**
 * Sets the value of the messagebody property.
 * 
 * @param value
 *     allowed object is
 *     {@link SendSMSInput.MESSAGEBODY }
 *     
 */
public void setMESSAGEBODY(SendSMSInput.MESSAGEBODY value) {
    this.messagebody = value;
}


/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="message" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "message"
})
public static class MESSAGEBODY {

    @XmlElement(required = true)
    protected List<String> message;

    /**
     * Gets the value of the message property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the message property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getMessage().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link String }
     * 
     * 
     */
    public List<String> getMessage() {
        if (message == null) {
            message = new ArrayList<String>();
        }
        return this.message;
    }

}


/**
 * <p>Java class for anonymous complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType>
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="msisdn" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "msisdn"
})
public static class TORECEIVERS {

    @XmlElement(required = true)
    protected List<String> msisdn;

    /**
     * Gets the value of the msisdn property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the msisdn property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getMsisdn().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link String }
     * 
     * 
     */
    public List<String> getMsisdn() {
        if (msisdn == null) {
            msisdn = new ArrayList<String>();
        }
        return this.msisdn;
    }

}

}

据我所知,我必须根据SendInput发送参数。我想我必须创建一个带有expirydate,messageclass,sdate,sender,shortnumber,srcmsisdn,nreq,toreceivers和messagebody的有效负载。

我的问题是如何将这些参数作为一个发送到SendSMSOutput方法?提前谢谢。

编辑:在文档中,soap消息的外观如下:

<soap:Body>
    <sdp:SendSMSInput>
        <sdp:EXPIRY_DATE>250106121212</sdp:EXPIRY_DATE>
        <sdp:MESSAGE_CLASS>0</sdp:MESSAGE_CLASS>
        <sdp:S_DATE>200106121212</sdp:S_DATE>
        <sdp:SHORT_NUMBER>1905</sdp:SHORT_NUMBER>
        <sdp:SRC_MSISDN>123123123123</sdp:SRC_MSISDN>
        <sdp:TO_RECEIVERS>
            <sdp:msisdn>123123123123</sdp:msisdn>
            <sdp:msisdn>123123123123</sdp:msisdn>
        </sdp:TO_RECEIVERS>
        <sdp:MESSAGE_BODY>
            <sdp:message>MESSAGE BODY GOES HERE</sdp:message>
            <sdp:message>SECOND BODY GOES HERE</sdp:message>
        </sdp:MESSAGE_BODY>
    </sdp:SendSMSInput>
</soap:Body>

1 个答案:

答案 0 :(得分:0)

您必须实例化类tr.com.SomeProvider.sdp.mapping.generated.SendSMSInput的对象,填充其字段并将其转发给方法sendSMS。实例化应该通过调用适当的构造函数以通常的方式完成。您将通过调用setXXX(..)方法直接填充大多数字段,但MESSAGEBODY和TORECEIVERS除外。你会用这种方式填充它们(TORECEIVERS的一个例子,类似于MESSAGEBODY):

//INSTANTIATE requestPart
...
SendSmsInput.TORECEIVERS receivers = new SendSmsInput.TORECEIVERS();
receivers.getMsisdn().add("value1");
receivers.getMsisdn().add("value2");
..
requestPart.setTORECEIVERS(receivers);