Search in sources :

Example 11 with AS4UserMessage

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

the class MainPhase4PeppolSenderZRE 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 boolean bVerify = true;
        final Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/" + (bVerify ? "zre/Verifizierungs_Rechnung_PEPPOL.xml" : "examples/base-example.xml"))).getDocumentElement();
        if (aPayloadElement == null)
            throw new IllegalStateException("Failed to read XML file to be send");
        // Start configuring here
        final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme(bVerify ? "0204:991-55555PEPPO-82" : "0204:991-33333TEST-33");
        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() + "'");
            }
        };
        final ESimpleUserMessageSendResult eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme(bVerify ? "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.0::2.1" : "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0")).senderParticipantID(Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:phase4-test-sender2")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadElement).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).validationConfiguration(bVerify ? null : PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, new Phase4PeppolValidatonResultHandler()).buildMessageCallback(aBuildMessageCallback).sendMessageAndCheckForReceipt();
        LOGGER.info("Peppol send result: " + eResult);
    } catch (final Exception ex) {
        LOGGER.error("Error sending Peppol message via AS4", ex);
    } finally {
        WebScopeManager.onGlobalEnd();
    }
}
Also used : IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) 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 12 with AS4UserMessage

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

the class MainOldAS4Client method main.

/**
 * Starting point for the SAAJ - SOAP Client Testing
 *
 * @param args
 *        ignored
 */
public static void main(final String[] args) {
    try (final AS4ResourceHelper aResHelper = new AS4ResourceHelper()) {
        String sURL = "http://127.0.0.1:8080/as4";
        if (false)
            sURL = "http://msh.holodeck-b2b.org:8080/msh";
        // Deactivate if not sending to local holodeck
        if (false)
            sURL = "http://localhost:8080/msh/";
        final HttpClientSettings aHCS = new HttpClientSettings();
        if (sURL.startsWith("https"))
            aHCS.setSSLContextTrustAll();
        if (false) {
            aHCS.setProxyHost(new HttpHost("172.30.9.6", 8080));
            aHCS.addNonProxyHostsFromPipeString("localhost|127.0.0.1");
        }
        final CloseableHttpClient aClient = new HttpClientFactory(aHCS).createHttpClient();
        LOGGER.info("Sending to " + sURL);
        final HttpPost aPost = new HttpPost(sURL);
        final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
        final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource("SOAPBodyPayload.xml"));
        final ESoapVersion eSoapVersion = ESoapVersion.SOAP_12;
        final IAS4CryptoFactory aCryptoFactory = AS4CryptoFactoryProperties.getDefaultInstance();
        if (true) {
            // No Mime Message Not signed or encrypted, just SOAP + Payload in SOAP
            // -
            // Body
            // final Document aDoc = TestMessages.testSignedUserMessage
            // (ESOAPVersion.SOAP_11, aPayload, aAttachments);
            final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned(eSoapVersion, aPayload, aAttachments);
            final Document aDoc = aMsg.getAsSoapDocument(aPayload);
            aPost.setEntity(new HttpXMLEntity(aDoc, eSoapVersion.getMimeType()));
        } else if (false) {
            // BodyPayload SIGNED
            final Document aDoc = MockClientMessages.createUserMessageSigned(eSoapVersion, aPayload, aAttachments, aResHelper);
            aPost.setEntity(new HttpXMLEntity(aDoc, eSoapVersion.getMimeType()));
        } else if (false) {
            // BodyPayload ENCRYPTED
            final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned(eSoapVersion, aPayload, aAttachments);
            Document aDoc = aMsg.getAsSoapDocument(aPayload);
            aDoc = AS4Encryptor.encryptSoapBodyPayload(aCryptoFactory, eSoapVersion, aDoc, false, AS4CryptParams.createDefault().setAlias("dummy"));
            aPost.setEntity(new HttpXMLEntity(aDoc, eSoapVersion.getMimeType()));
        } else if (true) {
            aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile("attachment/test.xml.gz")).mimeType(CMimeType.APPLICATION_GZIP).build(), aResHelper));
            final AS4UserMessage aMsg = MockClientMessages.createUserMessageNotSigned(eSoapVersion, null, aAttachments);
            final AS4MimeMessage aMimeMsg = MimeMessageCreator.generateMimeMessage(eSoapVersion, AS4Signer.createSignedMessage(aCryptoFactory, aMsg.getAsSoapDocument(null), eSoapVersion, aMsg.getMessagingID(), aAttachments, aResHelper, false, AS4SigningParams.createDefault()), aAttachments);
            // Move all global mime headers to the POST request
            MessageHelperMethods.forEachHeaderAndRemoveAfterwards(aMimeMsg, aPost::addHeader, true);
            aPost.setEntity(new HttpMimeMessageEntity(aMimeMsg));
        } else if (false) {
            Document aDoc = MockClientMessages.createUserMessageSigned(eSoapVersion, aPayload, aAttachments, aResHelper);
            aDoc = AS4Encryptor.encryptSoapBodyPayload(aCryptoFactory, eSoapVersion, aDoc, false, AS4CryptParams.createDefault().setAlias("dummy"));
            aPost.setEntity(new HttpXMLEntity(aDoc, eSoapVersion.getMimeType()));
        } else
            throw new IllegalStateException("Some test message should be selected :)");
        // re-instantiate if you want to see the request that is getting sent
        LOGGER.info(EntityUtils.toString(aPost.getEntity()));
        final CloseableHttpResponse aHttpResponse = aClient.execute(aPost);
        LOGGER.info("GET Response Status:: " + aHttpResponse.getStatusLine().getStatusCode());
        // print result
        LOGGER.info(EntityUtils.toString(aHttpResponse.getEntity()));
    } catch (final Exception e) {
        LOGGER.error("Error occurred while sending SOAP Request to Server", e);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) Node(org.w3c.dom.Node) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) HttpHost(org.apache.http.HttpHost) ESoapVersion(com.helger.phase4.soap.ESoapVersion) AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpClientSettings(com.helger.httpclient.HttpClientSettings) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) AS4ResourceHelper(com.helger.phase4.util.AS4ResourceHelper) HttpClientFactory(com.helger.httpclient.HttpClientFactory) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment)

