File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Create Attachment with SAAJ is problem" Watch "Create Attachment with SAAJ is problem" New topic
Author

Create Attachment with SAAJ is problem

chinna sankar
Greenhorn

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();
System.out.println(mf);
SOAPMessage _msg = mf.createMessage();
SOAPPart spart = _msg.getSOAPPart();
SOAPEnvelope senv = spart.getEnvelope();
SOAPBody soapbody = senv.getBody();
SOAPHeader sheaser = senv.getHeader();
_msg.writeTo(System.out);
FileDataSource fdsource = new FileDataSource(new File("C:/n.xml"));
DataHandler dhandler = new DataHandler(fdsource);
AttachmentPart apart = _msg.createAttachmentPart(dhandler);
_msg.addAttachmentPart(apart);
_msg.saveChanges();
_msg.writeTo(System.out);


I got below error


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

Joined: Aug 19, 2005
Posts: 2922
    
    5
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
    Greenhorn

    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: http://aspose.com/file-tools
     
    subject: Create Attachment with SAAJ is problem