Search in sources :

Example 1 with IAS4RawResponseConsumer

use of com.helger.phase4.client.IAS4RawResponseConsumer in project phase4 by phax.

the class AS4BidirectionalClientHelper method sendAS4PullRequestAndReceiveAS4UserMessage.

public static void sendAS4PullRequestAndReceiveAS4UserMessage(@Nonnull final IAS4CryptoFactory aCryptoFactory, @Nonnull final IPModeResolver aPModeResolver, @Nonnull final IAS4IncomingAttachmentFactory aIAF, @Nonnull final IAS4IncomingProfileSelector aIncomingProfileSelector, @Nonnull final AS4ClientPullRequestMessage aClientPullRequest, @Nonnull final Locale aLocale, @Nonnull final String sURL, @Nullable final IAS4ClientBuildMessageCallback aBuildMessageCallback, @Nullable final IAS4OutgoingDumper aOutgoingDumper, @Nullable final IAS4IncomingDumper aIncomingDumper, @Nullable final IAS4RetryCallback aRetryCallback, @Nullable final IAS4RawResponseConsumer aResponseConsumer, @Nullable final IAS4UserMessageConsumer aUserMsgConsumer) throws IOException, Phase4Exception, WSSecurityException, MessagingException {
    if (LOGGER.isInfoEnabled())
        LOGGER.info("Sending AS4 PullRequest to '" + sURL + "' with max. " + aClientPullRequest.httpRetrySettings().getMaxRetries() + " retries");
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("  MPC = '" + aClientPullRequest.getMPC() + "'");
    final Wrapper<HttpResponse> aWrappedResponse = new Wrapper<>();
    final ResponseHandler<byte[]> aResponseHdl = aHttpResponse -> {
        // May throw an ExtendedHttpResponseException
        final HttpEntity aEntity = ResponseHandlerHttpEntity.INSTANCE.handleResponse(aHttpResponse);
        if (aEntity == null)
            return null;
        aWrappedResponse.set(aHttpResponse);
        return EntityUtils.toByteArray(aEntity);
    };
    final AS4ClientSentMessage<byte[]> aResponseEntity = aClientPullRequest.sendMessageWithRetries(sURL, aResponseHdl, aBuildMessageCallback, aOutgoingDumper, aRetryCallback);
    if (LOGGER.isInfoEnabled())
        LOGGER.info("Successfully transmitted AS4 PullRequest with message ID '" + aResponseEntity.getMessageID() + "' to '" + sURL + "'");
    if (aResponseConsumer != null)
        aResponseConsumer.handleResponse(aResponseEntity);
    // Try interpret result as SignalMessage
    if (aResponseEntity.hasResponse() && aResponseEntity.getResponse().length > 0) {
        final IAS4IncomingMessageMetadata aMessageMetadata = new AS4IncomingMessageMetadata(EAS4MessageMode.RESPONSE).setRemoteAddr(sURL);
        // Read response as EBMS3 User Message
        // Read it in any case to ensure signature validation etc. happens
        final Ebms3UserMessage aUserMessage = AS4IncomingHandler.parseUserMessage(aCryptoFactory, aPModeResolver, aIAF, aIncomingProfileSelector, aClientPullRequest.getAS4ResourceHelper(), null, aLocale, aMessageMetadata, aWrappedResponse.get(), aResponseEntity.getResponse(), aIncomingDumper);
        if (aUserMessage != null && aUserMsgConsumer != null)
            aUserMsgConsumer.handleUserMessage(aUserMessage);
    } else
        LOGGER.info("AS4 ResponseEntity is empty");
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) IAS4SignalMessageConsumer(com.helger.phase4.client.IAS4SignalMessageConsumer) IAS4RawResponseConsumer(com.helger.phase4.client.IAS4RawResponseConsumer) LoggerFactory(org.slf4j.LoggerFactory) MessagingException(javax.mail.MessagingException) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) ResponseHandlerHttpEntity(com.helger.httpclient.response.ResponseHandlerHttpEntity) EntityUtils(org.apache.http.util.EntityUtils) IAS4IncomingProfileSelector(com.helger.phase4.servlet.IAS4IncomingProfileSelector) EAS4MessageMode(com.helger.phase4.messaging.EAS4MessageMode) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Locale(java.util.Locale) IAS4IncomingDumper(com.helger.phase4.dump.IAS4IncomingDumper) IAS4IncomingMessageMetadata(com.helger.phase4.messaging.IAS4IncomingMessageMetadata) IAS4RetryCallback(com.helger.phase4.client.IAS4RetryCallback) Nonnull(javax.annotation.Nonnull) IAS4IncomingAttachmentFactory(com.helger.phase4.attachment.IAS4IncomingAttachmentFactory) Phase4Exception(com.helger.phase4.util.Phase4Exception) Nullable(javax.annotation.Nullable) IAS4OutgoingDumper(com.helger.phase4.dump.IAS4OutgoingDumper) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) AS4ClientPullRequestMessage(com.helger.phase4.client.AS4ClientPullRequestMessage) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) Logger(org.slf4j.Logger) AS4IncomingMessageMetadata(com.helger.phase4.servlet.AS4IncomingMessageMetadata) IPModeResolver(com.helger.phase4.model.pmode.resolve.IPModeResolver) AS4ClientSentMessage(com.helger.phase4.client.AS4ClientSentMessage) HttpEntity(org.apache.http.HttpEntity) IOException(java.io.IOException) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) AS4IncomingHandler(com.helger.phase4.servlet.AS4IncomingHandler) Wrapper(com.helger.commons.wrapper.Wrapper) AS4ClientUserMessage(com.helger.phase4.client.AS4ClientUserMessage) HttpResponse(org.apache.http.HttpResponse) IAS4UserMessageConsumer(com.helger.phase4.client.IAS4UserMessageConsumer) ResponseHandler(org.apache.http.client.ResponseHandler) IAS4IncomingMessageMetadata(com.helger.phase4.messaging.IAS4IncomingMessageMetadata) Wrapper(com.helger.commons.wrapper.Wrapper) ResponseHandlerHttpEntity(com.helger.httpclient.response.ResponseHandlerHttpEntity) HttpEntity(org.apache.http.HttpEntity) IAS4IncomingMessageMetadata(com.helger.phase4.messaging.IAS4IncomingMessageMetadata) AS4IncomingMessageMetadata(com.helger.phase4.servlet.AS4IncomingMessageMetadata) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) HttpResponse(org.apache.http.HttpResponse)

