Search in sources :

Example 1 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class MimePackage method getRegularPartCharset.

/**
     * Get the character set of a regular part
     *
     * @param partIndex
     *            the index of the part
     * @return the charset
     * @throws PackageException
     */
@PublicAtsApi
public String getRegularPartCharset(int partIndex) throws PackageException {
    // first check if there is part at this position at all
    if (partIndex >= regularPartIndices.size()) {
        throw new NoSuchMimePartException("No regular part at position '" + partIndex + "'");
    }
    try {
        MimePart part = getPart(regularPartIndices.get(partIndex));
        // get the content type header
        ContentType contentType = new ContentType(part.getContentType());
        return contentType.getParameter("charset");
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : ContentType(javax.mail.internet.ContentType) MessagingException(javax.mail.MessagingException) NoSuchMimePartException(com.axway.ats.action.objects.model.NoSuchMimePartException) MimePart(javax.mail.internet.MimePart) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 2 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class MimePackage method getAllHeaders.

@SuppressWarnings("unchecked")
@PublicAtsApi
public List<PackageHeader> getAllHeaders() throws PackageException {
    try {
        List<PackageHeader> headers = new ArrayList<PackageHeader>();
        Enumeration<Header> messageHeaders = message.getAllHeaders();
        while (messageHeaders.hasMoreElements()) {
            Header messageHeader = messageHeaders.nextElement();
            headers.add(new PackageHeader(messageHeader.getName(), messageHeader.getValue()));
        }
        return headers;
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : Header(javax.mail.Header) PackageHeader(com.axway.ats.action.objects.model.PackageHeader) MessagingException(javax.mail.MessagingException) ArrayList(java.util.ArrayList) PackageHeader(com.axway.ats.action.objects.model.PackageHeader) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 3 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class MimePackage method writeToFile.

/**
     * Write the constructed MIME message to a file
     *
     * @param fileName
     *            the name of the file to write to
     *
     * @throws IOException
     * @throws PackageException
     */
@PublicAtsApi
public void writeToFile(String fileName) throws IOException, PackageException {
    FileOutputStream outStream = null;
    boolean storeReconnected = false;
    try {
        storeReconnected = reconnectStoreIfClosed();
        // store should be opened for actions including getting InputStream. Hence store open is not in getPart
        outStream = new FileOutputStream(new File(fileName));
        message.writeTo(outStream);
    } catch (MessagingException me) {
        throw new PackageException("Could not write message content", me);
    } finally {
        if (outStream != null) {
            outStream.close();
        }
        try {
            closeStoreConnection(storeReconnected);
        } catch (MessagingException ex) {
            log.warn("Error closing IMAP connection", ex);
        }
    }
}
Also used : MessagingException(javax.mail.MessagingException) FileOutputStream(java.io.FileOutputStream) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) File(java.io.File) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 4 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class MimePackage method getPartChecksum.

/**
     * Return the CRC checksum of a given part
     *
     * @param partIndex
     *            the index of the part
     * @param isAttachment
     *            true if the part is an attachment
     * @return the part checksum
     * @throws PackageException
     */
@PublicAtsApi
public long getPartChecksum(int partIndex, boolean isAttachment) throws PackageException {
    InputStream partDataStream = getPartData(partIndex, isAttachment);
    if (partDataStream != null) {
        try {
            SeekInputStream seekDataStream = new SeekInputStream(partDataStream);
            seekDataStream.seek(0);
            // create a new crc and reset it
            CRC32 crc = new CRC32();
            // use checked stream to get the checksum
            CheckedInputStream stream = new CheckedInputStream(seekDataStream, crc);
            int bufLen = 4096;
            byte[] buffer = new byte[bufLen];
            int numBytesRead = bufLen;
            while (numBytesRead == bufLen) {
                numBytesRead = stream.read(buffer, 0, bufLen);
            }
            long checksum = stream.getChecksum().getValue();
            stream.close();
            return checksum;
        } catch (IOException ioe) {
            throw new PackageException(ioe);
        }
    } else {
        throw new MimePartWithoutContentException("MIME part does not have any content");
    }
}
Also used : SeekInputStream(com.axway.ats.core.io.SeekInputStream) CRC32(java.util.zip.CRC32) CheckedInputStream(java.util.zip.CheckedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SeekInputStream(com.axway.ats.core.io.SeekInputStream) InputStream(java.io.InputStream) MimePartWithoutContentException(com.axway.ats.action.objects.model.MimePartWithoutContentException) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) IOException(java.io.IOException) CheckedInputStream(java.util.zip.CheckedInputStream) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 5 with PublicAtsApi

use of com.axway.ats.common.PublicAtsApi in project ats-framework by Axway.

the class MimePackage method getWholePackage.

@PublicAtsApi
public InputStream getWholePackage() throws PackageException {
    boolean storeReconnected = false;
    try {
        storeReconnected = reconnectStoreIfClosed();
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        message.writeTo(outStream);
        return new ByteArrayInputStream(outStream.toByteArray());
    } catch (MessagingException me) {
        throw new PackageException("Could not write message content", me);
    } catch (IOException ioe) {
        throw new PackageException("Could not write message content", ioe);
    } finally {
        try {
            closeStoreConnection(storeReconnected);
        } catch (MessagingException ex) {
            log.warn(ex);
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MessagingException(javax.mail.MessagingException) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

PublicAtsApi (com.axway.ats.common.PublicAtsApi)409 Validator (com.axway.ats.core.validation.Validator)66 SwingElementState (com.axway.ats.uiengine.utilities.swing.SwingElementState)60 WebElement (org.openqa.selenium.WebElement)57 IFileSystemOperations (com.axway.ats.core.filesystem.model.IFileSystemOperations)44 HiddenHtmlElementState (com.axway.ats.uiengine.utilities.hiddenbrowser.HiddenHtmlElementState)32 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)31 PackageException (com.axway.ats.action.objects.model.PackageException)31 RealHtmlElementState (com.axway.ats.uiengine.utilities.realbrowser.html.RealHtmlElementState)31 MessagingException (javax.mail.MessagingException)31 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)24 ArrayList (java.util.ArrayList)18 SeleniumOperationException (com.axway.ats.uiengine.exceptions.SeleniumOperationException)16 UiElementException (com.axway.ats.uiengine.exceptions.UiElementException)16 IOException (java.io.IOException)16 JTableFixture (org.fest.swing.fixture.JTableFixture)16 Actions (org.openqa.selenium.interactions.Actions)16 NotSupportedOperationException (com.axway.ats.uiengine.exceptions.NotSupportedOperationException)15 VerifyNotEqualityException (com.axway.ats.uiengine.exceptions.VerifyNotEqualityException)15 XMLException (com.axway.ats.common.xml.XMLException)14