Search in sources :

Example 51 with PModeLeg

use of com.helger.phase4.model.pmode.leg.PModeLeg 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 52 with PModeLeg

use of com.helger.phase4.model.pmode.leg.PModeLeg 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 53 with PModeLeg

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

the class TwoWayAsyncPullPushTest method before.

@Before
public void before() {
    final PMode aPMode = CEFPMode.createCEFPMode(AS4TestConstants.TEST_INITIATOR, AS4TestConstants.TEST_RESPONDER, MockJettySetup.getServerAddressFromSettings(), (i, r) -> "pmode" + GlobalIDFactory.getNewPersistentLongID(), false);
    // Setting second leg to the same as first
    final PModeLeg aLeg2 = aPMode.getLeg1();
    // ESENS PMode is One Way on default settings need to change to two way
    m_aPMode = new PMode(aPMode.getID(), PModeParty.createSimple(DEFAULT_PARTY_ID + "1", CAS4.DEFAULT_ROLE), PModeParty.createSimple(DEFAULT_PARTY_ID + "1", CAS4.DEFAULT_ROLE), aPMode.getAgreement(), EMEP.TWO_WAY, EMEPBinding.PULL_PUSH, aPMode.getLeg1(), aLeg2, aPMode.getPayloadService(), aPMode.getReceptionAwareness());
    // Delete old PMode since it is getting created in the ESENS createPMode
    MetaAS4Manager.getPModeMgr().deletePMode(aPMode.getID());
    MetaAS4Manager.getPModeMgr().createOrUpdatePMode(m_aPMode);
}
Also used : PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) PMode(com.helger.phase4.model.pmode.PMode) CEFPMode(com.helger.phase4.profile.cef.CEFPMode) Before(org.junit.Before)

Example 54 with PModeLeg

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

the class TwoWayMEPTest method before.

@Before
public void before() {
    final PMode aPMode = CEFPMode.createCEFPMode(AS4TestConstants.TEST_INITIATOR, AS4TestConstants.TEST_RESPONDER, MockJettySetup.getServerAddressFromSettings(), (i, r) -> "pmode" + GlobalIDFactory.getNewPersistentLongID(), false);
    // Setting second leg to the same as first
    final PModeLeg aLeg2 = aPMode.getLeg1();
    // ESENS PMode is One Way on default settings need to change to two way
    m_aPMode = new PMode(aPMode.getID(), PModeParty.createSimple(DEFAULT_PARTY_ID + "1", CAS4.DEFAULT_ROLE), PModeParty.createSimple(DEFAULT_PARTY_ID + "1", CAS4.DEFAULT_ROLE), aPMode.getAgreement(), EMEP.TWO_WAY, EMEPBinding.SYNC, aPMode.getLeg1(), aLeg2, aPMode.getPayloadService(), aPMode.getReceptionAwareness());
    // Delete old PMode since it is getting created in the ESENS createPMode
    MetaAS4Manager.getPModeMgr().deletePMode(aPMode.getID());
    MetaAS4Manager.getPModeMgr().createOrUpdatePMode(m_aPMode);
}
Also used : PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) PMode(com.helger.phase4.model.pmode.PMode) IPMode(com.helger.phase4.model.pmode.IPMode) CEFPMode(com.helger.phase4.profile.cef.CEFPMode) Before(org.junit.Before)

Example 55 with PModeLeg

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

the class AS4RequestHandler method _createResponseReceiptMessage.

/**
 * @param aState
 *        The processing state of the incoming message. Never
 *        <code>null</code>.
 * @param aSoapDocument
 *        document which should be used as source for the receipt to convert
 *        it to non-repudiation information. Can be <code>null</code>.
 * @param eSoapVersion
 *        SOAPVersion which should be used
 * @param aEffectiveLeg
 *        the leg that is used to determined, how the receipt should be build
 * @param aUserMessage
 *        used if no non-repudiation information is needed, prints the
 *        usermessage in receipt. Can be <code>null</code>.
 * @param aResponseAttachments
 *        that should be sent back if needed. Can be <code>null</code>.
 * @throws WSSecurityException
 */
@Nonnull
private IAS4ResponseFactory _createResponseReceiptMessage(@Nonnull final IAS4MessageState aState, @Nullable final Document aSoapDocument, @Nonnull final ESoapVersion eSoapVersion, @Nonnull @Nonempty final String sResponseMessageID, @Nonnull final PModeLeg aEffectiveLeg, @Nullable final Ebms3UserMessage aUserMessage, @Nullable final ICommonsList<WSS4JAttachment> aResponseAttachments) throws WSSecurityException {
    final AS4ReceiptMessage aReceiptMessage = AS4ReceiptMessage.create(eSoapVersion, sResponseMessageID, aUserMessage, aSoapDocument, _isSendNonRepudiationInformation(aEffectiveLeg)).setMustUnderstand(true);
    // We've got our response
    final Document aResponseDoc = aReceiptMessage.getAsSoapDocument();
    final AS4SigningParams aSigningParams = new AS4SigningParams().setFromPMode(aEffectiveLeg.getSecurity());
    final Document aSignedDoc = _signResponseIfNeeded(aResponseAttachments, aSigningParams, aResponseDoc, aEffectiveLeg.getProtocol().getSoapVersion(), aReceiptMessage.getMessagingID());
    return new AS4ResponseFactoryXML(m_aMessageMetadata, aState, sResponseMessageID, aSignedDoc, eSoapVersion.getMimeType());
}
Also used : AS4SigningParams(com.helger.phase4.crypto.AS4SigningParams) AS4ReceiptMessage(com.helger.phase4.messaging.domain.AS4ReceiptMessage) Document(org.w3c.dom.Document) Nonnull(javax.annotation.Nonnull)

Aggregations

PModeLeg (com.helger.phase4.model.pmode.leg.PModeLeg)99 PMode (com.helger.phase4.model.pmode.PMode)91 PModeLegSecurity (com.helger.phase4.model.pmode.leg.PModeLegSecurity)89 EMEP (com.helger.phase4.model.EMEP)88 EMEPBinding (com.helger.phase4.model.EMEPBinding)88 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)87 PModeLegErrorHandling (com.helger.phase4.model.pmode.leg.PModeLegErrorHandling)87 PModeLegProtocol (com.helger.phase4.model.pmode.leg.PModeLegProtocol)86 ESoapVersion (com.helger.phase4.soap.ESoapVersion)86 Before (org.junit.Before)86 Ebms3SignalMessage (com.helger.phase4.ebms3header.Ebms3SignalMessage)85 Locale (java.util.Locale)85 ErrorList (com.helger.commons.error.list.ErrorList)84 ECryptoAlgorithmSign (com.helger.phase4.crypto.ECryptoAlgorithmSign)84 ECryptoAlgorithmSignDigest (com.helger.phase4.crypto.ECryptoAlgorithmSignDigest)84 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)84 Ebms3PartyId (com.helger.phase4.ebms3header.Ebms3PartyId)84 Ignore (org.junit.Ignore)84 Test (org.junit.Test)84 ETriState (com.helger.commons.state.ETriState)83