result = AssertionResult.RESULT_NOT_APPLICABLE;
}
else
{
MimeParts mimeParts = entryContext.getMessageEntry().getMimeParts();
MimePart part = mimeParts.getRootPart();
if (part == null)
{
result = AssertionResult.RESULT_NOT_APPLICABLE;
}
else
{
String xmlEncoding = null;
String charset = MIMEUtils.getMimeHeaderSubAttribute(
part.getHeaders(),
MIMEConstants.HEADER_CONTENT_TYPE,
"charset");
try
{
// The HTTP Content-Type header's charset value is either UTF-8 or UTF-16.
if((charset != null) && (charset.equalsIgnoreCase("utf-8") ||
charset.equalsIgnoreCase("utf-16")))
{
// Looking at the messageContent element of the logged message, either
// (1) it has a BOM attribute which maps the charset value in the Content-Type header, or
int bom = 0;
if ((bom = entryContext.getMessageEntry().getBOM()) != 0)
{
if ((bom == WSIConstants.BOM_UTF8
&& !charset.equalsIgnoreCase("utf-8"))
|| ((bom == WSIConstants.BOM_UTF16
&& !charset.equalsIgnoreCase("utf-16")))
|| ((bom == WSIConstants.BOM_UTF16_BIG_ENDIAN
&& !charset.equalsIgnoreCase("utf-16"))))
{
throw new AssertionFailException("The BOM (" + bom +
") and charset value (" + charset + ")do not match.");
}
}
// (2) it has an XML declaration which matches the charset value in the Content-Type header, or
else if (((xmlEncoding =
Utils.getXMLEncoding(part.getContent())) != null) &&
!xmlEncoding.equals(""))
{
if(!xmlEncoding.equalsIgnoreCase(charset))
{
throw new AssertionFailException("The XML declaration encoding (" +