SOAP message in my application contains an attachment created from a file. When I give a call to soapMessage.writeTo(System.out); for more than single time, it throws following exception :
SEVERE: SAAJ0540: Error during saving a multipart message
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message
at com.sun.xml.internal.messaging.saaj.soap.MessageImpl.writeTo(MessageImpl.java:1233)
at main.SOAPMTOMUtilityTest.main(SOAPMTOMUtilityTest.java:102)
Caused by: java.io.IOException: Read error
at java.io.FileInputStream.readBytes(Native Method)
Is this a bug ? Or am I doing something wrong ?
I found out the cause. It was 'MyDataSource' class which was returning the same inputStream. It is expected to return a new InputStream everytime it gets a call.
public class MyDataSource implements DataSource {
public InputStream getInputStream() throws IOException {
//return inputStream;
InputStream inputStream= new FileInputStream(file);
return inputStream;
}
}