maress
maress

Reputation: 3533

JAX-WS and SOAP mapping for response

I have to implements a webservice interface and the following response SOAP message has been provided:

<?xml version="1.0"?>
  <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
   <SOAP-ENV:Body SOAP-ENC:encodingStyle="http://schemas.xmlsoap.org/soap/envelope/"
   xmlns:NS2="urn:WebserviceIntf">
    <NS1:VoidPaymentResponse xmlns:NS1="urn:WebserviceIntf-Webservice">
      <return href="#1"/>
    </NS1:VoidPaymentResponse>
    <NS2:TVoidPaymentResponse id="1" xsi:type="NS2:TVoidPaymentResponse">
      <MessageCode xsi:type="xsd:string">00</MessageCode>
      <MessageDescription xsi:type="xsd:string">Successful</MessageDescription>
    </NS2:TVoidPaymentResponse>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

This is what i have for the interface web method.

  @WebMethod(operationName = "VoidPayment")
  @ResponseWrapper(targetNamespace = "urn:WebserviceIntf-Webservice")
  @RequestWrapper(targetNamespace = "urn:WebserviceIntf-Webservice")
  public VoidPaymentDetailResponse voidPayment(
          @WebParam(name = "LoginID") String loginId,
          @WebParam(name = "Password") String password,
          @WebParam(name = "TransactionID") String transactionId,
          @WebParam(name = "Echo") String additionalInformation,
          @WebParam(name = "TVoidPaymentResponse", mode = WebParam.Mode.INOUT, targetNamespace = "urn:WebserviceIntf") Holder<VoidPaymentDetail> voidPaymentDetails) {
    VoidPayment vp = new VoidPayment(loginId, password, transactionId, additionalInformation);
    VoidPaymentDetail vpd = voidPayment(vp);
    voidPaymentDetails.value = vpd;
    return new VoidPaymentDetailResponse("#" + vpd.getId());
  }

When i test my web method on SOAPUI. I get the following soap message:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <ns3:VoidPaymentResponse xmlns:ns2="http://payapi.afrocoin.com/" xmlns:ns3="urn:WebserviceIntf-Webservice" xmlns:ns4="urn:WebserviceIntf">
         <return href="#Od4dY"/>
         <ns4:TVoidPaymentResponse id="Od4dY">
            <MessageCode>32</MessageCode>
            <MessageDescription>Login failed</MessageDescription>
         </ns4:TVoidPaymentResponse>
      </ns3:VoidPaymentResponse>
   </soap:Body>
</soap:Envelope>

Clearly there is a difference between the two messages, and i need to comply fully with the expected response. What annotations do i need to add to the web method to make sure that this happens.

I have spent countless hours trying to figure this out.

Additional codes:

@XmlAccessorType(XmlAccessType.FIELD)
public class VoidPaymentDetailResponse {

  @XmlAttribute(name = "href")
  private String paymentDetail;

  public VoidPaymentDetailResponse() {
  }

  public VoidPaymentDetailResponse(String paymentDetail) {
    this.paymentDetail = paymentDetail;
  }

  public String getPaymentDetail() {
    return paymentDetail;
  }

  public void setPaymentDetail(String paymentDetail) {
    this.paymentDetail = paymentDetail;
  }

}

@XmlType(name = "TVoidPaymentResponse", namespace = "urn:WebserviceIntf")
@Entity
@Table(name = "VoidPaymentResponseDetails")
@XmlAccessorType(XmlAccessType.FIELD)
public class VoidPaymentDetail implements Serializable {

  private static final long serialVersionUID = 19383656L;
  @Id
  @XmlTransient
  private Long detailId = IdGenerator.generateId();
  @XmlAttribute
  @XmlID
  @Transient
  private String id = IdGenerator.generateIdentifier(5);
  @XmlElement(name = "MessageCode")
  private String messageCode;
  @XmlElement(name = "MessageDescription")
  private String messageDescription;
  @XmlTransient
  @OneToOne
  private VoidPayment voidPaymentRequest;

  public void setId(String id) {
    this.id = id;
  }

  public String getId() {
    return id;
  }

  public Long getDetailId() {
    return detailId;
  }

  public void setDetailId(Long detailId) {
    this.detailId = detailId;
  }

  public VoidPayment getVoidPaymentRequest() {
    return voidPaymentRequest;
  }

  public void setVoidPaymentRequest(VoidPayment voidPaymentRequest) {
    this.voidPaymentRequest = voidPaymentRequest;
  }

  public String getMessageCode() {
    return messageCode;
  }

  public void setMessageCode(String messageCode) {
    this.messageCode = messageCode;
  }

  public String getMessageDescription() {
    return messageDescription;
  }

  public void setMessageDescription(String messageDescription) {
    this.messageDescription = messageDescription;
  }

}

I am using the default jboss wsimport.

Thanks

Upvotes: 2

Views: 2524

Answers (1)

Chris Hinshaw
Chris Hinshaw

Reputation: 7255

As per my comment. I don't believe that you can replicate the first message. This is because it contains two separate part's in the body.

http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383533

7.1 RPC and SOAP Body

  • A method response is modelled as a struct.

  • The method response is viewed as a single struct containing an accessor for the return value and each [out] or [in/out] parameter. The first accessor is the return value followed by the parameters in the same order as in the method signature.

Upvotes: 1

Related Questions