Example 2 with IAS4RawResponseConsumer

use of com.helger.phase4.client.IAS4RawResponseConsumer in project phase4 by phax.

the class AS4BidirectionalClientHelper method sendAS4UserMessageAndReceiveAS4SignalMessage.

public static void sendAS4UserMessageAndReceiveAS4SignalMessage(@Nonnull final IAS4CryptoFactory aCryptoFactory, @Nonnull final IPModeResolver aPModeResolver, @Nonnull final IAS4IncomingAttachmentFactory aIAF, @Nonnull final IAS4IncomingProfileSelector aIncomingProfileSelector, @Nonnull final AS4ClientUserMessage aClientUserMsg, @Nonnull final Locale aLocale, @Nonnull final String sURL, @Nullable final IAS4ClientBuildMessageCallback aBuildMessageCallback, @Nullable final IAS4OutgoingDumper aOutgoingDumper, @Nullable final IAS4IncomingDumper aIncomingDumper, @Nullable final IAS4RetryCallback aRetryCallback, @Nullable final IAS4RawResponseConsumer aResponseConsumer, @Nullable final IAS4SignalMessageConsumer aSignalMsgConsumer) throws IOException, Phase4Exception, WSSecurityException, MessagingException {
    if (LOGGER.isInfoEnabled())
        LOGGER.info("Sending AS4 UserMessage to '" + sURL + "' with max. " + aClientUserMsg.httpRetrySettings().getMaxRetries() + " retries");
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("  ServiceType = '" + aClientUserMsg.getServiceType() + "'");
        LOGGER.debug("  Service = '" + aClientUserMsg.getServiceValue() + "'");
        LOGGER.debug("  Action = '" + aClientUserMsg.getAction() + "'");
        LOGGER.debug("  ConversationId = '" + aClientUserMsg.getConversationID() + "'");
        LOGGER.debug("  MessageProperties:");
        for (final Ebms3Property p : aClientUserMsg.ebms3Properties()) LOGGER.debug("    [" + p.getName() + "] = [" + p.getValue() + "]");
        LOGGER.debug("  Attachments (" + aClientUserMsg.attachments().size() + "):");
        for (final WSS4JAttachment a : aClientUserMsg.attachments()) {
            LOGGER.debug("    [" + a.getId() + "] with [" + a.getMimeType() + "] and [" + a.getCharsetOrDefault(null) + "] and [" + a.getCompressionMode() + "] and [" + a.getContentTransferEncoding() + "]");
        }
    }
    final Wrapper<HttpResponse> aWrappedResponse = new Wrapper<>();
    final ResponseHandler<byte[]> aResponseHdl = aHttpResponse -> {
        // throws an ExtendedHttpResponseException on exception
        final HttpEntity aEntity = ResponseHandlerHttpEntity.INSTANCE.handleResponse(aHttpResponse);
        if (aEntity == null)
            return null;
        aWrappedResponse.set(aHttpResponse);
        return EntityUtils.toByteArray(aEntity);
    };
    final AS4ClientSentMessage<byte[]> aResponseEntity = aClientUserMsg.sendMessageWithRetries(sURL, aResponseHdl, aBuildMessageCallback, aOutgoingDumper, aRetryCallback);
    if (LOGGER.isInfoEnabled())
        LOGGER.info("Successfully transmitted AS4 UserMessage with message ID '" + aResponseEntity.getMessageID() + "' to '" + sURL + "'");
    if (aResponseConsumer != null)
        aResponseConsumer.handleResponse(aResponseEntity);
    // Try interpret result as SignalMessage
    if (aResponseEntity.hasResponse() && aResponseEntity.getResponse().length > 0) {
        final IAS4IncomingMessageMetadata aMessageMetadata = new AS4IncomingMessageMetadata(EAS4MessageMode.RESPONSE).setRemoteAddr(sURL);
        // Read response as EBMS3 Signal Message
        // Read it in any case to ensure signature validation etc. happens
        final Ebms3SignalMessage aSignalMessage = AS4IncomingHandler.parseSignalMessage(aCryptoFactory, aPModeResolver, aIAF, aIncomingProfileSelector, aClientUserMsg.getAS4ResourceHelper(), aClientUserMsg.getPMode(), aLocale, aMessageMetadata, aWrappedResponse.get(), aResponseEntity.getResponse(), aIncomingDumper);
        if (aSignalMessage != null && aSignalMsgConsumer != null)
            aSignalMsgConsumer.handleSignalMessage(aSignalMessage);
    } else
        LOGGER.info("AS4 ResponseEntity is empty");
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) IAS4SignalMessageConsumer(com.helger.phase4.client.IAS4SignalMessageConsumer) IAS4RawResponseConsumer(com.helger.phase4.client.IAS4RawResponseConsumer) LoggerFactory(org.slf4j.LoggerFactory) MessagingException(javax.mail.MessagingException) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) ResponseHandlerHttpEntity(com.helger.httpclient.response.ResponseHandlerHttpEntity) EntityUtils(org.apache.http.util.EntityUtils) IAS4IncomingProfileSelector(com.helger.phase4.servlet.IAS4IncomingProfileSelector) EAS4MessageMode(com.helger.phase4.messaging.EAS4MessageMode) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Locale(java.util.Locale) IAS4IncomingDumper(com.helger.phase4.dump.IAS4IncomingDumper) IAS4IncomingMessageMetadata(com.helger.phase4.messaging.IAS4IncomingMessageMetadata) IAS4RetryCallback(com.helger.phase4.client.IAS4RetryCallback) Nonnull(javax.annotation.Nonnull) IAS4IncomingAttachmentFactory(com.helger.phase4.attachment.IAS4IncomingAttachmentFactory) Phase4Exception(com.helger.phase4.util.Phase4Exception) Nullable(javax.annotation.Nullable) IAS4OutgoingDumper(com.helger.phase4.dump.IAS4OutgoingDumper) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) AS4ClientPullRequestMessage(com.helger.phase4.client.AS4ClientPullRequestMessage) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) Logger(org.slf4j.Logger) AS4IncomingMessageMetadata(com.helger.phase4.servlet.AS4IncomingMessageMetadata) IPModeResolver(com.helger.phase4.model.pmode.resolve.IPModeResolver) AS4ClientSentMessage(com.helger.phase4.client.AS4ClientSentMessage) HttpEntity(org.apache.http.HttpEntity) IOException(java.io.IOException) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) AS4IncomingHandler(com.helger.phase4.servlet.AS4IncomingHandler) Wrapper(com.helger.commons.wrapper.Wrapper) AS4ClientUserMessage(com.helger.phase4.client.AS4ClientUserMessage) HttpResponse(org.apache.http.HttpResponse) IAS4UserMessageConsumer(com.helger.phase4.client.IAS4UserMessageConsumer) ResponseHandler(org.apache.http.client.ResponseHandler) IAS4IncomingMessageMetadata(com.helger.phase4.messaging.IAS4IncomingMessageMetadata) Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) Wrapper(com.helger.commons.wrapper.Wrapper) ResponseHandlerHttpEntity(com.helger.httpclient.response.ResponseHandlerHttpEntity) HttpEntity(org.apache.http.HttpEntity) IAS4IncomingMessageMetadata(com.helger.phase4.messaging.IAS4IncomingMessageMetadata) AS4IncomingMessageMetadata(com.helger.phase4.servlet.AS4IncomingMessageMetadata) HttpResponse(org.apache.http.HttpResponse) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment)

