Skip to content

Commit

Permalink
Added sendMessageAndCheckForReceipt overload; #48
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Feb 12, 2021
1 parent f47e680 commit 4f769af
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -275,6 +275,7 @@ If you like the project, a star on GitHub is always appreciated.
* The configuration properties `server.debug`, `server.production`, `server.nostartupinfo`, `server.datapath`, `server.profile`, `server.incoming.duplicatedisposal.minutes` and `server.address` are no longer supported
* Removed all deprecated elements
* Extended the API of `ESimpleUserMessageSendResult`
* Added `AbstractAS4UserMessageBuilder.sendMessageAndCheckForReceipt` overload with an exception consumer (see [issue #48](https://github.com/phax/phase4/pull/48))
* v0.14.0 - 2021-01-27
* Changed the default directory structure of the incoming and outgoing dumper as well as the raw response consumer to have subdirectories for year, month and day of month
* Extended `Phase4OutgoingAttachment` to also have a `Charset` parameter. Thanks to [@pavelrotek](https://github.com/pavelrotek) for pointing this out.
Expand Down
Expand Up @@ -17,6 +17,7 @@
package com.helger.phase4.sender;

import java.security.cert.X509Certificate;
import java.util.function.Consumer;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -655,6 +656,27 @@ public static ESimpleUserMessageSendResult getFromIDOrNull (@Nullable final Stri
*/
@Nonnull
public final ESimpleUserMessageSendResult sendMessageAndCheckForReceipt ()
{
// This information might be crucial to determine what went wrong
return sendMessageAndCheckForReceipt (ex -> LOGGER.error ("Exception sending AS4 user message", ex));
}

/**
* This is a sanity method that encapsulates all the sending checks that are
* necessary to determine overall sending success or error.<br>
* Note: this method is not thread-safe, because it changes the signal message
* consumer internally.
*
* @param aExceptionConsumer
* An optional Consumer that takes an eventually thrown
* {@link Phase4Exception}. May be <code>null</code>.
* @return {@link ESimpleUserMessageSendResult#SUCCESS} only if all parameters
* are correct, HTTP transmission was successful and if a positive AS4
* Receipt was returned. Never <code>null</code>.
* @since 1.0.0-rc1
*/
@Nonnull
public final ESimpleUserMessageSendResult sendMessageAndCheckForReceipt (@Nullable final Consumer <? super Phase4Exception> aExceptionConsumer)
{
final IAS4SignalMessageConsumer aOld = m_aSignalMsgConsumer;
try
Expand Down Expand Up @@ -697,8 +719,8 @@ public final ESimpleUserMessageSendResult sendMessageAndCheckForReceipt ()
}
catch (final Phase4Exception ex)
{
// This information might be crucial to determine what went wrong
LOGGER.error ("Exception sending AS4 user message", ex);
if (aExceptionConsumer != null)
aExceptionConsumer.accept (ex);
// Something went wrong - see the logs
return ESimpleUserMessageSendResult.TRANSPORT_ERROR;
}
Expand Down

0 comments on commit 4f769af

Please sign in to comment.