It's not a secret anymore!
The moose likes Web Services and the fly likes Create Attachment with SAAJ is problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Create Attachment with SAAJ is problem" Watch "Create Attachment with SAAJ is problem" New topic

Create Attachment with SAAJ is problem

chinna sankar

Joined: Mar 06, 2005
Posts: 22
I am working for making Attachment with SOAP (we are making a SOAP Messages with Attachment and then sent via socket It�s not any web service). It�s very simple application

The below jar files are in my class path
saaj-ri.jar, saaj-api.jar, dom4j.jar,activation.jar,mail.jar,comman-logging.jar

My code is:
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage _msg = mf.createMessage();
SOAPPart spart = _msg.getSOAPPart();
SOAPEnvelope senv = spart.getEnvelope();
SOAPBody soapbody = senv.getBody();
SOAPHeader sheaser = senv.getHeader();
FileDataSource fdsource = new FileDataSource(new File("C:/n.xml"));
DataHandler dhandler = new DataHandler(fdsource);
AttachmentPart apart = _msg.createAttachmentPart(dhandler);

I got below error

java.lang.NoClassDefFoundError at com.sun.xml.messaging.saaj.soap.MessageImpl.createAttachmentPart(
at javax.xml.soap.SOAPMessage.createAttachmentPart(Unknown Source)
Peer Reynders

Joined: Aug 19, 2005
Posts: 2930
You may be experiencing a mailcap issue � though I can't be certain.
When trying to find a DataContentHandler (DCH) JAF 1.0.2 checks for mailcap files in the following order
  • user.home/mailcap
  • java.home/lib/mailcap
  • META-INF/mailcap
  • META-INF/mailcap.default

  • Issues:
  • Some SAAJ implementations provide their own mailcap file. In that case it is necessary to make sure that the mail.jar (with its META-INF/mailcap file) occurs after the SAAJ implementation jar (which may have it's own META-INF/mailcap) in the class path. So move that mail.jar to the end of the classpath.
  • The user.home/mailcap or java.home/lib/mailcap may specify a DataContentHandler that is incompatible with the SAAJ-implementation and/or that is provided in a JAR not currently in your class path.

  • [ April 21, 2006: Message edited by: Peer Reynders ]
    chinna sankar

    Joined: Mar 06, 2005
    Posts: 22
    Hi Peer Reynders ,

    Thank you, It's really Good information for me.

    I done accrodingly, I changed the order of Loading Jar files, Finally i suceeded to run my application with out any errors.

    Thanks again Peer Reynders.
    I agree. Here's the link:
    subject: Create Attachment with SAAJ is problem
    It's not a secret anymore!