Example 3 with IAS4RawResponseConsumer

use of com.helger.phase4.client.IAS4RawResponseConsumer in project phase4 by phax.

the class MainPhase4PeppolSenderHelger method send.

public static void send() {
    try {
        final Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/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("9915:helger");
        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() + "'");
            }
        };
        final IAS4RawResponseConsumer aRRC = new AS4RawResponseConsumerWriteToFile().setHandleStatusLine(true).setHandleHttpHeaders(true).and(x -> {
            LOGGER.info("Response status line: " + x.getResponseStatusLine());
            LOGGER.info("Response headers:");
            x.getResponseHeaders().forEachSingleHeader((k, v) -> LOGGER.info("  " + k + "=" + v), false);
        });
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("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-sender")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadElement).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).sbdDocumentConsumer(x -> {
            if (false)
                LOGGER.info(SBDHWriter.standardBusinessDocument().setFormattedOutput(true).getAsString(x));
        }).validationConfiguration(PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, new Phase4PeppolValidatonResultHandler()).buildMessageCallback(aBuildMessageCallback).rawResponseConsumer(aRRC).sendMessageAndCheckForReceipt();
        LOGGER.info("Peppol send result: " + eResult);
    } catch (final Exception ex) {
        LOGGER.error("Error sending Peppol message via AS4", ex);
    }
}
Also used : AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) Logger(org.slf4j.Logger) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) IAS4RawResponseConsumer(com.helger.phase4.client.IAS4RawResponseConsumer) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) LoggerFactory(org.slf4j.LoggerFactory) File(java.io.File) AS4DumpManager(com.helger.phase4.dump.AS4DumpManager) PeppolValidation3_13_0(com.helger.phive.peppol.PeppolValidation3_13_0) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) DOMReader(com.helger.xml.serialize.read.DOMReader) Element(org.w3c.dom.Element) MockServletContext(com.helger.servlet.mock.MockServletContext) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) WebScopeManager(com.helger.web.scope.mgr.WebScopeManager) SBDHWriter(com.helger.sbdh.builder.SBDHWriter) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) ESML(com.helger.peppol.sml.ESML) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) IAS4RawResponseConsumer(com.helger.phase4.client.IAS4RawResponseConsumer) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 4 with IAS4RawResponseConsumer

