use of com.axway.ats.action.objects.model.NoSuchMimePartException in project ats-framework by Axway.
the class MimePackage method getPartHeader.
/**
* Get the specified header value from a specified MIME part
*
* @param headerName
* @param partNum
* @param headerIndex
* @return
* @throws PackageException
*/
@PublicAtsApi
public String getPartHeader(String headerName, int partNum, int headerIndex) throws PackageException {
try {
String[] headers;
if (partNum >= parts.size()) {
throw new NoSuchMimePartException("No MIME part at position '" + partNum + "'");
}
MimePart part = parts.get(partNum);
headers = part.getHeader(headerName);
if ((headers != null) && (headers.length > headerIndex)) {
return headers[headerIndex];
} else {
throw new NoSuchHeaderException(headerName, partNum, headerIndex);
}
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of com.axway.ats.action.objects.model.NoSuchMimePartException in project ats-framework by Axway.
the class MimePackage method getRegularPartContentType.
/**
* Get the content type of a regular part
*
* @param partIndex
* the index of the regular part
* @return the content type as string
* @throws PackageException
*/
@PublicAtsApi
public String getRegularPartContentType(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.getBaseType();
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of com.axway.ats.action.objects.model.NoSuchMimePartException in project ats-framework by Axway.
the class MimePackage method getAttachmentFileName.
/**
* Get an attachment's file name
*
* @param partIndex
* @return
* @throws PackageException
*/
@PublicAtsApi
public String getAttachmentFileName(int partIndex) throws PackageException {
// first check if there is part at this position at all
if (partIndex >= attachmentPartIndices.size()) {
throw new NoSuchMimePartException("No attachment at position '" + partIndex + "'");
}
try {
MimePart part = getPart(attachmentPartIndices.get(partIndex));
// get the attachment file name
String fileName = part.getFileName();
if (fileName == null) {
throw new PackageException("Could not determine file name for attachment at position " + partIndex);
}
return fileName;
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of com.axway.ats.action.objects.model.NoSuchMimePartException in project ats-framework by Axway.
the class Test_NoSuchMimePartException method constructors.
@Test
public void constructors() {
NoSuchMimePartException exception;
exception = new NoSuchMimePartException("test");
assertEquals("test", exception.getMessage());
assertNull(exception.getCause());
Exception helperException = new Exception();
exception = new NoSuchMimePartException("test", helperException);
assertEquals("test", exception.getMessage());
assertEquals(helperException, exception.getCause());
exception = new NoSuchMimePartException(helperException);
assertEquals("java.lang.Exception", exception.getMessage());
assertEquals(helperException, exception.getCause());
}
use of com.axway.ats.action.objects.model.NoSuchMimePartException in project ats-framework by Axway.
the class MimePackage method getAttachmentCharset.
/**
* Get the attachment character set
*
* @param partIndex
* the index of the attachment
* @return the character set for this attachment, null if there is no such
* @throws PackageException
*/
@PublicAtsApi
public String getAttachmentCharset(int partIndex) throws PackageException {
// first check if there is part at this position at all
if (partIndex >= attachmentPartIndices.size()) {
throw new NoSuchMimePartException("No attachment at position '" + partIndex + "'");
}
try {
MimePart part = getPart(attachmentPartIndices.get(partIndex));
// get the content type header
ContentType contentType = new ContentType(part.getContentType());
return contentType.getParameter("charset");
} catch (MessagingException me) {
throw new PackageException(me);
}
}
Aggregations