Java 如果存在多个子元素,则无法提取SOAPBody内容
我正在尝试读取SOAP响应内容类型multipart/mixed。Mime头:应用程序/soap+xml 这在Java1.6和WebLogic11g中适用,但在Java1.7/WebLogic12c中不适用。引发异常的extractContentAsDocument来自:jar:file:/u01/app/oracle/Middleware/12c/oracle\u common/modules/com.oracle.webservices.orasaaj-rt-api\u 12.1.2.jar/oracle/j2ee/ws/saaj/soap/soap12/Body12.class 错误: javax.xml.soap.SOAPException:如果存在多个子元素,则无法提取SOAPBody内容 位于oracle.j2ee.ws.saaj.soap.BodyImpl.extractContentAsDocumentBodyImpl.java:233 在queryProducerqueryProducer.java:84Java 如果存在多个子元素,则无法提取SOAPBody内容,java,soap,weblogic,multipart,saaj,Java,Soap,Weblogic,Multipart,Saaj,我正在尝试读取SOAP响应内容类型multipart/mixed。Mime头:应用程序/soap+xml 这在Java1.6和WebLogic11g中适用,但在Java1.7/WebLogic12c中不适用。引发异常的extractContentAsDocument来自:jar:file:/u01/app/oracle/Middleware/12c/oracle\u common/modules/com.oracle.webservices.orasaaj-rt-api\u 12.1.2.jar
queryProducer.java:83:
SOAPMessage response = dispatch.invoke(request);
return response.getSOAPBody().extractContentAsDocument();
作为字符串的完整响应:
urn:ihe:iti:2007:CrossGatewayQueryResponse
f3116ff8-378d-11e4-b68e-8f828f8a95e9
urn:ihe:iti:2007:CrossGatewayQuery
我尝试了不同的方法使其工作,并使其工作,如下所述:。我认为主要的事情可能是升级Jersey的版本,并从应用程序包中选择它。好的。。。我遇到了完全相同的问题并解决了它。 这实际上是一个解决办法。 创建信封.class和Body.class,例如:
@XmlRootElement(name = "Envelope", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
public class Envelope {
@XmlElement(name = "Body", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
private Body body;
public Body getBody() {
return body;
}
public void setBody() {
this.body = new Body();
}
}
及
在你的代码中:
SOAPMessage response = dispatch.invoke(request);
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.writeTo(out);
JAXBContext jc = JAXBContext.newInstance(Envelope.class);
Unmarshaller um = jc.createUnmarshaller();
Envelope envelope = (Envelope) um.unmarshal(new ByteArrayInputStream(out.toByteArray()));
Body body = envelope.getBody();
body.methodFromWsdl... etc.
我有同样的问题,有同样的异常和消息。我们使用了一个模拟服务,该服务返回匹配请求的罐装XML。问题是SOAP Body元素的子元素周围有空格,这触发了此异常 通常,普通的Web服务只生成一行XML,使用时不会出现任何问题
@XmlRootElement(name = "Envelope", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
public class Envelope {
@XmlElement(name = "Body", namespace = "http://schemas.xmlsoap.org/soap/envelope/")
private Body body;
public Body getBody() {
return body;
}
public void setBody() {
this.body = new Body();
}
}
@XmlType
public class Body {
@XmlElement(name = "NameOfElementChildInBody", namespace = "namespace if needed for body")
private POJOClassOfElementChildInBody someVariableName;
public void setterIfNeeded(POJOClassOfElementChildInBody someVariableName) {
this.someVariableName = someVariableName;
}
}
SOAPMessage response = dispatch.invoke(request);
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.writeTo(out);
JAXBContext jc = JAXBContext.newInstance(Envelope.class);
Unmarshaller um = jc.createUnmarshaller();
Envelope envelope = (Envelope) um.unmarshal(new ByteArrayInputStream(out.toByteArray()));
Body body = envelope.getBody();
body.methodFromWsdl... etc.