Search in sources :

Example 41 with HttpXMLEntity

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

the class UserMessageDuplicateTest method testSendDuplicateMessageTestDisposalFeature.

@Test
@Ignore("Only use if you need to test the feature, takes a long time")
public void testSendDuplicateMessageTestDisposalFeature() throws Exception {
    final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
    final Document aDoc = MockMessages.createUserMessageNotSigned(m_eSoapVersion, aPayload, null).getAsSoapDocument(aPayload);
    final HttpEntity aEntity = new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType());
    sendPlainMessageAndWait(aEntity, true, null);
    // Making sure the message gets disposed off
    // 60 000 = 1 minute, *2 and + 10000 are a buffer
    // test file is configured for 1 minute can take LONGER if configured
    // differently
    ThreadHelper.sleep(AS4Configuration.getIncomingDuplicateDisposalMinutes() * CGlobal.MILLISECONDS_PER_MINUTE * 2 + 10 * CGlobal.MILLISECONDS_PER_SECOND);
    sendPlainMessageAndWait(aEntity, true, null);
}
Also used : HttpEntity(org.apache.http.HttpEntity) Node(org.w3c.dom.Node) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 42 with HttpXMLEntity

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

the class AS4ClientErrorMessage method buildMessage.

@Override
public AS4ClientBuiltMessage buildMessage(@Nonnull @Nonempty final String sMessageID, @Nullable final IAS4ClientBuildMessageCallback aCallback) throws IOException {
    _checkMandatoryAttributes();
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo(sMessageID, getRefToMessageID(), getSendingDateTimeOrNow());
    final AS4ErrorMessage aErrorMsg = AS4ErrorMessage.create(getSoapVersion(), aEbms3MessageInfo, m_aErrorMessages);
    if (aCallback != null)
        aCallback.onAS4Message(aErrorMsg);
    final Document aDoc = aErrorMsg.getAsSoapDocument();
    if (aCallback != null)
        aCallback.onSoapDocument(aDoc);
    // Wrap SOAP XML
    return new AS4ClientBuiltMessage(sMessageID, new HttpXMLEntity(aDoc, getSoapVersion().getMimeType()));
}
Also used : HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) AS4ErrorMessage(com.helger.phase4.messaging.domain.AS4ErrorMessage)

Example 43 with HttpXMLEntity

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

the class AS4CEFTwoWayFuncTest method testAS4_TA02.

/**
 * Prerequisite:<br>
 * SMSH and RMSH are configured to exchange AS4 messages according to the
 * e-SENS profile: Two-Way/Push-and-Push MEP. SMSH sends an AS4 User Message
 * (M1 with ID MessageId) that requires a consumer response to the RMSH.
 * Additionally, the message is associated to a specific conversation through
 * variable (element) CONVERSATIONIDM1 (set by the producer). The consumer
 * replies to the message M1.<br>
 * <br>
 * Predicate: <br>
 * The RMSH sends back a User Message (M2) with element REFTOMESSAGEID set to
 * MESSAGEID (of M1) and with element CONVERSATIONIDM2 equal to
 * ConversationIdM1.
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testAS4_TA02() 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());
    final Document aDoc = testSignedUserMessage(m_eSoapVersion, m_aPayload, null, s_aResMgr);
    final 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);
    final NodeList aNL = aDoc.getElementsByTagName("eb:MessageId");
    // Should only be called once
    final String aID = aNL.item(0).getTextContent();
    assertTrue(sResponse.contains("eb:RefToMessageId"));
    assertTrue(sResponse.contains(aID));
    assertNotNull(aIncomingDuplicateMgr.getItemOfMessageID(aID));
    assertEquals(2, aIncomingDuplicateMgr.getAll().size());
}
Also used : IAS4DuplicateManager(com.helger.phase4.duplicate.IAS4DuplicateManager) NodeList(org.w3c.dom.NodeList) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 44 with HttpXMLEntity

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

the class AS4eSENSCEFOneWayFuncTest method testEsens_TA20.

/**
 * Prerequisite:<br>
 * SMSH and RMSH are configured to exchange AS4 messages according to the
 * e-SENS profile: One-Way/Push MEP. SMSH sends an AS4 User Message including
 * a TRACKINGIDENTIFIER property set by the producer.<br>
 * <br>
 * Predicate: <br>
 * The RMSH returns a non-repudiation receipt within a HTTP response with
 * status code 2XX and the received AS4 message contains the
 * TRACKINGIDENTIFIER property.
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testEsens_TA20() throws Exception {
    // Add properties
    final ICommonsList<Ebms3Property> aEbms3Properties = AS4TestConstants.getEBMSProperties();
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(m_aPayload != null, null);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo;
    final Ebms3PartyInfo aEbms3PartyInfo;
    aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(m_aESENSOneWayPMode.getID(), DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, MockPModeGenerator.SOAP11_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
    aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, AS4TestConstants.CEF_INITIATOR_ID, CAS4.DEFAULT_RESPONDER_URL, AS4TestConstants.CEF_RESPONDER_ID);
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final String sTrackerIdentifier = "trackingidentifier";
    aEbms3MessageProperties.addProperty(MessageHelperMethods.createEbms3Property(sTrackerIdentifier, "tracker"));
    final AS4UserMessage aDoc = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, m_eSoapVersion).setMustUnderstand(true);
    final Document aSignedDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aDoc.getAsSoapDocument(m_aPayload), m_eSoapVersion, aDoc.getMessagingID(), null, s_aResMgr, false, AS4SigningParams.createDefault());
    final NodeList aNL = aSignedDoc.getElementsByTagName("eb:MessageProperties");
    assertEquals(aNL.item(0).getLastChild().getAttributes().getNamedItem("name").getTextContent(), sTrackerIdentifier);
    final String sResponse = sendPlainMessage(new HttpXMLEntity(aSignedDoc, m_eSoapVersion.getMimeType()), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.NON_REPUDIATION_INFORMATION));
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) NodeList(org.w3c.dom.NodeList) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Test(org.junit.Test)

Example 45 with HttpXMLEntity

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

the class AS4eSENSCEFOneWayFuncTest method testEsens_TA09.

/**
 * Prerequisite:<br>
 * SMSH and RMSH are configured to exchange AS4 messages according to the
 * e-SENS profile (One-Way/Push MEP). SMSH is simulated to send an AS4 user
 * message with a payload hyperlink reference.<br>
 * <br>
 * Predicate: <br>
 * The RMSH sends back a synchronous ebMS error message.
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testEsens_TA09() throws Exception {
    // Would throw an error in our implementation since the user would have said
    // there is a payload (With the hyperlink reference) but nothing is
    // attached.
    final DocumentBuilderFactory aDbfac = DocumentBuilderFactory.newInstance();
    final DocumentBuilder aDocBuilder = aDbfac.newDocumentBuilder();
    final Document aDoc = aDocBuilder.parse(ClassPathResource.getAsFile("attachment/HyperlinkPayload.xml"));
    sendPlainMessage(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), false, EEbmsError.EBMS_EXTERNAL_PAYLOAD_ERROR.getErrorCode());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) 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