Search in sources :

Example 1 with IPModeManager

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

the class DefaultPModeResolver method getPModeOfID.

@Nullable
public IPMode getPModeOfID(@Nullable final String sPModeID, @Nonnull final String sService, @Nonnull final String sAction, @Nonnull @Nonempty final String sInitiatorID, @Nonnull @Nonempty final String sResponderID, @Nullable final String sAgreementRef, @Nullable final String sAddress) {
    final IPModeManager aPModeMgr = MetaAS4Manager.getPModeMgr();
    IPMode ret = null;
    if (StringHelper.hasText(sPModeID)) {
        // An ID is present - try to resolve this ID
        ret = aPModeMgr.getPModeOfID(sPModeID);
        if (ret != null)
            return ret;
    }
    // the PMode id field is empty or null (or invalid)
    // try a combination of service and action
    ret = aPModeMgr.getPModeOfServiceAndAction(sService, sAction);
    if (ret != null)
        return ret;
    // Use default pmode based on profile
    final IAS4Profile aProfile = MetaAS4Manager.getProfileMgr().getDefaultProfileOrNull();
    if (aProfile != null)
        return aProfile.createPModeTemplate(sInitiatorID, sResponderID, sAddress);
    if (!m_bUseDefaultAsFallback) {
        // Not found and no default -> null
        return null;
    }
    // 2. Default default PMode
    return DefaultPMode.getOrCreateDefaultPMode(sInitiatorID, sResponderID, sAddress, true);
}
Also used : IAS4Profile(com.helger.phase4.profile.IAS4Profile) IPModeManager(com.helger.phase4.model.pmode.IPModeManager) IPMode(com.helger.phase4.model.pmode.IPMode) Nullable(javax.annotation.Nullable)

Example 2 with IPModeManager

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

the class PModeCheckTest method testPModeWrongMPC.

@Test
public void testPModeWrongMPC() throws Exception {
    final PMode aPMode = MockPModeGenerator.getTestPMode(SOAP_VERSION);
    aPMode.getLeg1().getBusinessInfo().setMPCID("wrongmpc-id");
    final IPModeManager aPModeMgr = MetaAS4Manager.getPModeMgr();
    try {
        for (final String sPModeID : aPModeMgr.getAllIDs()) {
            aPModeMgr.deletePMode(sPModeID);
        }
        assertTrue(aPModeMgr.getAllIDs().isEmpty());
        aPModeMgr.createOrUpdatePMode(aPMode);
        // Needed since different ids set in message and pmode otherwise
        m_aEbms3UserMessage.setCollaborationInfo(MessageHelperMethods.createEbms3CollaborationInfo(aPMode.getInitiatorID() + "-" + aPMode.getResponderID(), DEFAULT_AGREEMENT, null, CAS4.DEFAULT_SERVICE_URL, CAS4.DEFAULT_ACTION_URL, AS4TestConstants.TEST_CONVERSATION_ID));
        final Document aSignedDoc = AS4UserMessage.create(SOAP_VERSION, m_aEbms3UserMessage).setMustUnderstand(true).getAsSoapDocument(m_aPayload);
        sendPlainMessageAndWait(new HttpXMLEntity(aSignedDoc, SOAP_VERSION.getMimeType()), false, EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getErrorCode());
    } finally {
        // The MockPModeGenerator generates automatically a PMode, we need
        // too delete it after we are done with the test
        MetaAS4Manager.getPModeMgr().deletePMode(aPMode.getID());
        aPModeMgr.deletePMode(aPMode.getID());
    }
}
Also used : IPModeManager(com.helger.phase4.model.pmode.IPModeManager) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) PMode(com.helger.phase4.model.pmode.PMode) Test(org.junit.Test)

Example 3 with IPModeManager

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

the class PModeCheckTest method testPModeLegProtocolAddressReject.

/**
 * Is ESENS specific, EBMS3 specification is the protocol an optional element.
 * Maybe refactoring into a test if http and SMTP addresses later on get
 * converted right
 *
 * @throws Exception
 *         In case of an error
 */
