Search in sources :

Example 26 with HttpXMLEntity

use of com.helger.phase4.http.HttpXMLEntity 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 27 with HttpXMLEntity

use of com.helger.phase4.http.HttpXMLEntity in project phase4 by phax.

the class PModeCheckTest method testWrongMPCShouldReturnFailure.

@Test
public void testWrongMPCShouldReturnFailure() throws Exception {
    m_aEbms3UserMessage.setMpc("http://random.com/testmpc");
    final Document aDoc = AS4UserMessage.create(SOAP_VERSION, m_aEbms3UserMessage).setMustUnderstand(true).getAsSoapDocument(m_aPayload);
    sendPlainMessageAndWait(new HttpXMLEntity(aDoc, SOAP_VERSION.getMimeType()), false, EEbmsError.EBMS_VALUE_INCONSISTENT.getErrorCode());
}
Also used : HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 28 with HttpXMLEntity

use of com.helger.phase4.http.HttpXMLEntity 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 29 with HttpXMLEntity

use of com.helger.phase4.http.HttpXMLEntity in project phase4 by phax.

the class PModeCheckTest method testUserMessageMissingProperties.

@Test
public void testUserMessageMissingProperties() throws Exception {
    m_aEbms3UserMessage.setMessageProperties(null);
    final Document aDoc = AS4UserMessage.create(SOAP_VERSION, m_aEbms3UserMessage).setMustUnderstand(true).getAsSoapDocument(m_aPayload);
    sendPlainMessageAndWait(new HttpXMLEntity(aDoc, SOAP_VERSION.getMimeType()), false, "");
}
Also used : HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 30 with HttpXMLEntity

use of com.helger.phase4.http.HttpXMLEntity in project phase4 by phax.

the class PModeCheckTest method testNoResponderInMessageInvalidShouldReturnErrorMessage.

@Test
public void testNoResponderInMessageInvalidShouldReturnErrorMessage() throws Exception {
    final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    // never forget this!
    domFactory.setNamespaceAware(true);
    final DocumentBuilder builder = domFactory.newDocumentBuilder();
    final Document aDoc = builder.parse(new ClassPathResource("testfiles/NoResponder.xml").getInputStream());
    sendPlainMessageAndWait(new HttpXMLEntity(aDoc, SOAP_VERSION.getMimeType()), false, EEbmsError.EBMS_INVALID_HEADER.getErrorCode());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Aggregations

HttpXMLEntity (com.helger.phase4.http.HttpXMLEntity)65 Document (org.w3c.dom.Document)61 Test (org.junit.Test)60 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)30 Node (org.w3c.dom.Node)18 HttpEntity (org.apache.http.HttpEntity)16 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)10 NodeList (org.w3c.dom.NodeList)10 Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)9 Ebms3Property (com.helger.phase4.ebms3header.Ebms3Property)8 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)7 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)7 Ebms3PayloadInfo (com.helger.phase4.ebms3header.Ebms3PayloadInfo)7 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)7 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)6 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)6 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)5 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)5 IAS4CryptoFactory (com.helger.phase4.crypto.IAS4CryptoFactory)4