[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 {
SOAPBody body = msg.getSOAPBody();
Node port = body.getChildNodes().item(0);
String portContent = port.toString();
NodeList list = port.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
port.removeChild(list.item(i));
}
ByteArrayOutputStream outArr = new ByteArrayOutputStream();
GZIPOutputStream zip = new GZIPOutputStream(outArr);
zip.write(portContent.getBytes());
zip.flush();
zip.close();
byte[] arr = outArr.toByteArray();
TestDataSource ds = new TestDataSource(arr);
AttachmentPart attPart = msg.createAttachmentPart();
attPart.setDataHandler(new DataHandler(ds));
msg.addAttachmentPart(attPart);
} catch (SOAPException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return true;
}//源代码片段来自云代码http://yuncode.net