@Test
@Ignore("The PMode leg protocol address is curently not used, therefore the wrong address never pops up")
public void testPModeLegProtocolAddressReject() throws Exception {
    final String sInvalidPModeID = "pmode-" + GlobalIDFactory.getNewPersistentIntID();
    final PMode aPMode = MockPModeGenerator.getTestPMode(SOAP_VERSION);
    aPMode.setLeg1(new PModeLeg(PModeLegProtocol.createForDefaultSoapVersion("TestsimulationAddressWrong"), null, null, null, null));
    final IPModeManager aPModeMgr = MetaAS4Manager.getPModeMgr();
    try {
        aPModeMgr.createOrUpdatePMode(aPMode);
        final Wrapper<String> aMsgID = new Wrapper<>();
        final Document aDoc = modifyUserMessage(sInvalidPModeID, null, null, createDefaultProperties(), null, null, x -> aMsgID.set(x));
        final Document aSignedDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aDoc, SOAP_VERSION, aMsgID.get(), null, s_aResMgr, false, AS4SigningParams.createDefault());
        sendPlainMessageAndWait(new HttpXMLEntity(aSignedDoc, SOAP_VERSION.getMimeType()), false, EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getErrorCode());
    } finally {
        aPModeMgr.deletePMode(aPMode.getID());
    }
}
Also used : Wrapper(com.helger.commons.wrapper.Wrapper) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) IPModeManager(com.helger.phase4.model.pmode.IPModeManager) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) PMode(com.helger.phase4.model.pmode.PMode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with IPModeManager

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

the class MockPModeGenerator method ensureMockPModesArePresent.

public static void ensureMockPModesArePresent() {
    // Delete all in the correct order
    final IPModeManager aPModeMgr = MetaAS4Manager.getPModeMgr();
    for (final String sID : aPModeMgr.getAllIDs()) aPModeMgr.deletePMode(sID);
    // Create new one
    DefaultPMode.getOrCreateDefaultPMode(SOAP_11_PARTY_ID, SOAP_11_PARTY_ID, "http://test.mock11.org", true);
    DefaultPMode.getOrCreateDefaultPMode(SOAP_12_PARTY_ID, SOAP_12_PARTY_ID, "http://test.mock12.org", true);
    for (final ESoapVersion e : ESoapVersion.values()) aPModeMgr.createOrUpdatePMode(MockPModeGenerator.getTestPModeWithSecurity(e));
}
Also used : IPModeManager(com.helger.phase4.model.pmode.IPModeManager) ESoapVersion(com.helger.phase4.soap.ESoapVersion)

Example 5 with IPModeManager

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

the class PModeCheckTest method testPModeLegNullReject.

@Test
public void testPModeLegNullReject() throws Exception {
    final PMode aPMode = MockPModeGenerator.getTestPMode(SOAP_VERSION);
    aPMode.setLeg1(null);
    final IPModeManager aPModeMgr = MetaAS4Manager.getPModeMgr();
    // Needed since different ids set in message and pmode otherwise
    m_aEbms3UserMessage.setCollaborationInfo(MessageHelperMethods.createEbms3CollaborationInfo(aPMode.getInitiatorID() + "-" + aPMode.getResponderID(), DEFAULT_AGREEMENT, null, CAS4.DEFAULT_SERVICE_URL, CAS4.DEFAULT_ACTION_URL, AS4TestConstants.TEST_CONVERSATION_ID));
    try {
        for (final String sPModeID : aPModeMgr.getAllIDs()) {
            aPModeMgr.deletePMode(sPModeID);
        }
        assertTrue(aPModeMgr.getAllIDs().isEmpty());
        aPModeMgr.createOrUpdatePMode(aPMode);
        final AS4UserMessage aMsg = AS4UserMessage.create(SOAP_VERSION, m_aEbms3UserMessage).setMustUnderstand(true);
        final Document aSignedDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(m_aPayload), SOAP_VERSION, aMsg.getMessagingID(), null, s_aResMgr, false, AS4SigningParams.createDefault());
        sendPlainMessageAndWait(new HttpXMLEntity(aSignedDoc, SOAP_VERSION.getMimeType()), false, EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getErrorCode());
    } finally {
        // The MockPModeGenerator generates automatically a PMode, we need
        // too delete it after we are done with the test
        aPModeMgr.deletePMode(aPMode.getID());
    }
}
Also used : IPModeManager(com.helger.phase4.model.pmode.IPModeManager) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) PMode(com.helger.phase4.model.pmode.PMode) Test(org.junit.Test)

Aggregations

IPModeManager (com.helger.phase4.model.pmode.IPModeManager)5 HttpXMLEntity (com.helger.phase4.http.HttpXMLEntity)3 PMode (com.helger.phase4.model.pmode.PMode)3 Test (org.junit.Test)3 Document (org.w3c.dom.Document)3 Wrapper (com.helger.commons.wrapper.Wrapper)1 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)1 IPMode (com.helger.phase4.model.pmode.IPMode)1 PModeLeg (com.helger.phase4.model.pmode.leg.PModeLeg)1 IAS4Profile (com.helger.phase4.profile.IAS4Profile)1 ESoapVersion (com.helger.phase4.soap.ESoapVersion)1 Nullable (javax.annotation.Nullable)1 Ignore (org.junit.Ignore)1