XML 编码未返回 SOAP 中的 HTML 个实体
XML encoding is not returning HTML entities in SOAP
我有以下测试方法
public String ping(String xml) {
return "<PingResult>Service is Live</PingResult>";
}
我调用它得到的结果如下:
<?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">
<PingResult>Service is Live</PingResult>
</PingResponse>
</soapenv:Body>
</soapenv:Envelope>
用 <
替换 <
没有帮助。知道我实际上如何 return 那些 <
和 >
符号吗?看来无论我用什么代替它们都不起作用。
编辑
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;
}
}
而且我确实有一个更新,在添加以上所有内容后我能够得到一些不同的东西。这不是我需要的,但已经接近了。
<?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>
所以那里有一些以前没有的额外内容,并且 pingResult
由于某种原因是小写的。
响应中使用的架构 class 应如下所示:
@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;
}
}
我有以下测试方法
public String ping(String xml) {
return "<PingResult>Service is Live</PingResult>";
}
我调用它得到的结果如下:
<?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">
<PingResult>Service is Live</PingResult>
</PingResponse>
</soapenv:Body>
</soapenv:Envelope>
用 <
替换 <
没有帮助。知道我实际上如何 return 那些 <
和 >
符号吗?看来无论我用什么代替它们都不起作用。
编辑
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;
}
}
而且我确实有一个更新,在添加以上所有内容后我能够得到一些不同的东西。这不是我需要的,但已经接近了。
<?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>
所以那里有一些以前没有的额外内容,并且 pingResult
由于某种原因是小写的。
响应中使用的架构 class 应如下所示:
@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;
}
}