soap字符串报文转对象,对象再转为字符串,报文的body部分丢失,求解
/**
* <把soap字符串格式化为SOAPMessage>
* <功能详细描述>
* @param soapString
* @return
*/
public static SOAPMessage formartStringToSoap(String soapString){
MessageFactory msgFactory;
try{
msgFactory = MessageFactory.newInstance();
SOAPMessage reqMsg =
msgFactory.createMessage(new MimeHeaders(),
new ByteArrayInputStream(soapString.getBytes(Charset.forName("UTF-8"))));
reqMsg.saveChanges();
return reqMsg;
}
catch (Exception e){
e.printStackTrace();
return null;
}
}
/**
* 把soap对象格式化为字符串
* @param soapPart
* @return
*/
public static String formartSoapToString(SOAPMessage soapMessage){
String str="";
try{
SOAPPart soapPart=soapMessage.getSOAPPart();
Transformer trans = TransformerFactory.newInstance().newTransformer();
StringWriter sw = new StringWriter();
trans.transform(new DOMSource(soapPart.getEnvelope()), new StreamResult(sw));
sw.flush();
sw.close();
str=format(sw.toString());
}catch(Exception e){
e.printStackTrace();
}
return str;
}
我的字符串是下面的这个
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:out_parResponse xmlns:ns="http://ws.apache.org/axis2">
<return>838</return>
</ns:out_parResponse>
</soapenv:Body>
</soapenv:Envelope>
调用方法装换为soap报文,然后再转换为字符串,<return>838</return>(这个字符串的值丢失了,求解??)
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body/>
</SOAP-ENV:Envelope>
是不是因为jar包的版本不对,还是什么呀???
字符里面是<soapenv,转为对象再转为字符串的时候,居然变成了<SOAP-ENV