Hi All,

I am creating a SOAP message using axis2 soap-api and soap-impl. First I am
creating the SOAPPart and then I am adding the attachmentpart.

Now, when I do soapMessage.writeTo(OuputStream out), it only writes the soap
envelop and not the MIME message. Could somebody please clarify why it is
not writing the MIME message. Following is my code snippet....

      soapMsg = MessageFactory.newInstance().createMessage();
      //setting the namespace declaration.
      SOAPPart sp = soapMsg.getSOAPPart();
      SOAPEnvelope se = sp.getEnvelope();
      soapMsg.setProperty(soapMsg.CHARACTER_SET_ENCODING, DEFAULT_ENCODING);
      soapMsg.setProperty(soapMsg.WRITE_XML_DECLARATION, "true");

     se.addChildElemet().......

     then I am adding the attachments...like
     addAttachments(attachmentList);


private void addAttachments(List attachmentList) throws SOAPException,
IOException {
      if (attachmentList != null && attachmentList.size() > 0) {
          Iterator attachmentit = attachmentList.iterator();
          while (attachmentit.hasNext()) {
              DataHandler dh = (DataHandler) attachmentit.next();
              AttachmentPart ap = soapMsg.createAttachmentPart();
              ap.setContentId(dh.getName());
              Object content = dh.getContent();
              ap.setContent(dh.getContent(), dh.getContentType());
              soapMsg.addAttachmentPart(ap);
          }
      }
  }


Thanks,
Chinmoy

Reply via email to