Search in sources :

Example 1 with AS4UserMessage

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

the class MainPhase4CEFSenderToop 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()) {
        final byte[] aPayloadBytes = SimpleFileIO.getAllFileBytes(new File("src/test/resources/examples/base-example.xml"));
        if (aPayloadBytes == null)
            throw new IllegalStateException();
        // Start configuring here
        final IParticipantIdentifier aReceiverID = Phase4CEFSender.IF.createParticipantIdentifier("iso6523-actorid-upis", "9915:tooptest");
        final IAS4ClientBuildMessageCallback aBuildMessageCallback = 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() + "'");
            }
        };
        if (Phase4CEFSender.builder().documentTypeID(Phase4CEFSender.IF.createDocumentTypeIdentifier("toop-doctypeid-qns", "urn:eu:toop:ns:dataexchange-1p40::Response##urn:eu.toop.response.registeredorganization::1.40")).processID(Phase4CEFSender.IF.createProcessIdentifier("toop-procid-agreement", "urn:eu.toop.process.datarequestresponse")).senderParticipantID(Phase4CEFSender.IF.createParticipantIdentifier("iso6523-actorid-upis", "9914:phase4-test-sender")).receiverParticipantID(aReceiverID).fromPartyID(new SimpleParticipantIdentifier("type", "POP000306")).fromRole("http://www.toop.eu/edelivery/gateway").toPartyID(new SimpleParticipantIdentifier("type", "POP000306")).toRole("http://www.toop.eu/edelivery/gateway").payload(Phase4OutgoingAttachment.builder().data(aPayloadBytes).mimeTypeXML()).smpClient(new BDXRClientReadOnly(Phase4CEFSender.URL_PROVIDER, aReceiverID, SML_TOOP)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).buildMessageCallback(aBuildMessageCallback).sendMessage().isSuccess()) {
            LOGGER.info("Successfully sent CEF message via AS4");
        } else {
            LOGGER.error("Failed to send CEF message via AS4");
        }
    } catch (final Exception ex) {
        LOGGER.error("Error sending CEF message via AS4", ex);
    } finally {
        WebScopeManager.onGlobalEnd();
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) BDXRClientReadOnly(com.helger.smpclient.bdxr1.BDXRClientReadOnly) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 2 with AS4UserMessage

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

the class AS4CEFOneWayFuncTest method testAS4_TA20.

