Search in sources :

Example 1 with EAS4CompressionMode

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));
        }
    }
}
Also used : PModeValidationException(com.helger.phase4.model.pmode.PModeValidationException) EMEPBinding(com.helger.phase4.model.EMEPBinding) EMEP(com.helger.phase4.model.EMEP) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) EAS4CompressionMode(com.helger.phase4.attachment.EAS4CompressionMode) PModePayloadService(com.helger.phase4.model.pmode.PModePayloadService)

Example 2 with EAS4CompressionMode

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));
        }
    }
}
Also used : PModeValidationException(com.helger.phase4.model.pmode.PModeValidationException) EMEPBinding(com.helger.phase4.model.EMEPBinding) EMEP(com.helger.phase4.model.EMEP) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) EAS4CompressionMode(com.helger.phase4.attachment.EAS4CompressionMode) PModePayloadService(com.helger.phase4.model.pmode.PModePayloadService)

Example 3 with EAS4CompressionMode

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);
}
Also used : EAS4CompressionMode(com.helger.phase4.attachment.EAS4CompressionMode) Nonnull(javax.annotation.Nonnull)

Example 4 with EAS4CompressionMode

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);
}
Also used : EAS4CompressionMode(com.helger.phase4.attachment.EAS4CompressionMode) Nonnull(javax.annotation.Nonnull)

Example 5 with EAS4CompressionMode

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);
                }
            }
        }
    }
}
Also used : HasInputStream(com.helger.commons.io.stream.HasInputStream) IHasInputStream(com.helger.commons.io.IHasInputStream) AS4DecompressException(com.helger.phase4.attachment.AS4DecompressException) MultipartItemInputStream(com.helger.web.multipart.MultipartStream.MultipartItemInputStream) NonBlockingByteArrayInputStream(com.helger.commons.io.stream.NonBlockingByteArrayInputStream) HasInputStream(com.helger.commons.io.stream.HasInputStream) IHasInputStream(com.helger.commons.io.IHasInputStream) InputStream(java.io.InputStream) IHasInputStream(com.helger.commons.io.IHasInputStream) EAS4CompressionMode(com.helger.phase4.attachment.EAS4CompressionMode) IOException(java.io.IOException) Ebms3PartInfo(com.helger.phase4.ebms3header.Ebms3PartInfo) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property)

Aggregations

EAS4CompressionMode (com.helger.phase4.attachment.EAS4CompressionMode)7 PModeLeg (com.helger.phase4.model.pmode.leg.PModeLeg)4 EMEP (com.helger.phase4.model.EMEP)3 EMEPBinding (com.helger.phase4.model.EMEPBinding)3 PModePayloadService (com.helger.phase4.model.pmode.PModePayloadService)3 PModeValidationException (com.helger.phase4.model.pmode.PModeValidationException)3 Nonnull (javax.annotation.Nonnull)3 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)2 Ebms3PartInfo (com.helger.phase4.ebms3header.Ebms3PartInfo)2 Ebms3Property (com.helger.phase4.ebms3header.Ebms3Property)2 CommonsHashMap (com.helger.commons.collection.impl.CommonsHashMap)1 IError (com.helger.commons.error.IError)1 IHasInputStream (com.helger.commons.io.IHasInputStream)1 HasInputStream (com.helger.commons.io.stream.HasInputStream)1 NonBlockingByteArrayInputStream (com.helger.commons.io.stream.NonBlockingByteArrayInputStream)1 CollectingValidationEventHandler (com.helger.jaxb.validation.CollectingValidationEventHandler)1 AS4DecompressException (com.helger.phase4.attachment.AS4DecompressException)1 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)1 Ebms3Error (com.helger.phase4.ebms3header.Ebms3Error)1 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)1