Package com.eviware.soapui.model.iface

Examples of com.eviware.soapui.model.iface.Attachment


                    .selectPath("declare namespace xop='http://www.w3.org/2004/08/xop/include'; //xop:Include");

            for (XmlObject include : includes) {
                Element elm = (Element) include.getDomNode();
                String href = elm.getAttribute("href");
                Attachment attachment = getMmSupport().getAttachmentWithContentId("<" + href.substring(4) + ">");
                if (attachment != null) {
                    ByteArrayOutputStream data = Tools.readAll(attachment.getInputStream(), 0);
                    byte[] byteArray = data.toByteArray();

                    XmlCursor cursor = include.newCursor();
                    cursor.toParent();
                    XmlObject parentXmlObject = cursor.getObject();
View Full Code Here


                        }
                    } else {
                        // extract contentId
                        String textContent = XmlUtils.getNodeValue(cursor.getDomNode());
                        if (StringUtils.hasContent(textContent)) {
                            Attachment attachment = null;
                            boolean isXopAttachment = false;

                            // is content a reference to a file?
                            if (container.isInlineFilesEnabled() && textContent.startsWith("file:")) {
                                String filename = textContent.substring(5);
                                if (container.isMtomEnabled()) {
                                    MimeBodyPart part = new PreencodedMimeBodyPart("binary");
                                    String xmimeContentType = getXmlMimeContentType(cursor);

                                    if (StringUtils.isNullOrEmpty(xmimeContentType)) {
                                        xmimeContentType = ContentTypeHandler.getContentTypeFromFilename(filename);
                                    }

                                    part.setDataHandler(new DataHandler(new XOPPartDataSource(new File(filename),
                                            xmimeContentType, schemaType)));
                                    part.setContentID("<" + filename + ">");
                                    mp.addBodyPart(part);

                                    isXopAttachment = true;
                                } else {
                                    if (new File(filename).exists()) {
                                        inlineData(cursor, schemaType, new FileInputStream(filename));
                                    } else {
                                        Attachment att = getAttachmentForFilename(container, filename);
                                        if (att != null) {
                                            inlineData(cursor, schemaType, att.getInputStream());
                                        }
                                    }
                                }
                            } else {
                                Attachment[] attachmentsForPart = container.getAttachmentsForPart(textContent);
View Full Code Here

    public static void addMimeParts(AttachmentContainer container, List<Attachment> attachments, MimeMultipart mp,
                                    StringToStringMap contentIds) throws MessagingException {
        // no multipart handling?
        if (!container.isMultipartEnabled()) {
            for (int c = 0; c < attachments.size(); c++) {
                Attachment att = attachments.get(c);
                if (att.getAttachmentType() != Attachment.AttachmentType.CONTENT) {
                    addSingleAttachment(mp, contentIds, att);
                }
            }
        } else {
            // first identify if any part has more than one attachments
            Map<String, List<Attachment>> attachmentsMap = new HashMap<String, List<Attachment>>();
            for (int c = 0; c < attachments.size(); c++) {
                Attachment att = attachments.get(c);
                if (att.getAttachmentType() == Attachment.AttachmentType.CONTENT) {
                    continue;
                }

                String partName = att.getPart();

                if (!attachmentsMap.containsKey(partName)) {
                    attachmentsMap.put(partName, new ArrayList<Attachment>());
                }

                attachmentsMap.get(partName).add(att);
            }

            // add attachments
            for (Iterator<String> i = attachmentsMap.keySet().iterator(); i.hasNext(); ) {
                attachments = attachmentsMap.get(i.next());
                if (attachments.size() == 1) {
                    Attachment att = attachments.get(0);
                    addSingleAttachment(mp, contentIds, att);
                }
                // more than one attachment with the same part -> create multipart
                // attachment
                else if (attachments.size() > 1) {
View Full Code Here

                                              List<Attachment> attachments) throws MessagingException {
        MimeMultipart multipart = new MimeMultipart("mixed");
        long totalSize = 0;

        for (int c = 0; c < attachments.size(); c++) {
            Attachment att = attachments.get(c);
            String contentType = att.getContentType();
            totalSize += att.getSize();

            MimeBodyPart part = contentType.startsWith("text/") ? new MimeBodyPart() : new PreencodedMimeBodyPart(
                    "binary");

            part.setDataHandler(new DataHandler(new AttachmentDataSource(att)));
            initPartContentId(contentIds, part, att, false);
            multipart.addBodyPart(part);
        }

        MimeBodyPart part = new PreencodedMimeBodyPart("binary");

        if (totalSize > MAX_SIZE_IN_MEMORY_ATTACHMENT) {
            part.setDataHandler(new DataHandler(new MultipartAttachmentFileDataSource(multipart)));
        } else {
            part.setDataHandler(new DataHandler(new MultipartAttachmentDataSource(multipart)));
        }

        Attachment attachment = attachments.get(0);
        initPartContentId(contentIds, part, attachment, true);

        mp.addBodyPart(part);
    }
View Full Code Here

            Attachment[] attachments = messageExchange.getRequestAttachmentsForPart(part.getName());
            if (attachments.length == 0) {
                errors.add(XmlError.forMessage("Missing attachment for part [" + part.getName() + "]"));
            } else if (attachments.length == 1) {
                Attachment attachment = attachments[0];
                String types = "";
                for (MIMEContent content : contents) {
                    String type = content.getType();
                    if (type.equals(attachment.getContentType()) || type.toUpperCase().startsWith("MULTIPART")) {
                        types = null;
                        break;
                    }
                    if (types.length() > 0) {
                        types += ",";
                    }

                    types += type;
                }

                if (types != null) {
                    String msg = "Missing attachment for part [" + part.getName() + "] with content-type [" + types + "],"
                            + " content type is [" + attachment.getContentType() + "]";

                    if (SoapUI.getSettings().getBoolean(WsdlSettings.ALLOW_INCORRECT_CONTENTTYPE)) {
                        log.warn(msg);
                    } else {
                        errors.add(XmlError.forMessage(msg));
View Full Code Here

            }

            if (attachments.length == 0) {
                errors.add(XmlError.forMessage("Missing attachment for part [" + part.getName() + "]"));
            } else if (attachments.length == 1) {
                Attachment attachment = attachments[0];
                String types = "";
                for (MIMEContent content : contents) {
                    String type = content.getType();
                    if (type.equals(attachment.getContentType()) || type.toUpperCase().startsWith("MULTIPART")) {
                        types = null;
                        break;
                    }

                    if (types.length() > 0) {
                        types += ",";
                    }

                    types += type;
                }

                if (types != null) {
                    String msg = "Missing attachment for part [" + part.getName() + "] with content-type [" + types
                            + "], content type is [" + attachment.getContentType() + "]";

                    if (SoapUI.getSettings().getBoolean(WsdlSettings.ALLOW_INCORRECT_CONTENTTYPE)) {
                        log.warn(msg);
                    } else {
                        errors.add(XmlError.forMessage(msg));
View Full Code Here

                    Attachment[] attachments = ((MessageExchange) result).getResponseAttachments();
                    if (attachments != null && attachments.length > 0) {
                        for (int c = 0; c < attachments.length; c++) {
                            fileName = nameBase + "-attachment-" + (c + 1) + ".";

                            Attachment attachment = attachments[c];
                            String contentType = attachment.getContentType();
                            if (!"application/octet-stream".equals(contentType) && contentType != null
                                    && contentType.indexOf('/') != -1) {
                                fileName += contentType.substring(contentType.lastIndexOf('/') + 1);
                            } else {
                                fileName += "dat";
                            }

                            fileName = absoluteOutputFolder + File.separator + fileName;

                            FileOutputStream outFile = new FileOutputStream(fileName);
                            Tools.writeAll(outFile, attachment.getInputStream());
                            outFile.close();
                        }
                    }
                }
View Full Code Here

    public void setAttachXmlBomb(boolean attach) {
        xmlBombConfig.setAttachXmlBomb(attach);
    }

    private Attachment addAttachement(TestStep testStep) {
        Attachment attach = null;
        if (isAttachXmlBomb()) {
            WsdlRequest request = (WsdlRequest) getRequest(testStep);

            if (currentIndex < getXmlBombList().size()) {
                String bomb = getXmlBombList().get(currentIndex);
                try {
                    File bombFile = File.createTempFile(getAttachmentPrefix(), ".xml");
                    BufferedWriter writer = new BufferedWriter(new FileWriter(bombFile));
                    writer.write(bomb);
                    writer.flush();
                    request.setInlineFilesEnabled(false);
                    attach = request.attachFile(bombFile, false);
                    attach.setContentType("text/xml;");
                    currentIndex++;
                } catch (IOException e) {
                    SoapUI.logError(e);
                }
            }
View Full Code Here

    }

    private Attachment addAttachment(TestStep testStep, File file, String contentType, boolean generated, boolean cache)
            throws IOException {
        AbstractHttpRequest<?> request = (AbstractHttpRequest<?>) getRequest(testStep);
        Attachment attach = request.attachFile(file, cache);
        attach.setContentType(contentType);

        return attach;
    }
View Full Code Here

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        if (AttachmentContainer.ATTACHMENTS_PROPERTY.equals(evt.getPropertyName())) {
            if (evt.getOldValue() == null && evt.getNewValue() != null) {
                if (evt.getNewValue() instanceof Attachment) {
                    Attachment attachment = (Attachment) evt.getNewValue();
                    addedAttachment(attachment);
                }
            } else if (evt.getOldValue() != null && evt.getNewValue() == null) {
                if (evt.getOldValue() instanceof Attachment) {
                    Attachment attachment = (Attachment) evt.getOldValue();
                    removedAttachment(attachment);
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.eviware.soapui.model.iface.Attachment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.