Search in sources :

Example 6 with EMEPBinding

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

the class ENTSOGCompatibilityValidator 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 (aPMode.getLeg2() != null) {
        aErrorList.add(_createError("PMode.Leg[2] must not be present"));
    }
    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));
        } else {
            aErrorList.add(_createError("PMode.PayloadService.CompressionMode is missing"));
        }
    } else {
        aErrorList.add(_createError("PMode.PayloadService is missing"));
    }
}
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 7 with EMEPBinding

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

the class PullRequestTest method testSendPullRequestSuccessTwoWayPushPull.

@Test
public void testSendPullRequestSuccessTwoWayPushPull() 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/PushPull.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 8 with EMEPBinding

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

the class TwoWayAsyncPullPushTest method testPullPushSuccess.

@Test
public void testPullPushSuccess() throws Exception {
    // Needs to be cleared so we can exactly see if two messages are contained
    // in the duplicate manager
    final IAS4DuplicateManager aIncomingDuplicateMgr = MetaAS4Manager.getIncomingDuplicateMgr();
    aIncomingDuplicateMgr.clearCache();
    assertTrue(aIncomingDuplicateMgr.isEmpty());
    // 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());
    // add the ID from the usermessage since its still one async message
    // transfer
    Document aDoc = AS4PullRequestMessage.create(m_eSoapVersion, MessageHelperMethods.createEbms3MessageInfo(), AS4TestConstants.DEFAULT_MPC, aAny).getAsSoapDocument();
    final HttpEntity aEntity = new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType());
    String sResponse = sendPlainMessageAndWait(aEntity, true, null);
    // Avoid stopping server to receive async response
    LOGGER.info("Waiting for 1 second");
    ThreadHelper.sleepSeconds(1);
    final NodeList nPullList = aDoc.getElementsByTagName("eb:MessageId");
    // Should only be called once
    final String aPullID = nPullList.item(0).getTextContent();
    aDoc = modifyUserMessage(m_aPMode.getID(), null, null, createDefaultProperties(), null, aPullID, null);
    sResponse = sendPlainMessageAndWait(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), true, null);
    final NodeList nList = aDoc.getElementsByTagName("eb:MessageId");
    // Should only be called once
    final String sID = nList.item(0).getTextContent();
    // Step one assertion for final the sync part
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains("<eb:RefToMessageId>" + sID));
    assertNotNull(aIncomingDuplicateMgr.getItemOfMessageID(sID));
    // Pull => First UserMsg, Push part second UserMsg
    assertEquals(2, aIncomingDuplicateMgr.getAll().size());
}
Also used : IAS4DuplicateManager(com.helger.phase4.duplicate.IAS4DuplicateManager) HttpEntity(org.apache.http.HttpEntity) NodeList(org.w3c.dom.NodeList) 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 9 with EMEPBinding

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

the class TwoWayAsyncPushPullTest method testPushPullSuccess.

@Test
public void testPushPullSuccess() throws Exception {
    // Needs to be cleared so we can exactly see if two messages are contained
    // in the duplicate manager
    final IAS4DuplicateManager aIncomingDuplicateMgr = MetaAS4Manager.getIncomingDuplicateMgr();
    aIncomingDuplicateMgr.clearCache();
    assertTrue(aIncomingDuplicateMgr.isEmpty());
    Document aDoc = modifyUserMessage(m_aPMode.getID(), null, null, createDefaultProperties(), null, null, null);
    String sResponse = sendPlainMessageAndWait(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), true, null);
    // Avoid stopping server to receive async response
    LOGGER.info("Waiting for 1 second");
    ThreadHelper.sleepSeconds(1);
    // Step one assertion for the sync part
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    final NodeList nList = aDoc.getElementsByTagName("eb:MessageId");
    // Should only be called once
    final String sID = nList.item(0).getTextContent();
    assertNotNull(aIncomingDuplicateMgr.getItemOfMessageID(sID));
    assertEquals(1, aIncomingDuplicateMgr.size());
    assertTrue(sResponse.contains("<eb:RefToMessageId>" + sID));
    // 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/PushPull.xml"));
    final ICommonsList<Object> aAny = new CommonsArrayList<>();
    aAny.add(aPayload.getDocumentElement());
    // add the ID from the usermessage since its still one async message
    // transfer
    aDoc = AS4PullRequestMessage.create(m_eSoapVersion, MessageHelperMethods.createEbms3MessageInfo(sID), AS4TestConstants.DEFAULT_MPC, aAny).getAsSoapDocument();
    final HttpEntity aEntity = new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType());
    sResponse = sendPlainMessageAndWait(aEntity, true, null);
    final NodeList nUserList = aDoc.getElementsByTagName("eb:MessageId");
    // Should only be called once
    final String aUserMsgID = nUserList.item(0).getTextContent();
    assertTrue(sResponse.contains(aUserMsgID));
}
Also used : IAS4DuplicateManager(com.helger.phase4.duplicate.IAS4DuplicateManager) HttpEntity(org.apache.http.HttpEntity) NodeList(org.w3c.dom.NodeList) 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)

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