Skip to content

Commit

Permalink
Renamed class to EAS4UserMessageSendResult
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Aug 26, 2024
1 parent ceccea0 commit faf2d56
Show file tree
Hide file tree
Showing 70 changed files with 233 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import com.helger.phase4.dump.AS4IncomingDumperFileBased;
import com.helger.phase4.dump.AS4OutgoingDumperFileBased;
import com.helger.phase4.ebms3header.Ebms3SignalMessage;
import com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult;
import com.helger.phase4.sender.EAS4UserMessageSendResult;
import com.helger.servlet.mock.MockServletContext;
import com.helger.web.scope.mgr.WebScopeManager;

Expand Down Expand Up @@ -71,7 +71,7 @@ public static void main (final String [] args)
final Wrapper <Ebms3SignalMessage> aSignalMsgHolder = new Wrapper <> ();

// Start configuring here
final ESimpleUserMessageSendResult eResult;
final EAS4UserMessageSendResult eResult;
eResult = Phase4BDEWSender.builder ()
.encryptionKeyIdentifierType (ECryptoKeyIdentifierType.X509_KEY_IDENTIFIER)
.signingKeyIdentifierType (ECryptoKeyIdentifierType.BST_DIRECT_REFERENCE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import com.helger.phase4.http.HttpRetrySettings;
import com.helger.phase4.messaging.domain.AS4UserMessage;
import com.helger.phase4.messaging.domain.AbstractAS4Message;
import com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult;
import com.helger.phase4.sender.EAS4UserMessageSendResult;
import com.helger.security.certificate.CertificateHelper;
import com.helger.security.keystore.EKeyStoreType;
import com.helger.security.keystore.KeyStoreHelper;
Expand Down Expand Up @@ -121,7 +121,7 @@ public void onSoapDocument (@Nonnull final Document aDoc)
};
// XXX The message ID to use in the UI
final String sAS4MessageID = "36999089-662a-441f-95fd-470bec2b538e-100@phase4";
final ESimpleUserMessageSendResult eRes = Phase4CEFSender.builder ()
final EAS4UserMessageSendResult eRes = Phase4CEFSender.builder ()
.cryptoFactory (CF)
.httpRetrySettings (new HttpRetrySettings ().setMaxRetries (0))
.action ("TC1Leg1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.helger.phase4.dump.AS4DumpManager;
import com.helger.phase4.dump.AS4IncomingDumperFileBased;
import com.helger.phase4.dump.AS4OutgoingDumperFileBased;
import com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult;
import com.helger.phase4.sender.EAS4UserMessageSendResult;
import com.helger.servlet.mock.MockServletContext;
import com.helger.smpclient.bdxr2.BDXR2ClientReadOnly;
import com.helger.smpclient.dbna.EDBNASML;
Expand Down Expand Up @@ -62,7 +62,7 @@ public static void main (final String [] args)
EDBNASML.TEST.getZoneName()));
aSMPClient.setVerifySignature (false);