Example 13 with AS4UserMessage

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

the class MockClientMessages method createUserMessageSoapNotSignedNotPModeConform.

@Nonnull
public static Document createUserMessageSoapNotSignedNotPModeConform(@Nonnull final ESoapVersion eSoapVersion, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aAttachments) {
    // Add properties
    final ICommonsList<Ebms3Property> aEbms3Properties = new CommonsArrayList<>();
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property("ProcessInst", "PurchaseOrder:123456"));
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property("ContextID", "987654321"));
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, aAttachments);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo("pm-esens-generic-resp", DEFAULT_AGREEMENT, "MyServiceTypes", "QuoteToCollect", "NewPurchaseOrder", "4321");
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, "testt", CAS4.DEFAULT_RESPONDER_URL, "testt");
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final AS4UserMessage aDoc = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSoapVersion).setMustUnderstand(true);
    return aDoc.getAsSoapDocument(aPayload);
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Nonnull(javax.annotation.Nonnull)

Example 14 with AS4UserMessage

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

the class MockClientMessages method createEmptyUserMessage.

@Nonnull
@SuppressFBWarnings("NP_NONNULL_PARAM_VIOLATION")
public static Document createEmptyUserMessage(@Nonnull final ESoapVersion eSoapVersion, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aAttachments) {
    // Add properties
    final ICommonsList<Ebms3Property> aEbms3Properties = new CommonsArrayList<>();
    final Ebms3Property aEbms3PropertyProcess = new Ebms3Property();
    aEbms3Properties.add(aEbms3PropertyProcess);
    // Use an empty message info by purpose
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, aAttachments);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(null, null, null, "svc", "act", "conv");
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo("fid", "frole", "tid", "trole");
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final AS4UserMessage aDoc = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSoapVersion).setMustUnderstand(true);
    return aDoc.getAsSoapDocument(aPayload);
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Nonnull(javax.annotation.Nonnull) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 15 with AS4UserMessage

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

the class MockClientMessages method createUserMessageNotSigned.

@Nonnull
public static AS4UserMessage createUserMessageNotSigned(@Nonnull final ESoapVersion eSoapVersion, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aAttachments) {
    // Add properties
    final ICommonsList<Ebms3Property> aEbms3Properties = new CommonsArrayList<>();
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property("ProcessInst", "PurchaseOrder:123456"));
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property("ContextID", "987654321"));
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property(CAS4.ORIGINAL_SENDER, "C1 OS"));
    aEbms3Properties.add(MessageHelperMethods.createEbms3Property(CAS4.FINAL_RECIPIENT, "C4 FR"));
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, aAttachments);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo("pmode-twoway", DEFAULT_AGREEMENT, "MyServiceTypes", "QuoteToCollect", "NewPurchaseOrder", "4321");
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, "1234", CAS4.DEFAULT_RESPONDER_URL, "5678");
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final AS4UserMessage aDoc = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSoapVersion).setMustUnderstand(true);
    return aDoc;
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Nonnull(javax.annotation.Nonnull)

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