use of com.helger.phase4.client.IAS4RawResponseConsumer in project phase4 by phax.

the class MainPhase4PeppolSenderHelgerLargeFile method send.

public static void send() {
    try {
        final Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/examples/large-files/base-example-large-10m.xml")).getDocumentElement();
        if (aPayloadElement == null)
            throw new IllegalStateException("Failed to read XML file to be send");
        final boolean bNoValidate = false;
        // Start configuring here
        final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:helger");
        final IAS4RawResponseConsumer aRRC = new AS4RawResponseConsumerWriteToFile().setHandleStatusLine(true).setHandleHttpHeaders(true);
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("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-sender")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadElement).compressPayload(false).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).validationConfiguration(bNoValidate ? null : PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, bNoValidate ? null : new Phase4PeppolValidatonResultHandler()).rawResponseConsumer(aRRC).sendMessageAndCheckForReceipt();
        LOGGER.info("Peppol send result: " + eResult);
    } catch (final Exception ex) {
        LOGGER.error("Error sending Peppol message via AS4", ex);
    }
}
Also used : SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) Element(org.w3c.dom.Element) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) IAS4RawResponseConsumer(com.helger.phase4.client.IAS4RawResponseConsumer) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 5 with IAS4RawResponseConsumer

use of com.helger.phase4.client.IAS4RawResponseConsumer in project phase4 by phax.

