When I try to construct a SOAP message with an attachment there is no
attachment being attached when I send it.
The monitor between my source and the endpoint picks up the main soap
message but does not include the attachments.
There are no exceptions thrown on the SOAP client like attachments not
supported, and a similair snippet has worked using an older version of axis.
There are ways to do it by using datahandlers and call objects in RPC
mode, but this is JAXM and is manipulating the SOAP message directly,
and it's meant to handle attachments as shown but does not.
Simon...
Client source:
private boolean sendXML(String xml,String endPoint,String keyA,String
keyB) throws Exception {
SOAPConnectionFactory scFactory =
SOAPConnectionFactory.newInstance();
SOAPConnection con = scFactory.createConnection();
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
Name bodyName = envelope.createName("store", "n",
"urn:xmethods-repository");
SOAPBodyElement gltp = body.addBodyElement(bodyName);
Name nameA = envelope.createName("keyA");
SOAPElement keyAElement = gltp.addChildElement(nameA);
keyAElement.addTextNode(keyA);
Name nameB = envelope.createName("keyB");
SOAPElement keyBElement = gltp.addChildElement(nameB);
keyBElement.addTextNode(keyB);
URLEndpoint endpoint = new URLEndpoint(endPoint);
// attachment part
AttachmentPart ap = message.createAttachmentPart();
ap.setContent(xml, "text/xml");
ap.setContentId("MyContentId");
message.addAttachmentPart(ap);
AttachmentPart ap2 = message.createAttachmentPart();
ap2.setContent("test attachment", "text/plain");
ap2.setContentId("otherContentID");
message.addAttachmentPart(ap2);
message.saveChanges();
SOAPMessage response = con.call(message, endpoint);
con.close();
}