/**
 * Prerequisite:<br>
 * eSENS_TA14.<br>
 * Simulated SMSH sends a signed AS4 User Message with an encrypted first,
 * then compressed payload to the RMSH.<br>
 * <br>
 * Predicate: <br>
 * The SMSH receives a WS-Security SOAP Fault.
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testAS4_TA20() throws Exception {
    final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned(m_eSoapVersion, m_aPayload, null);
    final Document aDoc = AS4Encryptor.encryptSoapBodyPayload(m_aCryptoFactory, m_eSoapVersion, aMsg.getAsSoapDocument(m_aPayload), true, m_aCryptParams);
    final NodeList aNL = aDoc.getElementsByTagName("S12:Body");
    final NonBlockingByteArrayOutputStream outputStream = new NonBlockingByteArrayOutputStream();
    final Source xmlSource = new DOMSource(aNL.item(0));
    final Result outputTarget = new StreamResult(outputStream);
    TransformerFactory.newInstance().newTransformer().transform(xmlSource, outputTarget);
    final byte[] aSrc = outputStream.toByteArray();
    // Compression
    final NonBlockingByteArrayOutputStream aCompressedOS = new NonBlockingByteArrayOutputStream();
    try (final InputStream aIS = new NonBlockingByteArrayInputStream(aSrc);
        final OutputStream aOS = EAS4CompressionMode.GZIP.getCompressStream(aCompressedOS)) {
        StreamHelper.copyInputStreamToOutputStream(aIS, aOS);
    }
    aNL.item(0).setTextContent(AS4XMLHelper.serializeXML(aDoc));
    sendPlainMessage(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), false, EEbmsError.EBMS_FAILED_DECRYPTION.getErrorCode());
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) StreamResult(javax.xml.transform.stream.StreamResult) NonBlockingByteArrayInputStream(com.helger.commons.io.stream.NonBlockingByteArrayInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) NonBlockingByteArrayOutputStream(com.helger.commons.io.stream.NonBlockingByteArrayOutputStream) OutputStream(java.io.OutputStream) NonBlockingByteArrayOutputStream(com.helger.commons.io.stream.NonBlockingByteArrayOutputStream) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result) NonBlockingByteArrayInputStream(com.helger.commons.io.stream.NonBlockingByteArrayInputStream) Test(org.junit.Test)

Example 3 with AS4UserMessage

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

the class AS4CEFOneWayFuncTest method testAS4_TA19.

/**
 * Prerequisite:<br>
 * eSENS_TA14.<br>
 * The SMSH is simulated to send a compressed then encrypted AS4 message to
 * the RMSH.<br>
 * <br>
 * Predicate: <br>
 * The RMSH sends back an AS4 non-repudiation receipt.
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testAS4_TA19() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML_XML)).mimeTypeXML().build(), s_aResMgr));
    final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned(m_eSoapVersion, null, aAttachments);
    final AS4MimeMessage aMimeMsg = AS4Encryptor.encryptMimeMessage(m_eSoapVersion, aMsg.getAsSoapDocument(), aAttachments, m_aCryptoFactory, false, s_aResMgr, m_aCryptParams);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
}
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) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 4 with AS4UserMessage

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

the class AS4CEFOneWayFuncTest method testAS4_TA21.

/**
 * Prerequisite:<br>
 * SMSH and RMSH are configured to exchange AS4 messages according to the
 * e-SENS profile (One-Way/Push MEP). The SMSH sends an AS4 message with a
 * compressed then encrypted and signed payload to the RMSH.<br>
 * <br>
 * Predicate: <br>
 * The RMSH sends back an AS4 non-repudiation receipt.
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testAS4_TA21() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML_XML)).mimeTypeXML().compressionGZIP().build(), s_aResMgr));
    final AS4UserMessage aMsg = MockMessages.createUserMessageNotSigned(m_eSoapVersion, null, aAttachments);
    final Document aDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(null), m_eSoapVersion, aMsg.getMessagingID(), aAttachments, s_aResMgr, false, AS4SigningParams.createDefault());
    final AS4MimeMessage aMimeMsg = AS4Encryptor.encryptMimeMessage(m_eSoapVersion, aDoc, aAttachments, m_aCryptoFactory, false, s_aResMgr, m_aCryptParams);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMimeMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains(AS4TestConstants.NON_REPUDIATION_INFORMATION));
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) Document(org.w3c.dom.Document) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 5 with AS4UserMessage

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

the class AS4CEFOneWayFuncTest method testAS4_TA03.

/**
 * 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 to the RMSH with parameter MESSAGEPROPERTIES containing: A property
 * with attributes "name" and "type" present. A property with only attribute
 * "name" present.<br>
 * <br>
 * Predicate: <br>
 * The RMSH returns a non-repudiation receipt within a HTTP response with
 * status code 2XX.
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testAS4_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);
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final String sTrackerIdentifier = "trackingidentifier";
    aEbms3MessageProperties.addProperty(MessageHelperMethods.createEbms3Property(sTrackerIdentifier, "tracker"));
    // Can not do a Property without Value (type) since type does not exist
    // final Ebms3Property aPropOnlyName = new Ebms3Property ();
    // aPropOnlyName.setName ("OnlyName");
    // aEbms3MessageProperties.addProperty (aPropOnlyName);
    final AS4UserMessage aMsg = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, m_eSoapVersion).setMustUnderstand(true);
    final Document aSignedDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aMsg.getAsSoapDocument(m_aPayload), m_eSoapVersion, aMsg.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)

Aggregations

AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)45 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)20 Test (org.junit.Test)19 Document (org.w3c.dom.Document)19 AS4MimeMessage (com.helger.phase4.messaging.mime.AS4MimeMessage)17 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)16 IAS4ClientBuildMessageCallback (com.helger.phase4.client.IAS4ClientBuildMessageCallback)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 AbstractAS4Message (com.helger.phase4.messaging.domain.AbstractAS4Message)16 File (java.io.File)16 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)15 AS4IncomingDumperFileBased (com.helger.phase4.dump.AS4IncomingDumperFileBased)15 AS4OutgoingDumperFileBased (com.helger.phase4.dump.AS4OutgoingDumperFileBased)15 Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)15 ESimpleUserMessageSendResult (com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult)15 Nonnull (javax.annotation.Nonnull)15