如何在java中创建mime-attachment soap消息

时间:2015-06-25 05:29:17

标签: java web-services soap mime mime4j

我需要将带有mime-attachment的SOAP消息发送到我的web服务中。我为它编写了这段代码:

 File file = new File(fileName);
 DataSource ds = new FileDataSource(file) {
            public String getContentType() {
                return "application/zip";// "application/binary";
            }
        };
        UUID ref = UUID.randomUUID();
        SOAPElement refBody = refNode.addChildElement("PackageBody");
        refBody.removeContents();
        packBody.setAttribute("href", "cid:" + ref.toString());
        AttachmentPart attachment = soapMessage.createAttachmentPart(new DataHandler(ds));
        attachment.setContentId(ref.toString());
        soapMessage.addAttachmentPart(attachment);
        //
        Iterator iterator = soapMessage.getAttachments();
        while (iterator.hasNext()) {
            AttachmentPart attached = (AttachmentPart) iterator.next();
            //
            String id = attached.getContentId();
            String type = attached.getContentType();
            System.out.println("Attachment " + id + " has content type " + type);
            if (type.equals("text/xml")) {
                Object content = attached.getContent();
                System.out.println("Attachment contains:\n" + content);
            }
        }

它适用于我的项目,但不正确。如果我发送带附件的sopa请求,我有:

  

在soap请求中找到了对不存在的mime-attachment的引用   

如果是假的话,请告诉我如何纠正在java中为soap创建这个mime-attachment。感谢

0 个答案:

没有答案