final ESimpleUserMessageSendResult eResult;
final EAS4UserMessageSendResult eResult;
eResult = Phase4DBNAllianceSender.builder ()
.documentTypeID (SimpleIdentifierFactory.INSTANCE.createDocumentTypeIdentifier ("bdx-docid-qns", "urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##DBNAlliance-1.0-data-Core"))
.processID (Phase4DBNAllianceSender.IF.createProcessIdentifier(null, "bdx:noprocess"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import com.helger.phase4.profile.euctp.EEuCtpAction;
import com.helger.phase4.profile.euctp.EEuCtpService;
import com.helger.phase4.profile.euctp.EuCtpPMode;
import com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult;
import com.helger.phase4.sender.EAS4UserMessageSendResult;
import com.helger.phase4.util.Phase4Exception;
import com.helger.security.keystore.EKeyStoreType;
import com.helger.servlet.mock.MockServletContext;
Expand Down Expand Up @@ -177,7 +177,7 @@ private static void _sendConnectionTest (final Phase4EuCtpHttpClientSettings aHt
final Wrapper <Ebms3SignalMessage> aSignalMsgHolder,
final AS4CryptoFactoryProperties cryptoFactoryProperties)
{
ESimpleUserMessageSendResult eResult;
EAS4UserMessageSendResult eResult;
eResult = Phase4EuCtpSender.builder ()
.httpClientFactory (aHttpClientSettings)
.fromPartyID (fromPartyID)
Expand Down Expand Up @@ -206,7 +206,7 @@ private static void _sendENSFilling (final Phase4EuCtpHttpClientSettings aHttpCl
final byte [] aPayloadBytes = StreamHelper.getAllBytes (new ClassPathResource ("/external/examples/base-example.xml"));

final Wrapper <Ebms3SignalMessage> aSignalMsgHolder = new Wrapper <> ();
ESimpleUserMessageSendResult eResult;
EAS4UserMessageSendResult eResult;
eResult = Phase4EuCtpSender.builder ()
.httpClientFactory (aHttpClientSettings)
.fromPartyID (fromPartyID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.helger.commons.annotation.Nonempty;
import com.helger.commons.collection.impl.CommonsArrayList;
import com.helger.commons.collection.impl.ICommonsList;
import com.helger.commons.id.IHasID;
import com.helger.commons.lang.EnumHelper;
import com.helger.commons.state.ESuccess;
import com.helger.commons.state.ISuccessIndicator;
import com.helger.commons.string.StringHelper;
import com.helger.commons.wrapper.Wrapper;
import com.helger.phase4.attachment.AS4OutgoingAttachment;
Expand All @@ -45,7 +41,6 @@
import com.helger.phase4.model.MessageProperty;
import com.helger.phase4.model.pmode.IPMode;
import com.helger.phase4.util.Phase4Exception;
import com.helger.phase4.v3.ChangePhase4V3;

/**
* Abstract builder base class for a user message.
Expand Down Expand Up @@ -708,96 +703,19 @@ protected void applyToUserMessage (@Nonnull final AS4ClientUserMessage aUserMsg)
aUserMsg.setForceMimeMessage (m_bForceMimeMessage);
}

/**
* Specific enumeration with the result error codes of the
* {@link AbstractAS4UserMessageBuilder#sendMessageAndCheckForReceipt()}
* method.
*
* @author Philip Helger
*/
@ChangePhase4V3 ("Moved to top-level and rename")
public enum ESimpleUserMessageSendResult implements IHasID <String>, ISuccessIndicator
{
/**
* Programming error, because not all mandatory fields are filled.
*/
INVALID_PARAMETERS ("invalid-parameters"),
/**
* Something failed on the network or HTTP(S) level
*/
TRANSPORT_ERROR ("transport-error"),
/**
* Some answer was received, but it was no valid AS4 Signal Message
*/
NO_SIGNAL_MESSAGE_RECEIVED ("no-signal-msg-received"),
/**
* An AS4 Error Message was received
*/
AS4_ERROR_MESSAGE_RECEIVED ("as4-error-msg-received"),
/**
* An AS4 Signal Message was received, but it was neither a Receipt nor an
* Error Message but something else.
*/
INVALID_SIGNAL_MESSAGE_RECEIVED ("invalid-signal-message-received"),
/**
* Everything worked according to plan. The message was successfully
* delivered.
*/
SUCCESS ("success");

private final String m_sID;

ESimpleUserMessageSendResult (@Nonnull @Nonempty final String sID)
{
m_sID = sID;
}

/**
* @return The ID of the of the error message.
* @since 1.0.0-rc1
*/
@Nonnull
@Nonempty
public String getID ()
{
return m_sID;
}

public boolean isSuccess ()
{
return this == SUCCESS;
}

/**
* @return A recommendation whether a retry might be feasible in case the
* internal retries were disabled.
* @since 1.0.0-rc1
*/
public boolean isRetryFeasible ()
{
return this == TRANSPORT_ERROR || this == NO_SIGNAL_MESSAGE_RECEIVED || this == INVALID_SIGNAL_MESSAGE_RECEIVED;
}

@Nullable
public static ESimpleUserMessageSendResult getFromIDOrNull (@Nullable final String sID)
{
return EnumHelper.getFromIDOrNull (ESimpleUserMessageSendResult.class, sID);
}
}

/**
* 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.
*
* @return {@link ESimpleUserMessageSendResult#SUCCESS} only if all parameters
* @return {@link EAS4UserMessageSendResult#SUCCESS} only if all parameters
* are correct, HTTP transmission was successful and if a positive AS4
* Receipt was returned. Never <code>null</code>.
* @since 0.13.0
*/
@Nonnull
public final ESimpleUserMessageSendResult sendMessageAndCheckForReceipt ()
public final EAS4UserMessageSendResult sendMessageAndCheckForReceipt ()
{
// This information might be crucial to determine what went wrong
return sendMessageAndCheckForReceipt (ex -> LOGGER.error ("Exception sending AS4 user message", ex));
Expand All @@ -812,13 +730,13 @@ public final ESimpleUserMessageSendResult sendMessageAndCheckForReceipt ()
* @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
* @return {@link EAS4UserMessageSendResult#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)
public final EAS4UserMessageSendResult sendMessageAndCheckForReceipt (@Nullable final Consumer <? super Phase4Exception> aExceptionConsumer)
{
final IAS4SignalMessageConsumer aOld = m_aSignalMsgConsumer;
try
Expand All @@ -837,7 +755,7 @@ public final ESimpleUserMessageSendResult sendMessageAndCheckForReceipt (@Nullab
if (sendMessage ().isFailure ())
{
// Parameters are missing/incorrect
return ESimpleUserMessageSendResult.INVALID_PARAMETERS;
return EAS4UserMessageSendResult.INVALID_PARAMETERS;
}

final Ebms3SignalMessage aSignalMsg = aSignalMsgKeeper.get ();
Expand All @@ -847,7 +765,7 @@ public final ESimpleUserMessageSendResult sendMessageAndCheckForReceipt (@Nullab
LOGGER.debug ("Failed to get a SignalMessage as the response");

// Unexpected response - invalid XML or at least no Ebms3 signal message
return ESimpleUserMessageSendResult.NO_SIGNAL_MESSAGE_RECEIVED;
return EAS4UserMessageSendResult.NO_SIGNAL_MESSAGE_RECEIVED;
}

if (aSignalMsg.hasErrorEntries ())
Expand All @@ -857,20 +775,20 @@ public final ESimpleUserMessageSendResult sendMessageAndCheckForReceipt (@Nullab

// An error was returned from the other side
// Errors have precedence over receipts
return ESimpleUserMessageSendResult.AS4_ERROR_MESSAGE_RECEIVED;
return EAS4UserMessageSendResult.AS4_ERROR_MESSAGE_RECEIVED;
}

if (aSignalMsg.getReceipt () != null)
{
// A receipt was returned - this is deemed success
return ESimpleUserMessageSendResult.SUCCESS;
return EAS4UserMessageSendResult.SUCCESS;
}

if (LOGGER.isDebugEnabled ())
LOGGER.debug ("The SignalMessage contains neither Errors nor a Receipt - unexpected SignalMessage layout.");

// Neither an error nor a receipt was returned - this is weird
return ESimpleUserMessageSendResult.INVALID_SIGNAL_MESSAGE_RECEIVED;
return EAS4UserMessageSendResult.INVALID_SIGNAL_MESSAGE_RECEIVED;
}
catch (final Phase4Exception ex)
{
Expand All @@ -880,7 +798,7 @@ public final ESimpleUserMessageSendResult sendMessageAndCheckForReceipt (@Nullab
if (aExceptionConsumer != null)
aExceptionConsumer.accept (ex);
// Something went wrong - see the logs
return ESimpleUserMessageSendResult.TRANSPORT_ERROR;
return EAS4UserMessageSendResult.TRANSPORT_ERROR;
}
finally
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.helger.phase4.sender;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.helger.commons.annotation.Nonempty;
import com.helger.commons.id.IHasID;
import com.helger.commons.lang.EnumHelper;
import com.helger.commons.state.ISuccessIndicator;

/**
* Specific enumeration with the result error codes of the
* {@link AbstractAS4UserMessageBuilder#sendMessageAndCheckForReceipt()}
* method.<br />
* Old name before v3: <code>ESimpleUserMessageSendResult</code>
*
* @author Philip Helger
*/
public enum EAS4UserMessageSendResult implements IHasID <String>, ISuccessIndicator
{
/**
* Programming error, because not all mandatory fields are filled.
*/
INVALID_PARAMETERS ("invalid-parameters"),
/**
* Something failed on the network or HTTP(S) level
*/
TRANSPORT_ERROR ("transport-error"),
/**
* Some answer was received, but it was no valid AS4 Signal Message
*/
NO_SIGNAL_MESSAGE_RECEIVED ("no-signal-msg-received"),
/**
* An AS4 Error Message was received
*/
AS4_ERROR_MESSAGE_RECEIVED ("as4-error-msg-received"),
/**
* An AS4 Signal Message was received, but it was neither a Receipt nor an
* Error Message but something else.
*/
INVALID_SIGNAL_MESSAGE_RECEIVED ("invalid-signal-message-received"),
/**
* Everything worked according to plan. The message was successfully
* delivered.
*/
SUCCESS ("success");

private final String m_sID;

EAS4UserMessageSendResult (@Nonnull @Nonempty final String sID)
{
m_sID = sID;
}

/**
* @return The ID of the of the error message.
* @since 1.0.0-rc1
*/
@Nonnull
@Nonempty
public String getID ()
{
return m_sID;
}

public boolean isSuccess ()
{
return this == SUCCESS;
}

/**
* @return A recommendation whether a retry might be feasible in case the
* internal retries were disabled.
* @since 1.0.0-rc1
*/
public boolean isRetryFeasible ()
{
return this == TRANSPORT_ERROR || this == NO_SIGNAL_MESSAGE_RECEIVED || this == INVALID_SIGNAL_MESSAGE_RECEIVED;
}

@Nullable
public static EAS4UserMessageSendResult getFromIDOrNull (@Nullable final String sID)
{
return EnumHelper.getFromIDOrNull (EAS4UserMessageSendResult.class, sID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import com.helger.phase4.dump.AS4DumpManager;
import com.helger.phase4.dump.AS4IncomingDumperFileBased;
import com.helger.phase4.dump.AS4OutgoingDumperFileBased;
import com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult;
import com.helger.phase4.sender.EAS4UserMessageSendResult;
import com.helger.phive.api.result.ValidationResultList;
import com.helger.phive.peppol.PeppolValidation2023_11;
import com.helger.photon.io.WebFileIO;
Expand Down Expand Up @@ -68,7 +68,7 @@ public static void main (final String [] args)

// Start configuring here
final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme ("9915:helger");
final ESimpleUserMessageSendResult eResult;
final EAS4UserMessageSendResult 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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.helger.phase4.dump.AS4IncomingDumperFileBased;
import com.helger.phase4.dump.AS4OutgoingDumperFileBased;
import com.helger.phase4.http.HttpRetrySettings;
import com.helger.phase4.sender.AbstractAS4UserMessageBuilder.ESimpleUserMessageSendResult;
import com.helger.phase4.sender.EAS4UserMessageSendResult;
import com.helger.phive.peppol.PeppolValidation2023_11;
import com.helger.security.certificate.CertificateHelper;
import com.helger.servlet.mock.MockServletContext;
Expand Down Expand Up @@ -60,7 +60,7 @@ public static void main (final String [] args)

// Start configuring here
final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme ("9930:INPOSIATEST");
final ESimpleUserMessageSendResult eResult;
final EAS4UserMessageSendResult 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"))
Expand Down
Loading

0 comments on commit faf2d56

Please sign in to comment.