I am trying to pass different files using a
SOAP with attachments (JAXM). It works fine for an xml file as the attchment (for example) but any other type of file is causing the following error:
"java.net.SocketException: Unexpected end of file from server"
The code I am using to pass create the attachment is:
File outputFile = new File("C:/myfile.bmp");
//Build the call:-
//Get a connection
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection connSOAP = scf.createConnection();
//Create a message
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = mf.createMessage();
//Access the elements of the message
SOAPPart part = msg.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
//Add a new SOAP element
Name name = envelope.createName("loadFile");
SOAPElement child = body.addBodyElement(name);
//Add content
name = envelope.createName("filename");
SOAPElement filename = child.addChildElement(name);
filename.addTextNode(outputFile.getAbsolutePath());
//Add attachment
URL fileurl = outputFile.toURL();
DataHandler dh = new DataHandler(fileurl);
AttachmentPart attachment = msg.createAttachmentPart(dh);
attachment.setContentId("test_file");
msg.addAttachmentPart(attachment);
Any ideas as to where I'm going wrong? Or is this a known bug?
Any help, very much appreciated.
Cheers
Ste