the class MainPhase4PeppolSenderHelgerXRechnung12CII method send.

@SuppressWarnings("deprecation")
public static void send() {
    try {
        final Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/examples/xrechnung-1.2-cii-example1.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("9915:helger");
        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() + "'");
            }
        };
        final Wrapper<Ebms3SignalMessage> aSignalMsgWrapper = new Wrapper<>();
        final IAS4RawResponseConsumer aRRC = new AS4RawResponseConsumerWriteToFile().setHandleStatusLine(true).setHandleHttpHeaders(true);
        // Add XRechnung rulesets
        final IValidationExecutorSetRegistry<IValidationSourceXML> aVESRegistry = Phase4PeppolValidation.createDefaultRegistry();
        EN16931Validation.initEN16931(aVESRegistry);
        XRechnungValidation.initXRechnung(aVESRegistry);
        final ESimpleUserMessageSendResult eResult;
        eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100::CrossIndustryInvoice##urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_1.2::D16B")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0")).senderParticipantID(Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:phase4-test-sender")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadElement).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).validationRegistry(aVESRegistry).validationConfiguration(XRechnungValidation.VID_XRECHNUNG_CII_122, new Phase4PeppolValidatonResultHandler()).buildMessageCallback(aBuildMessageCallback).rawResponseConsumer(aRRC).signalMsgConsumer(aSignalMsgWrapper::set).sendMessageAndCheckForReceipt();
        LOGGER.info("Peppol send result: " + eResult);
    } catch (final Exception ex) {
        LOGGER.error("Error sending Peppol message via AS4", ex);
    }
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) Wrapper(com.helger.commons.wrapper.Wrapper) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) Element(org.w3c.dom.Element) IValidationSourceXML(com.helger.phive.engine.source.IValidationSourceXML) IAS4RawResponseConsumer(com.helger.phase4.client.IAS4RawResponseConsumer) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) ESimpleUserMessageSendResult(com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Aggregations

IAS4RawResponseConsumer (com.helger.phase4.client.IAS4RawResponseConsumer)5 IAS4ClientBuildMessageCallback (com.helger.phase4.client.IAS4ClientBuildMessageCallback)4 Wrapper (com.helger.commons.wrapper.Wrapper)3 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)3 AS4RawResponseConsumerWriteToFile (com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile)3 Ebms3SignalMessage (com.helger.phase4.ebms3header.Ebms3SignalMessage)3 ESimpleUserMessageSendResult (com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult)3 SMPClientReadOnly (com.helger.smpclient.peppol.SMPClientReadOnly)3 File (java.io.File)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Element (org.w3c.dom.Element)3 ResponseHandlerHttpEntity (com.helger.httpclient.response.ResponseHandlerHttpEntity)2 IAS4IncomingAttachmentFactory (com.helger.phase4.attachment.IAS4IncomingAttachmentFactory)2 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)2 AS4ClientPullRequestMessage (com.helger.phase4.client.AS4ClientPullRequestMessage)2 AS4ClientSentMessage (com.helger.phase4.client.AS4ClientSentMessage)2 AS4ClientUserMessage (com.helger.phase4.client.AS4ClientUserMessage)2 IAS4RetryCallback (com.helger.phase4.client.IAS4RetryCallback)2 IAS4SignalMessageConsumer (com.helger.phase4.client.IAS4SignalMessageConsumer)2