Search in sources :

Example 1 with EMEPBinding

use of com.helger.phase4.model.EMEPBinding 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 EMEPBinding

use of com.helger.phase4.model.EMEPBinding 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 EMEPBinding

use of com.helger.phase4.model.EMEPBinding in project phase4 by phax.

the class PModeJsonConverter method convertToNative.

@Nonnull
public static PMode convertToNative(@Nonnull final IJsonObject aElement) {
    final IJsonObject aInit = aElement.getAsObject(ELEMENT_INITIATOR);
    final PModeParty aInitiator = aInit == null ? null : PModePartyJsonConverter.convertToNative(aInit);
    final IJsonObject aResp = aElement.getAsObject(ELEMENT_RESPONDER);
    final PModeParty aResponder = aResp == null ? null : PModePartyJsonConverter.convertToNative(aResp);
    final String sAgreement = aElement.getAsString(ATTR_AGREEMENT);
    final String sMEP = aElement.getAsString(ATTR_MEP);
    final EMEP eMEP = EMEP.getFromIDOrNull(sMEP);
    if (eMEP == null)
        throw new IllegalStateException("Failed to resolve MEP '" + sMEP + "'");
    final String sMEPBinding = aElement.getAsString(ATTR_MEP_BINDING);
    final EMEPBinding eMEPBinding = EMEPBinding.getFromIDOrNull(sMEPBinding);
    if (eMEPBinding == null)
        throw new IllegalStateException("Failed to resolve MEPBinding '" + sMEPBinding + "'");
    final IJsonObject aL1 = aElement.getAsObject(ELEMENT_LEG1);
    final PModeLeg aLeg1 = aL1 == null ? null : PModeLegJsonConverter.convertToNative(aL1);
    final IJsonObject aL2 = aElement.getAsObject(ELEMENT_LEG2);
    final PModeLeg aLeg2 = aL2 == null ? null : PModeLegJsonConverter.convertToNative(aL2);
    final IJsonObject aPS = aElement.getAsObject(ELEMENT_PAYLOADSERVICE);
    final PModePayloadService aPayloadService = aPS == null ? null : PModePayloadServiceJsonConverter.convertToNative(aPS);
    final IJsonObject aRA = aElement.getAsObject(ELEMENT_RECEPETIONAWARENESS);
    final PModeReceptionAwareness aReceptionAwareness = aRA == null ? null : PModeReceptionAwarenessJsonConverter.convertToNative(aRA);
    return new PMode(getStubObject(aElement), aInitiator, aResponder, sAgreement, eMEP, eMEPBinding, aLeg1, aLeg2, aPayloadService, aReceptionAwareness);
}
Also used : EMEPBinding(com.helger.phase4.model.EMEPBinding) EMEP(com.helger.phase4.model.EMEP) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) IJsonObject(com.helger.json.IJsonObject) Nonnull(javax.annotation.Nonnull)

Example 4 with EMEPBinding

use of com.helger.phase4.model.EMEPBinding in project phase4 by phax.

the class PullRequestTest method testSendPullRequestSuccessTwoWayPullPush.

@Test
public void testSendPullRequestSuccessTwoWayPullPush() throws Exception {
    // Depending on the payload a different EMEPBinding get chosen by
    // @MockPullRequestProcessorSPI
    // To Test the pull request part of the EMEPBinding
    final Document aPayload = DOMReader.readXMLDOM(new ClassPathResource("testfiles/PullPush.xml"));
    final ICommonsList<Object> aAny = new CommonsArrayList<>();
    aAny.add(aPayload.getDocumentElement());
    final Document aDoc = AS4PullRequestMessage.create(m_eSoapVersion, MessageHelperMethods.createEbms3MessageInfo(), AS4TestConstants.DEFAULT_MPC, aAny).getAsSoapDocument();
    final HttpEntity aEntity = new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType());
    final String sResponse = sendPlainMessageAndWait(aEntity, true, null);
    assertTrue(sResponse.contains(AS4TestConstants.USERMESSAGE_ASSERTCHECK));
}
Also used : HttpEntity(org.apache.http.HttpEntity) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Test(org.junit.Test)

Example 5 with EMEPBinding

use of com.helger.phase4.model.EMEPBinding in project phase4 by phax.

the class PModeMicroTypeConverter method convertToNative.

@Nonnull
public PMode convertToNative(@Nonnull final IMicroElement aElement) {
    final PModeParty aInitiator = MicroTypeConverter.convertToNative(aElement.getFirstChildElement(ELEMENT_INITIATOR), PModeParty.class);
    final PModeParty aResponder = MicroTypeConverter.convertToNative(aElement.getFirstChildElement(ELEMENT_RESPONDER), PModeParty.class);
    final String sAgreement = aElement.getAttributeValue(ATTR_AGREEMENT);
    final String sMEP = aElement.getAttributeValue(ATTR_MEP);
    final EMEP eMEP = EMEP.getFromIDOrNull(sMEP);
    if (eMEP == null)
        throw new IllegalStateException("Failed to resolve MEP '" + sMEP + "'");
    final String sMEPBinding = aElement.getAttributeValue(ATTR_MEP_BINDING);
    final EMEPBinding eMEPBinding = EMEPBinding.getFromIDOrNull(sMEPBinding);
    if (eMEPBinding == null)
        throw new IllegalStateException("Failed to resolve MEPBinding '" + sMEPBinding + "'");
    final PModeLeg aLeg1 = MicroTypeConverter.convertToNative(aElement.getFirstChildElement(ELEMENT_LEG1), PModeLeg.class);
    final PModeLeg aLeg2 = MicroTypeConverter.convertToNative(aElement.getFirstChildElement(ELEMENT_LEG2), PModeLeg.class);
    final PModePayloadService aPayloadService = MicroTypeConverter.convertToNative(aElement.getFirstChildElement(ELEMENT_PAYLOADSERVICE), PModePayloadService.class);
    final PModeReceptionAwareness aReceptionAwareness = MicroTypeConverter.convertToNative(aElement.getFirstChildElement(ELEMENT_RECEPETIONAWARENESS), PModeReceptionAwareness.class);
    return new PMode(getStubObject(aElement), aInitiator, aResponder, sAgreement, eMEP, eMEPBinding, aLeg1, aLeg2, aPayloadService, aReceptionAwareness);
}
Also used : EMEPBinding(com.helger.phase4.model.EMEPBinding) EMEP(com.helger.phase4.model.EMEP) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) Nonnull(javax.annotation.Nonnull)

Aggregations

EMEP (com.helger.phase4.model.EMEP)5 EMEPBinding (com.helger.phase4.model.EMEPBinding)5 PModeLeg (com.helger.phase4.model.pmode.leg.PModeLeg)5 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)4 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)4 HttpXMLEntity (com.helger.phase4.http.HttpXMLEntity)4 HttpEntity (org.apache.http.HttpEntity)4 Test (org.junit.Test)4 Document (org.w3c.dom.Document)4 EAS4CompressionMode (com.helger.phase4.attachment.EAS4CompressionMode)3 PModePayloadService (com.helger.phase4.model.pmode.PModePayloadService)3 PModeValidationException (com.helger.phase4.model.pmode.PModeValidationException)3 IAS4DuplicateManager (com.helger.phase4.duplicate.IAS4DuplicateManager)2 Nonnull (javax.annotation.Nonnull)2 NodeList (org.w3c.dom.NodeList)2 IJsonObject (com.helger.json.IJsonObject)1