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