浏览 2676 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-12-25
主要是改动header和body部分。 代码如下。 code 1 [java 取出body,加一个header] -----------------------------我是分割线 code 1------------------------------- SOAPMessage message = messageContext.getMessage(); //把soap的body提出来。 //Creates a new DOM org.w3c.dom.Document and sets the first child of this SOAPBody as //it's document element. The child SOAPElement is removed as part of the process. Document doc = message.getSOAPBody().extractContentAsDocument(); StringWriter output = new StringWriter(); TransformerFactory.newInstance().newTransformer().transform( new DOMSource(doc), new StreamResult(output)); //这个就是soapbody的字符串表示了 String bodyString = output.toString(); String encryptBodyString = encryptString(bodyString); SOAPElement soapElement = message.getSOAPHeader().addChildElement( HeaderConstant.DataQName); soapElement.addTextNode(encryptBodyString); -----------------------------我是分割线 code 1------------------------------- code 2 [java 设置body,删除一个header] -----------------------------我是分割线 code 2------------------------------- SOAPMessage message = messageContext.getMessage(); SOAPHeader header = message.getSOAPHeader(); Iterator dataIterator = header.getChildElements(HeaderConstant.DataQName); SOAPElement dataElements = (SOAPElement) dataIterator.next(); bodayString = dataElements.getValue(); String decryptString = decryptString(bodayString); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(decryptString.getBytes())); message.getSOAPBody().addDocument(doc); -----------------------------我是分割线 code 2------------------------------- 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |