0

我需要将带有 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 请求,我有这个:

在肥皂请求中找到对不存在的 mime-attachment 的引用

如果它是错误的方式,请告诉我如何正确地在 java 中为肥皂创建这个 mime-attachment。谢谢

4

0 回答 0