use of com.helger.phase4.attachment.EAS4CompressionMode in project phase4 by phax.
the class PeppolCompatibilityValidator method validatePMode.
@Override
public void validatePMode(@Nonnull final IPMode aPMode, @Nonnull final ErrorList aErrorList) {
ValueEnforcer.isTrue(aErrorList.isEmpty(), () -> "Errors in global PMode validation: " + aErrorList.toString());
try {
MetaAS4Manager.getPModeMgr().validatePMode(aPMode);
} catch (final PModeValidationException ex) {
aErrorList.add(_createError(ex.getMessage()));
}
final EMEP eMEP = aPMode.getMEP();
final EMEPBinding eMEPBinding = aPMode.getMEPBinding();
if (eMEP == EMEP.ONE_WAY && eMEPBinding == EMEPBinding.PUSH) {
// Valid
} else {
aErrorList.add(_createError("An invalid combination of PMode MEP (" + eMEP + ") and MEP binding (" + eMEPBinding + ") was specified, only one-way/push is valid."));
}
// Leg1 must be present
final PModeLeg aPModeLeg1 = aPMode.getLeg1();
if (aPModeLeg1 == null) {
aErrorList.add(_createError("PMode.Leg[1] is missing"));
} else {
_checkIfLegIsValid(aErrorList, aPModeLeg1, "PMode.Leg[1].");
}
if (aPMode.getLeg2() != null) {
aErrorList.add(_createError("PMode.Leg[2] must not be present"));
}
// Compression application/gzip ONLY
// other possible states are absent or "" (No input)
final PModePayloadService aPayloadService = aPMode.getPayloadService();
if (aPayloadService != null) {
final EAS4CompressionMode eCompressionMode = aPayloadService.getCompressionMode();
if (eCompressionMode != null) {
if (!eCompressionMode.equals(EAS4CompressionMode.GZIP))
aErrorList.add(_createError("PMode.PayloadService.CompressionMode must be " + EAS4CompressionMode.GZIP + " instead of " + eCompressionMode));
}
}
}
use of com.helger.phase4.attachment.EAS4CompressionMode in project phase4 by phax.
the class CEFCompatibilityValidator method validatePMode.
@Override
public void validatePMode(@Nonnull final IPMode aPMode, @Nonnull final ErrorList aErrorList) {
ValueEnforcer.isTrue(aErrorList.isEmpty(), () -> "Errors in global PMode validation: " + aErrorList.toString());
try {
MetaAS4Manager.getPModeMgr().validatePMode(aPMode);
} catch (final PModeValidationException ex) {
aErrorList.add(_createError(ex.getMessage()));
}
final EMEP eMEP = aPMode.getMEP();
final EMEPBinding eMEPBinding = aPMode.getMEPBinding();
if ((eMEP == EMEP.ONE_WAY && eMEPBinding == EMEPBinding.PUSH) || (eMEP == EMEP.TWO_WAY && eMEPBinding == EMEPBinding.PUSH_PUSH)) {
// Valid
} else {
aErrorList.add(_createError("An invalid combination of PMode MEP (" + eMEP + ") and MEP binding (" + eMEPBinding + ") was specified, valid are only one-way/push and two-way/push-push."));
}
// Leg1 must be present
final PModeLeg aPModeLeg1 = aPMode.getLeg1();
if (aPModeLeg1 == null) {
aErrorList.add(_createError("PMode.Leg[1] is missing"));
} else {
_checkIfLegIsValid(aErrorList, aPModeLeg1, "PMode.Leg[1].");
}
if (eMEP.isTwoWay()) {
final PModeLeg aPModeLeg2 = aPMode.getLeg2();
if (aPModeLeg2 == null) {
aErrorList.add(_createError("PMode.Leg[2] is missing as it specified as TWO-WAY"));
} else {
_checkIfLegIsValid(aErrorList, aPModeLeg2, "PMode.Leg[2].");
}
}
// Compression application/gzip ONLY
// other possible states are absent or "" (No input)
final PModePayloadService aPayloadService = aPMode.getPayloadService();
if (aPayloadService != null) {
final EAS4CompressionMode eCompressionMode = aPayloadService.getCompressionMode();
if (eCompressionMode != null) {
if (!eCompressionMode.equals(EAS4CompressionMode.GZIP))
aErrorList.add(_createError("PMode.PayloadService.CompressionMode must be " + EAS4CompressionMode.GZIP + " instead of " + eCompressionMode));
}
}
}
use of com.helger.phase4.attachment.EAS4CompressionMode in project phase4 by phax.
the class PModePayloadServiceJsonConverter method convertToNative.
@Nonnull
public static PModePayloadService convertToNative(@Nonnull final IJsonObject aElement) {
final String sCompressionModeID = aElement.getAsString(COMPRESSION_MODE);
final EAS4CompressionMode eCompressionMode = EAS4CompressionMode.getFromIDOrNull(sCompressionModeID);
if (sCompressionModeID != null && eCompressionMode == null)
throw new IllegalStateException("Invalid compression mode ID '" + sCompressionModeID + "' provided!");
return new PModePayloadService(eCompressionMode);
}
use of com.helger.phase4.attachment.EAS4CompressionMode in project phase4 by phax.
the class PModePayloadServiceMicroTypeConverter method convertToNative.
@Nonnull
public PModePayloadService convertToNative(@Nonnull final IMicroElement aElement) {
final String sCompressionModeID = aElement.getAttributeValue(ATTR_COMPRESSION_MODE);
final EAS4CompressionMode eCompressionMode = EAS4CompressionMode.getFromIDOrNull(sCompressionModeID);
if (sCompressionModeID != null && eCompressionMode == null)
throw new IllegalStateException("Invalid compression mode ID '" + sCompressionModeID + "' provided!");
return new PModePayloadService(eCompressionMode);
}
use of com.helger.phase4.attachment.EAS4CompressionMode in project phase4 by phax.
the class AS4IncomingHandler method _decompressAttachments.
private static void _decompressAttachments(@Nonnull final ICommonsList<WSS4JAttachment> aIncomingDecryptedAttachments, @Nonnull final Ebms3UserMessage aUserMessage, @Nonnull final IAS4MessageState aState) {
// For all incoming attachments
for (final WSS4JAttachment aIncomingAttachment : aIncomingDecryptedAttachments.getClone()) {
final EAS4CompressionMode eCompressionMode = aState.getAttachmentCompressionMode(aIncomingAttachment.getId());
if (eCompressionMode != null) {
final IHasInputStream aOldISP = aIncomingAttachment.getInputStreamProvider();
aIncomingAttachment.setSourceStreamProvider(new HasInputStream(() -> {
try {
final InputStream aSrcIS = aOldISP.getInputStream();
if (aSrcIS == null)
throw new IllegalStateException("Failed to create InputStream from " + aOldISP);
if (LOGGER.isDebugEnabled())
LOGGER.debug("Decompressing attachment with ID '" + aIncomingAttachment.getId() + "' using " + eCompressionMode);
return eCompressionMode.getDecompressStream(aSrcIS);
} catch (final IOException ex) {
// invalid payload
throw new AS4DecompressException(ex);
}
}, aOldISP.isReadMultiple()));
// Remember the compression mode
aIncomingAttachment.setCompressionMode(eCompressionMode);
final String sAttachmentContentID = StringHelper.trimStart(aIncomingAttachment.getId(), "attachment=");
// x.getHref() != null needed since, if a message contains a payload and
// an attachment, it would throw a NullPointerException since a payload
// does not have anything written in its partinfo therefore also now
// href
final Ebms3PartInfo aPartInfo = CollectionHelper.findFirst(aUserMessage.getPayloadInfo().getPartInfo(), x -> x.getHref() != null && x.getHref().contains(sAttachmentContentID));
if (aPartInfo != null && aPartInfo.getPartProperties() != null) {
// Find MimeType property
final Ebms3Property aProperty = CollectionHelper.findFirst(aPartInfo.getPartProperties().getProperty(), x -> x.getName().equalsIgnoreCase(MessageHelperMethods.PART_PROPERTY_MIME_TYPE));
if (aProperty != null) {
final String sMimeType = aProperty.getValue();
if (MimeTypeParser.safeParseMimeType(sMimeType) == null)
LOGGER.warn("Value '" + sMimeType + "' of property '" + MessageHelperMethods.PART_PROPERTY_MIME_TYPE + "' is not a valid MIME type");
aIncomingAttachment.overwriteMimeType(sMimeType);
}
}
}
}
}
Aggregations