Hi Marc,
The writeTo method should work even when there are attachments.
How were the attachments created ?. Which JDK are you using and which
version of SAAJ are you using ?. Are you using the latest downloadble
from saaj.dev.java.net ?.
Can you also try doing the following :
1. Set system property -Djava.awt.headless=true for your VM
running this code
2. Capture the Message with a TCP Monitor and send the message
to me, so i can try and reproduce the problem locally.
regards,
kumar
Marc Beckers wrote:
>
> Hello,
>
> I have to store a SOAPMessage with two AttachmentParts (SAAJ) into a
> database (MySQL) as one BLOB, but I get an IOException:
>
>java.io.IOException: Unable to run the JPEG Encoder on a stream
>
>
>
>
> Here is my code:
>
> ByteArrayOutputStream baos = *new* ByteArrayOutputStream();
> // dto.getInhoud() returns a javax.xml.soap.SOAPMessage with two
> // javax.xml.soap.AttachmentPart's (jpg images)
> dto.getInhoud().writeTo(baos); // here I get the IOException
> *byte*[] buffer = baos.toByteArray();
> ByteArrayInputStream bais = *new* ByteArrayInputStream(buffer);
> ps.setBinaryStream(10, bais, buffer.length);
>
>
>
>
> Here is the output:
>
>31-okt-2006 12:06:59 com.sun.xml.messaging.saaj.soap.MessageImpl saveChanges
>SEVERE: SAAJ0540: Error during saving a multipart message
>31-okt-2006 12:06:59 wo.wow.WOWController doPost
>SEVERE: Er is een exceptie opgetreden in WOWController.doPost().
>com.sun.xml.messaging.saaj.SOAPExceptionImpl: Error during saving a multipart message
> at com.sun.xml.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:1104)
> at com.sun.xml.messaging.saaj.soap.MessageImpl.writeTo(MessageImpl.java:1196)
> at wo.dao.BerichtDAO.create(BerichtDAO.java:67)
> at wo.wow.BerichtBeheerder.opslaan(BerichtBeheerder.java:169)
> at wo.wow.dossier.BetalingsverzoekDoe.execute(BetalingsverzoekDoe.java:51)
> at wo.wow.WOWController.doPost(WOWController.java:222)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
> at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
> at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
> at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:535)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
> at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
> at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:790)
> at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:709)
> at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:572)
> at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
> at java.lang.Thread.run(Thread.java:595)
>Caused by: java.io.IOException: Unable to run the JPEG Encoder on a stream [B
> at com.sun.xml.messaging.saaj.soap.JpegDataContentHandler.writeTo(JpegDataContentHandler.java:149)
> at javax.activation.ObjectDataContentHandler.writeTo(Unknown Source)
> at javax.activation.DataHandler.writeTo(Unknown Source)
> at com.sun.xml.messaging.saaj.packaging.mime.internet.MimeBodyPart.writeTo(MimeBodyPart.java:880)
> at com.sun.xml.messaging.saaj.packaging.mime.internet.MimeMultipart.writeTo(MimeMultipart.java:245)
> at com.sun.xml.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:1092)
> ... 38 more
>
>CAUSE:
>
>java.io.IOException: Unable to run the JPEG Encoder on a stream [B
> at com.sun.xml.messaging.saaj.soap.JpegDataContentHandler.writeTo(JpegDataContentHandler.java:149)
> at javax.activation.ObjectDataContentHandler.writeTo(Unknown Source)
> at javax.activation.DataHandler.writeTo(Unknown Source)
> at com.sun.xml.messaging.saaj.packaging.mime.internet.MimeBodyPart.writeTo(MimeBodyPart.java:880)
> at com.sun.xml.messaging.saaj.packaging.mime.internet.MimeMultipart.writeTo(MimeMultipart.java:245)
> at com.sun.xml.messaging.saaj.soap.MessageImpl.saveChanges(MessageImpl.java:1092)
> at com.sun.xml.messaging.saaj.soap.MessageImpl.writeTo(MessageImpl.java:1196)
> at wo.dao.BerichtDAO.create(BerichtDAO.java:67)
> at wo.wow.BerichtBeheerder.opslaan(BerichtBeheerder.java:169)
> at wo.wow.dossier.BetalingsverzoekDoe.execute(BetalingsverzoekDoe.java:51)
> at wo.wow.WOWController.doPost(WOWController.java:222)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
> at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
> at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
> at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
> at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
> at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
> at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
> at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
> at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:535)
> at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
> at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
> at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
> at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
> at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:790)
> at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:709)
> at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:572)
> at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:644)
> at java.lang.Thread.run(Thread.java:595)
>
>
>
>
> Who can help me?
>
> with kind regards,
>
> Marc Beckers
>
> P.S. When the SOAPMessage has no AttachmentParts it works fine.