简体   繁体   中英

send parameters from java to jax-ws source

I am developinging a Java web service client project. In it, I have to send parameters from java to related java class of wsdl implementer. The code that I have to use is:

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);
}

I have to send parameters from main class to this method.

@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;
    }

}

}

As far as I understood I have to send my parameters in terms of SendInput. I think I have to create such a payload that carries expirydate, messageclass, sdate, sender, shortnumber, srcmsisdn, nreq, toreceivers, and messagebody.

My question is how to send those parameters as one to SendSMSOutput method? Thanks in advance.

edit: in the documentation the way how soap message will look like is:

<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>

You'll have to instantiate an object of class tr.com.SomeProvider.sdp.mapping.generated.SendSMSInput , populate its fields and forward it to the method sendSMS . Instantiation should be done in usual way, by calling appropriate constructor. Most of the fields you'll populate directly, by calling setXXX(..) methods, except MESSAGEBODY and TORECEIVERS. You'll populate them this way (an example for TORECEIVERS, similar for MESSAGEBODY):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM