Search in sources :

Example 36 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.

the class MainCEFeInvoicingConnectivityTest method main.

public static void main(final String[] args) {
    WebScopeManager.onGlobalBegin(MockServletContext.create());
    // Dump (for debugging purpose only)
    AS4DumpManager.setIncomingDumper(new AS4IncomingDumperFileBased());
    AS4DumpManager.setOutgoingDumper(new AS4OutgoingDumperFileBased());
    try (final WebScoped w = new WebScoped()) {
        // Read a UBL Invoice
        final byte[] aPayloadBytes = SimpleFileIO.getAllFileBytes(new File("src/test/resources/examples/base-example.xml"));
        if (aPayloadBytes == null)
            throw new IllegalStateException();
        final IAS4ClientBuildMessageCallback x1 = new IAS4ClientBuildMessageCallback() {

            public void onAS4Message(final AbstractAS4Message<?> aMsg) {
                final AS4UserMessage aUserMsg = (AS4UserMessage) aMsg;
                LOGGER.info("Sending out AS4 message with message ID '" + aUserMsg.getEbms3UserMessage().getMessageInfo().getMessageId() + "'");
                LOGGER.info("Sending out AS4 message with conversation ID '" + aUserMsg.getEbms3UserMessage().getCollaborationInfo().getConversationId() + "'");
            }

            public void onSoapDocument(@Nonnull final Document aDoc) {
                if (false)
                    LOGGER.info("SOAP Document:\n" + XMLWriter.getNodeAsString(aDoc, new XMLWriterSettings().setIndent(EXMLSerializeIndent.INDENT_AND_ALIGN)));
            }
        };
        // TODO The message ID to use in the UI
        final String sAS4MessageID = "36999089-662a-441f-95fd-470bec2b538e-100@phase4";
        final ESimpleUserMessageSendResult eRes = Phase4CEFSender.builder().cryptoFactory(CF).httpRetrySettings(new HttpRetrySettings().setMaxRetries(0)).action("TC1Leg1").service("tc1", "bdx:noprocess").senderParticipantID(new SimpleParticipantIdentifier("connectivity-partid-qns", YOUR_ID)).receiverParticipantID(new SimpleParticipantIdentifier("connectivity-partid-qns", "domibus-gitb")).fromPartyIDType("urn:oasis:names:tc:ebcore:partyid-type:unregistered").fromPartyID(YOUR_ID).fromRole(CAS4.DEFAULT_INITIATOR_URL).toPartyIDType("urn:oasis:names:tc:ebcore:partyid-type:unregistered").toPartyID("domibus-gitb").toRole(CAS4.DEFAULT_RESPONDER_URL).messageID(sAS4MessageID).payload(Phase4OutgoingAttachment.builder().data(aPayloadBytes).filename("businessContentPayload").compressionGZIP().mimeType(CMimeType.TEXT_XML).contentID("message").build()).buildMessageCallback(x1).endpointDetailProvider(new AS4EndpointDetailProviderConstant(CertificateHelper.convertStringToCertficateOrNull("-----BEGIN CERTIFICATE-----\r\n" + "MIIDOzCCAiOgAwIBAgIJAKbwaKpEwNTKMA0GCSqGSIb3DQEBCwUAMDQxDTALBgNV\r\n" + "BAoMBEdJVEIxDTALBgNVBAsMBEdJVEIxFDASBgNVBAMMC2dpdGItZW5naW5lMB4X\r\n" + "DTE0MTIyNDEzMjIzNFoXDTI0MTIyMTEzMjIzNFowNDENMAsGA1UECgwER0lUQjEN\r\n" + "MAsGA1UECwwER0lUQjEUMBIGA1UEAwwLZ2l0Yi1lbmdpbmUwggEiMA0GCSqGSIb3\r\n" + "DQEBAQUAA4IBDwAwggEKAoIBAQCpNuRRMhpd2SvNKsZe/WTxm4zuX2Zc5by3zGcm\r\n" + "uzwePdMCnCXk2FAUH67qS9r5VBa4USfiB7l1piyLrNwYWGRDo5OeWIz6Q821/1v7\r\n" + "UHq7FfB0LFPcJ+mOwrDqS+VL0MjcSW4pocJHrpFwObWHTY/R4WmW2xwGOKVh0OUL\r\n" + "UhqQsHDnDhCzFaEWhS8n1lUw3GRipwKLyYvXK8XgLceEmh+j0+cdmIj4a1L4oza/\r\n" + "UgBnCqSob+vowgClyZnGVihE9K8eLLwCSLlIiD+bXWf0VJPLXBNLdNIkRRC0QO0j\r\n" + "T9TuE5TF3SknkA5D0NFp023Alz7jieI0D6JE78QyNQN6y6QRAgMBAAGjUDBOMB0G\r\n" + "A1UdDgQWBBQpAkry20hAcvlw+4poxQC8TI+EgTAfBgNVHSMEGDAWgBQpAkry20hA\r\n" + "cvlw+4poxQC8TI+EgTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBS\r\n" + "dfmT3E9uvhiEgVefdwXkkxqlXLQQxfjaqVRVzPTHLqdVs/nBK+iQNhqg+6eLcaGQ\r\n" + "yyDy88vwQ85rqwOFbZd05esIFXYl0pgl1pVsb7HmMNmKT3UPay3HDlHX45ZoexDU\r\n" + "pza4OcrauEM8Yg/5i9dCIPC1GiHebJpYusMVfP78b+5DAyARrHtcb0EJ8rOLxHh6\r\n" + "K2S4EHI6sqQkGHEt1z4m66LyK+vnkLGaq3y6MWEufh78eICDyyVz0DhdIhr18ZHX\r\n" + "dpcsH2VOkE36KnWSo0spEXa6ZtP8MqQ60kJgBt4XcuArKfjIGC6vB6dE0NzXngBD\r\n" + "PHgMfmHJW018/6eN/f0q\r\n" + "-----END CERTIFICATE-----"), "https://www.itb.ec.europa.eu/cef/domibus/services/msh")).sendMessageAndCheckForReceipt();
        LOGGER.info("Sending AS4 message to CEF with result " + eRes);
    } finally {
        WebScopeManager.onGlobalEnd();
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) XMLWriterSettings(com.helger.xml.serialize.write.XMLWriterSettings) Nonnull(javax.annotation.Nonnull) Document(org.w3c.dom.Document) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) HttpRetrySettings(com.helger.phase4.http.HttpRetrySettings) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4EndpointDetailProviderConstant(com.helger.phase4.dynamicdiscovery.AS4EndpointDetailProviderConstant) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased)

