use of org.bouncycastle.mail.smime.SMIMECompressedParser in project as2-lib by phax.
the class AS2ReceiverHandler method decompress.
protected void decompress(@Nonnull final IMessage aMsg) throws AS2DispositionException {
try {
if (aMsg.partnership().isDisableDecompress()) {
if (LOGGER.isInfoEnabled())
LOGGER.info("Message claims to be compressed but decompression is disabled" + aMsg.getLoggingText());
} else {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Decompressing a compressed AS2 message");
MimeBodyPart aDecompressedPart;
final ZlibExpanderProvider aExpander = new ZlibExpanderProvider();
// Compress using stream
if (LOGGER.isDebugEnabled()) {
final StringBuilder aSB = new StringBuilder();
aSB.append("Headers before uncompress\n");
final MimeBodyPart part = aMsg.getData();
final Enumeration<String> aHeaderLines = part.getAllHeaderLines();
while (aHeaderLines.hasMoreElements()) {
aSB.append(aHeaderLines.nextElement()).append('\n');
}
aSB.append("done");
LOGGER.debug(aSB.toString());
}
// The default buffer size in BufferedInputStream is 8192
final SMIMECompressedParser aCompressedParser = new SMIMECompressedParser(aMsg.getData());
// TODO: get buffer from configuration
aDecompressedPart = SMIMEUtil.toMimeBodyPart(aCompressedParser.getContent(aExpander));
// Update the message object
aMsg.setData(aDecompressedPart);
// Remember that message was decompressed
aMsg.attrs().putIn(AS2Message.ATTRIBUTE_RECEIVED_COMPRESSED, true);
if (LOGGER.isInfoEnabled())
LOGGER.info("Successfully decompressed incoming AS2 message" + aMsg.getLoggingText());
}
} catch (final SMIMEException | CMSException | MessagingException ex) {
if (LOGGER.isErrorEnabled())
LOGGER.error("Error decompressing received message", ex);
throw new AS2DispositionException(DispositionType.createError("unexpected-processing-error"), AbstractActiveNetModule.DISP_DECOMPRESSION_ERROR, ex);
}
}
Aggregations