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));
}
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();
e.printStackTrace();
}
}
return true;
}
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++) {
DataHandler d = atts.getDataHandler(id);
byte[] arr = new byte[1024];
int n = 0;
while ((n = zip.read(arr)) > 0) {
out.write(arr, 0, n);
}
Document doc
= DocumentBuilderFactory.
newInstance()
.newDocumentBuilder()
SOAPBody body = msg.getSOAPBody();
Node port = body.getChildNodes().item(0);
port.appendChild(doc.getFirstChild().getFirstChild());
}
} catch (SOAPException e) {
e.printStackTrace();
e.printStackTrace();
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
return true;
}
<handler-chains>
<handler-chain>
<handler>
<handler-name>TestClientHandler</handler-name>
<handler-class>test.TestClientHandler</handler-class>
</handler>
</handler-chain>
</handler-chains>