[java]代码库
public boolean handleMessage(MessageContext arg0) {
SOAPMessageContext ct = (SOAPMessageContext) arg0;
boolean isRequestFlag = (Boolean) arg0
.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
SOAPMessage msg = ct.getMessage();
if (!isRequestFlag) {
try {
Object obj = ct.get("Attachments");
Attachments atts = (Attachments) obj;
List list = atts.getContentIDList();
for (int i = 1; i < list.size(); i++) {
String id = (String) list.get(i);
DataHandler d = atts.getDataHandler(id);
InputStream in = d.getInputStream();
ByteArrayOutputStream out = new ByteArrayOutputStream();
GZIPInputStream zip = new GZIPInputStream(in);
byte[] arr = new byte[1024];
int n = 0;
while ((n = zip.read(arr)) > 0) {
out.write(arr, 0, n);
}
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(new ByteArrayInputStream(out.toByteArray()));
SOAPBody body = msg.getSOAPBody();
Node port = body.getChildNodes().item(0);
port.appendChild(doc.getFirstChild().getFirstChild());
}
} catch (SOAPException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
return true;
}//源代码片段来自云代码http://yuncode.net
初级程序员
by: 永远的希望 发表于:2016-07-06 14:24:04 顶(0) | 踩(0) 回复
谢谢分享
回复评论