Example 37 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.

the class AS4CEFOneWayFuncTest method testAS4_TA13.

/**
 * 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 compressed but damaged payloads. The SMSH sends the AS4 User
 * Message to the RMSH.<br>
 * <br>
 * Predicate: <br>
 * The RMSH sends back a synchronous error response with error code "Code =
 * EBMS:0303, Short Description = DecompressionFailure, Severity = Failure,
 * Category = Communication".
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testAS4_TA13() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    final WSS4JAttachment aAttachment = WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML_XML)).mimeTypeXML().compressionGZIP().build(), s_aResMgr);
    aAttachment.setCharset(StandardCharsets.UTF_8);
    aAttachments.add(aAttachment);
    final AS4UserMessage aMsg = createTestUserMessageSoapNotSigned(m_aPayload, aAttachments);
    // Damaged payload: txt file
    aAttachments.get(0).setSourceStreamProvider(new ClassPathResource("attachment/CompressedPayload.txt"));
    final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, aMsg.getAsSoapDocument(m_aPayload), aAttachments);
    sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), false, EEbmsError.EBMS_DECOMPRESSION_FAILURE.getErrorCode());
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 38 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage 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 39 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.

the class AS4eSENSCEFOneWayFuncTest method testEsens_TA03.

/**
 * Prerequisite:<br>
 * SMSH and RMSH are configured to exchange AS4 messages according to the
 * e-SENS profile: One-Way/Push MEP. SMSH and RMSH exchange several AS4 User
 * Messages.<br>
 * <br>
 * Predicate: <br>
 * Each exchanged AS4 message contains single ORIGIN and DESTINATION elements.
 * <br>
 * Goal: "Both UserMessage/PartyInfo/From and UserMessage/PartyInfo/To must
 * not include more than one PartyId element"
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testEsens_TA03() 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);
    aEbms3PartyInfo.getTo().addPartyId(MessageHelperMethods.createEbms3PartyId("Second ID"));
    // Check if we added a second party id
    assertTrue(aEbms3PartyInfo.getTo().getPartyId().size() == 2);
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final Ebms3UserMessage aUserMessage = new Ebms3UserMessage();
    aUserMessage.setPartyInfo(aEbms3PartyInfo);
    aUserMessage.setCollaborationInfo(aEbms3CollaborationInfo);
    aUserMessage.setMessageProperties(aEbms3MessageProperties);
    aUserMessage.setPayloadInfo(aEbms3PayloadInfo);
    aUserMessage.setMessageInfo(aEbms3MessageInfo);
    final Document aDoc = new AS4UserMessage(ESoapVersion.AS4_DEFAULT, aUserMessage).getAsSoapDocument(m_aPayload);
    sendPlainMessage(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), false, EEbmsError.EBMS_VALUE_INCONSISTENT.getErrorCode());
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) 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 40 with AS4UserMessage

use of com.helger.phase4.messaging.domain.AS4UserMessage in project phase4 by phax.

the class AS4_NETFuncTest method testSendToAS4_NET.

@Test
public void testSendToAS4_NET() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML)).mimeTypeXML().build(), s_aResMgr));
    // New message ID
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(false, aAttachments);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(m_aESENSOneWayPMode.getID(), DEFAULT_AGREEMENT, COLLABORATION_INFO_SERVICE_TYPE, COLLABORATION_INFO_SERVICE, COLLABORATION_INFO_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, "phase4-sender", CAS4.DEFAULT_RESPONDER_URL, TO_PARTY_ID);
    // Add properties
    final ICommonsList<Ebms3Property> aEbms3Properties = new CommonsArrayList<>(MessageHelperMethods.createEbms3Property(CAS4.ORIGINAL_SENDER, null, "C1"), MessageHelperMethods.createEbms3Property(CAS4.FINAL_RECIPIENT, null, "C4"));
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property("trackingidentifier", "tracker"));
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final AS4UserMessage aUserMsg = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, m_eSoapVersion).setMustUnderstand(true);
    // Sign payload document
    final Document aSignedDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aUserMsg.getAsSoapDocument(), m_eSoapVersion, aUserMsg.getMessagingID(), aAttachments, s_aResMgr, false, AS4SigningParams.createDefault());
    final AS4MimeMessage aMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, aSignedDoc, aAttachments);
    sendMimeMessage(new HttpMimeMessageEntity(aMsg), true, null);
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Document(org.w3c.dom.Document) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Test(org.junit.Test)

Aggregations

AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)46 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)20 Document (org.w3c.dom.Document)20 Test (org.junit.Test)19 IAS4ClientBuildMessageCallback (com.helger.phase4.client.IAS4ClientBuildMessageCallback)17 AbstractAS4Message (com.helger.phase4.messaging.domain.AbstractAS4Message)17 AS4MimeMessage (com.helger.phase4.messaging.mime.AS4MimeMessage)17 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)16 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)16 AS4IncomingDumperFileBased (com.helger.phase4.dump.AS4IncomingDumperFileBased)16 AS4OutgoingDumperFileBased (com.helger.phase4.dump.AS4OutgoingDumperFileBased)16 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)16 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)16 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)16 Ebms3PayloadInfo (com.helger.phase4.ebms3header.Ebms3PayloadInfo)16 HttpMimeMessageEntity (com.helger.phase4.http.HttpMimeMessageEntity)16 ESimpleUserMessageSendResult (com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult)16 File (java.io.File)16 Nonnull (javax.annotation.Nonnull)16 Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)15