use of com.axway.ats.action.objects.model.NoSuchHeaderException 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.NoSuchHeaderException in project ats-framework by Axway.
the class HeaderRule method performMatch.
@Override
protected boolean performMatch(MetaData metaData) throws RbvException {
//get the emailMessage
//the meta data type check already passed, so it is safe to cast
MimePackage emailMessage = getNeededMimePackage(metaData);
String[] headerValues;
try {
if (headerIndex == -1) {
// we are going to check all header values
if (partIndex == PART_MAIN_MESSAGE) {
headerValues = emailMessage.getHeaderValues(headerName);
} else {
headerValues = emailMessage.getPartHeaderValues(headerName, partIndex);
}
} else {
// we are going to check a particular header value
String headerValue;
if (partIndex == PART_MAIN_MESSAGE) {
headerValue = emailMessage.getHeader(headerName, headerIndex);
} else {
headerValue = emailMessage.getPartHeader(headerName, partIndex, headerIndex);
}
headerValues = new String[] { headerValue };
}
} catch (NoSuchHeaderException nshe) {
log.debug("Meta data has no header '" + headerName + "'");
//no such header, so return false
return false;
} catch (PackageException pe) {
throw new RbvException(pe);
}
//if there is no such header return false
boolean actualResult = false;
if (headerValues == null || headerValues.length == 0) {
log.info("No header '" + headerName + "' was found");
} else {
for (String headerValue : headerValues) {
switch(matchMode) {
case LEFT:
actualResult = headerValue.startsWith(expectedValue);
break;
case RIGHT:
actualResult = headerValue.endsWith(expectedValue);
break;
case EQUALS:
actualResult = headerValue.equals(expectedValue);
break;
case FIND:
actualResult = headerValue.indexOf(expectedValue) >= 0;
break;
case REGEX:
actualResult = Pattern.compile(expectedValue).matcher(headerValue).find();
break;
}
log.info("Actual value for header '" + headerName + "' is '" + headerValue + "'");
if (actualResult) {
// we matched a header value, stop iterating the rest of the values
break;
}
}
}
return actualResult;
}
use of com.axway.ats.action.objects.model.NoSuchHeaderException in project ats-framework by Axway.
the class MimePackage method getPartHeaderValues.
/**
* Get all header values from a specified MIME part
*
* @param headerName
* @param partNum
* @return
* @throws PackageException
*/
@PublicAtsApi
public String[] getPartHeaderValues(String headerName, int partNum) 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 > 0)) {
return headers;
} else {
throw new NoSuchHeaderException(headerName, partNum);
}
} catch (MessagingException me) {
throw new PackageException(me);
}
}
Aggregations