Search in sources :

Example 1 with PMode

use of com.helger.phase4.model.pmode.PMode in project phase4 by phax.

the class ENTSOGPMode method createENTSOGPMode.

/**
 * One-Way Version of the CEF pmode uses one-way push
 *
 * @param sInitiatorID
 *        Initiator ID
 * @param sResponderID
 *        Responder ID
 * @param sResponderAddress
 *        Responder URL
 * @param aPModeIDProvider
 *        PMode ID provider
 * @param bPersist
 *        <code>true</code> to persist the PMode in the PModeManager,
 *        <code>false</code> to have it only in memory.
 * @return New PMode
 */
@Nonnull
public static PMode createENTSOGPMode(@Nonnull @Nonempty final String sInitiatorID, @Nonnull @Nonempty final String sResponderID, @Nullable final String sResponderAddress, @Nonnull final IPModeIDProvider aPModeIDProvider, final boolean bPersist) {
    final PModeParty aInitiator = new PModeParty(ENTSOG_PARTY_ID_TYPE, sInitiatorID, CAS4.DEFAULT_INITIATOR_URL, null, null);
    final PModeParty aResponder = new PModeParty(ENTSOG_PARTY_ID_TYPE, sResponderID, CAS4.DEFAULT_RESPONDER_URL, null, null);
    final PMode aPMode = new PMode(aPModeIDProvider.getPModeID(sInitiatorID, sResponderID), aInitiator, aResponder, DEFAULT_AGREEMENT_ID, EMEP.ONE_WAY, EMEPBinding.PUSH, generatePModeLeg(sResponderAddress), (PModeLeg) null, generatePModePayloadSevice(), generatePModeReceptionAwareness());
    if (bPersist) {
        // Ensure it is stored
        MetaAS4Manager.getPModeMgr().createOrUpdatePMode(aPMode);
    }
    return aPMode;
}
Also used : PModeParty(com.helger.phase4.model.pmode.PModeParty) PMode(com.helger.phase4.model.pmode.PMode) Nonnull(javax.annotation.Nonnull)

Example 2 with PMode

use of com.helger.phase4.model.pmode.PMode in project phase4 by phax.

the class ENTSOGPModeTest method testENTSOGPMode.

@Test
public void testENTSOGPMode() {
    final PMode aPMode = ENTSOGPMode.createENTSOGPMode("TestInitiator", "TestResponder", "https://test.example.org", IPModeIDProvider.DEFAULT_DYNAMIC, false);
    assertNotNull(aPMode);
}
Also used : PMode(com.helger.phase4.model.pmode.PMode) Test(org.junit.Test)

Example 3 with PMode

use of com.helger.phase4.model.pmode.PMode 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 4 with PMode

use of com.helger.phase4.model.pmode.PMode in project phase4 by phax.

the class PeppolPMode method createPeppolPMode.

/**
 * One-Way Version of the PEPPOL pmode uses one-way push
 *
 * @param sInitiatorID
 *        Initiator ID. May neither be <code>null</code> nor empty.
 * @param sResponderID
 *        Responder ID. May neither be <code>null</code> nor empty.
 * @param sAddress
 *        Endpoint address URL. May be <code>null</code>.
 * @param aPModeIDProvider
 *        PMode ID provider. May not be <code>null</code>.
 * @param bPersist
 *        <code>true</code> to persist the PMode in the PModeManager,
 *        <code>false</code> to have it only in memory.
 * @return New PMode and never <code>null</code>.
 */
@Nonnull
public static PMode createPeppolPMode(@Nonnull @Nonempty final String sInitiatorID, @Nonnull @Nonempty final String sResponderID, @Nullable final String sAddress, @Nonnull final IPModeIDProvider aPModeIDProvider, final boolean bPersist) {
    final PModeParty aInitiator = createParty(sInitiatorID, CAS4.DEFAULT_INITIATOR_URL);
    final PModeParty aResponder = createParty(sResponderID, CAS4.DEFAULT_RESPONDER_URL);
    final PMode aPMode = new PMode(aPModeIDProvider.getPModeID(sInitiatorID, sResponderID), aInitiator, aResponder, DEFAULT_AGREEMENT_ID, EMEP.ONE_WAY, EMEPBinding.PUSH, generatePModeLeg(sAddress), (PModeLeg) null, (PModePayloadService) null, generatePModeReceptionAwareness());
    if (bPersist) {
        // Ensure it is stored
        MetaAS4Manager.getPModeMgr().createOrUpdatePMode(aPMode);
    }
    return aPMode;
}
Also used : PModeParty(com.helger.phase4.model.pmode.PModeParty) PMode(com.helger.phase4.model.pmode.PMode) Nonnull(javax.annotation.Nonnull)

Example 5 with PMode

use of com.helger.phase4.model.pmode.PMode 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)

Aggregations

Nonnull (javax.annotation.Nonnull)17 PModeLeg (com.helger.phase4.model.pmode.leg.PModeLeg)15 PMode (com.helger.phase4.model.pmode.PMode)13 Document (org.w3c.dom.Document)9 IPMode (com.helger.phase4.model.pmode.IPMode)8 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)6 Test (org.junit.Test)6 EAS4CompressionMode (com.helger.phase4.attachment.EAS4CompressionMode)5 Ebms3Property (com.helger.phase4.ebms3header.Ebms3Property)5 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)5 EMEP (com.helger.phase4.model.EMEP)5 EMEPBinding (com.helger.phase4.model.EMEPBinding)5 PModeParty (com.helger.phase4.model.pmode.PModeParty)5 Phase4Exception (com.helger.phase4.util.Phase4Exception)5 AS4DecompressException (com.helger.phase4.attachment.AS4DecompressException)4 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)4 Ebms3Error (com.helger.phase4.ebms3header.Ebms3Error)4 HttpXMLEntity (com.helger.phase4.http.HttpXMLEntity)4 IOException (java.io.IOException)4 Nullable (javax.annotation.Nullable)4