A.J
A.J

Reputation: 1180

XML encoding is not returning HTML entities in SOAP

I have the following test method.

public String ping(String xml) {
    return "<PingResult>Service is Live</PingResult>";
}

What I get back when I call it is the following:

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <PingResponse xmlns="http://www.url.com/service">
        &lt;PingResult&gt;Service is Live&lt;/PingResult&gt;
      </PingResponse>
   </soapenv:Body>
</soapenv:Envelope>

Substituting < with &lt; does not help. Any idea how I can actually return those < and > symbols? It looks like no matter what I substitute them with it doesn't work.

EDIT

PingResponse.java

package user;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "PingResponse")
public class PingResponse implements java.io.Serializable {

    private String pingResult;

    @XmlElement(name = "PingResult")
    public String getPingResult() {
        return pingResult;
    }

    public void setPingResult(String pingResult) {
        this.pingResult = pingResult;
    }

    // Type metadata
    private static org.apache.axis.description.TypeDesc typeDesc =
        new org.apache.axis.description.TypeDesc(PingResponse.class, true);

    static {
        typeDesc.setXmlType(new javax.xml.namespace.QName("user", "PingResponse"));
        org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("PingResult");
        elemField.setXmlName(new javax.xml.namespace.QName("", "PingResult"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://schemas.xmlsoap.org/soap/encoding/", "string"));
        elemField.setNillable(true);
        typeDesc.addFieldDesc(elemField);
    }

    /**
     * Return type metadata object
     */
    public static org.apache.axis.description.TypeDesc getTypeDesc() {
        return typeDesc;
    }

    /**
     * Get Custom Serializer
     */
    public static org.apache.axis.encoding.Serializer getSerializer(
        java.lang.String mechType,
        java.lang.Class _javaType,
        javax.xml.namespace.QName _xmlType) {
        return
        new org.apache.axis.encoding.ser.BeanSerializer(
            _javaType, _xmlType, typeDesc);
    }

    /**
     * Get Custom Deserializer
     */
    public static org.apache.axis.encoding.Deserializer getDeserializer(
        java.lang.String mechType,
        java.lang.Class _javaType,
        javax.xml.namespace.QName _xmlType) {
        return
        new org.apache.axis.encoding.ser.BeanDeserializer(
            _javaType, _xmlType, typeDesc);
    }
}

ServicesSoapImpl.java

package user;

import user.PingResponse;

public class ServicesSoapImpl implements user.serviceSoap {


    public PingResponse ping(String xml) throws java.rmi.RemoteException {

        PingResponse response = new PingResponse();
        response.setPingResult("Service is Live");
        return response;

    }

}

And I do have an update, after adding all of the above I am able to get something different. It is not exactly what I need, but it is close to it.

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <PingResponse xmlns="user" xmlns:ns1="user" xsi:type="ns1:PingResponse">
         <pingResult>Service is Live</pingResult>
      </PingResponse>
   </soapenv:Body>
</soapenv:Envelope>

So there is some extra stuff there that wasn't before and pingResult is lower case for some reason.

Upvotes: 0

Views: 133

Answers (1)

forty-two
forty-two

Reputation: 12817

The schema class used in the response should look something like this:

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

private String pingResult;

@XmlElement(name = "PingResult")
public String getPingResult() {
    return pingResult;
}

public void setPingResult(String pingResult) {
    this.pingResult = pingResult;
}

}

Upvotes: 1

Related Questions