Skip to content

Commit

Permalink
Renamed Peppol specific classes
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Aug 26, 2024
1 parent 53b7282 commit b945d8a
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
import com.helger.phase4.messaging.IAS4IncomingMessageMetadata;
import com.helger.phase4.mgr.MetaAS4Manager;
import com.helger.phase4.peppol.server.storage.StorageHelper;
import com.helger.phase4.peppol.servlet.Phase4PeppolServletConfiguration;
import com.helger.phase4.peppol.servlet.Phase4PeppolDefaultReceiverConfiguration;
import com.helger.phase4.profile.peppol.AS4PeppolProfileRegistarSPI;
import com.helger.phase4.profile.peppol.PeppolCRLDownloader;
import com.helger.phase4.profile.peppol.Phase4PeppolHttpClientSettings;
Expand Down Expand Up @@ -206,12 +206,12 @@ private static void _initPeppolAS4 ()
{
// Our server expects all SBDH to contain the COUNTRY_C1 element in SBDH
// (this is the default setting, but added it here for easy modification)
Phase4PeppolServletConfiguration.setCheckSBDHForMandatoryCountryC1 (true);
Phase4PeppolDefaultReceiverConfiguration.setCheckSBDHForMandatoryCountryC1 (true);

// Our server should check all signing certificates of incoming messages if
// they are revoked or not
// (this is the default setting, but added it here for easy modification)
Phase4PeppolServletConfiguration.setCheckSigningCertificateRevocation (true);
Phase4PeppolDefaultReceiverConfiguration.setCheckSigningCertificateRevocation (true);

// Make sure the download of CRL is using Apache HttpClient and that the
// provided settings are used. If e.g. a proxy is needed to access outbound
Expand Down Expand Up @@ -322,11 +322,11 @@ private static void _initPeppolAS4 ()
final String sAPURL = AS4Configuration.getThisEndpointAddress ();
if (StringHelper.hasText (sSMPURL) && StringHelper.hasText (sAPURL))
{
Phase4PeppolServletConfiguration.setReceiverCheckEnabled (true);
Phase4PeppolServletConfiguration.setSMPClient (new SMPClientReadOnly (URLHelper.getAsURI (sSMPURL)));
Phase4PeppolServletConfiguration.setWildcardSelectionMode (Phase4PeppolServletConfiguration.DEFAULT_WILDCARD_SELECTION_MODE);
Phase4PeppolServletConfiguration.setAS4EndpointURL (sAPURL);
Phase4PeppolServletConfiguration.setAPCertificate (aAPCert);
Phase4PeppolDefaultReceiverConfiguration.setReceiverCheckEnabled (true);
Phase4PeppolDefaultReceiverConfiguration.setSMPClient (new SMPClientReadOnly (URLHelper.getAsURI (sSMPURL)));
Phase4PeppolDefaultReceiverConfiguration.setWildcardSelectionMode (Phase4PeppolDefaultReceiverConfiguration.DEFAULT_WILDCARD_SELECTION_MODE);
Phase4PeppolDefaultReceiverConfiguration.setAS4EndpointURL (sAPURL);
Phase4PeppolDefaultReceiverConfiguration.setAPCertificate (aAPCert);
LOGGER.info (CAS4.LIB_NAME +
" Peppol receiver checks are enabled on SMP '" +
sSMPURL +
Expand All @@ -336,7 +336,7 @@ private static void _initPeppolAS4 ()
}
else
{
Phase4PeppolServletConfiguration.setReceiverCheckEnabled (false);
Phase4PeppolDefaultReceiverConfiguration.setReceiverCheckEnabled (false);
LOGGER.warn (CAS4.LIB_NAME + " Peppol receiver checks are disabled");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.helger.phase4.ebms3header.Ebms3UserMessage;
import com.helger.phase4.incoming.IAS4MessageState;
import com.helger.phase4.messaging.IAS4IncomingMessageMetadata;
import com.helger.phase4.v3.ChangePhase4V3;

/**
* This is the interface that must be implemented to handle incoming SBD
Expand Down Expand Up @@ -72,9 +71,7 @@ public interface IPhase4PeppolIncomingSBDHandlerSPI
* if this specific exception is thrown, it translates into a
* synchronous AS4 error message.
* @throws Exception
* In case it cannot be processed. If
* {@link #exceptionTranslatesToAS4Error()} returns <code>true</code>
* each Exception is converted into a synchronous AS4 error message.
* In case it cannot be processed.
*/
void handleIncomingSBD (@Nonnull IAS4IncomingMessageMetadata aMessageMetadata,
@Nonnull HttpHeaderMap aHeaders,
Expand All @@ -84,20 +81,4 @@ void handleIncomingSBD (@Nonnull IAS4IncomingMessageMetadata aMessageMetadata,
@Nonnull PeppolSBDHData aPeppolSBD,
@Nonnull IAS4MessageState aState,
@Nonnull ICommonsList <Ebms3Error> aProcessingErrorMessages) throws Exception;

/**
* Define if an exception from
* {@link #handleIncomingSBD(IAS4IncomingMessageMetadata, HttpHeaderMap, Ebms3UserMessage, byte[], StandardBusinessDocument, PeppolSBDHData, IAS4MessageState, ICommonsList)}
* results in a negative AS4 response or not. By default it is not.
*
* @return <code>true</code> to convert an Exception into an AS4 Error,
* <code>false</code> if the Exception should simply be logged and
* than processing should continue.
* @since 0.12.2
*/
@ChangePhase4V3 ("Remove Exception handling and force usage of aProcessingErrorMessages")
default boolean exceptionTranslatesToAS4Error ()
{
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import com.helger.commons.string.StringHelper;
import com.helger.peppol.sbdh.read.PeppolSBDHDocumentReader;
import com.helger.phase4.CAS4;
import com.helger.phase4.v3.ChangePhase4V3;
import com.helger.smpclient.peppol.ISMPServiceMetadataProvider;
import com.helger.smpclient.peppol.PeppolWildcardSelector;
import com.helger.smpclient.peppol.PeppolWildcardSelector.EMode;
Expand All @@ -40,20 +39,19 @@
* {@link Phase4PeppolServletMessageProcessorSPI}. Please note that this class
* is not thread safe, as the default values are not meant to be modified during
* runtime.<br>
* See {@link Phase4PeppolReceiverCheckData} for the "per-request" version of
* this class.
* See {@link Phase4PeppolReceiverConfiguration} for the "per-request" version
* of this class.
*
* @author Philip Helger
*/
@NotThreadSafe
@ChangePhase4V3 ("Rename to Phase4PeppolGlobalReceiverConfiguration")
public final class Phase4PeppolServletConfiguration
public final class Phase4PeppolDefaultReceiverConfiguration
{
public static final boolean DEFAULT_RECEIVER_CHECK_ENABLED = true;
public static final EMode DEFAULT_WILDCARD_SELECTION_MODE = EMode.WILDCARD_ONLY;
public static final boolean DEFAULT_CHECK_SIGNING_CERTIFICATE_REVOCATION = true;

private static final Logger LOGGER = LoggerFactory.getLogger (Phase4PeppolServletConfiguration.class);
private static final Logger LOGGER = LoggerFactory.getLogger (Phase4PeppolDefaultReceiverConfiguration.class);

private static boolean s_bReceiverCheckEnabled = DEFAULT_RECEIVER_CHECK_ENABLED;
private static ISMPServiceMetadataProvider s_aSMPClient;
Expand All @@ -64,7 +62,7 @@ public final class Phase4PeppolServletConfiguration
private static boolean s_bCheckSBDHForMandatoryCountryC1 = PeppolSBDHDocumentReader.DEFAULT_CHECK_FOR_COUNTRY_C1;
private static boolean s_bCheckSigningCertificateRevocation = DEFAULT_CHECK_SIGNING_CERTIFICATE_REVOCATION;

private Phase4PeppolServletConfiguration ()
private Phase4PeppolDefaultReceiverConfiguration ()
{}

/**
Expand Down Expand Up @@ -283,16 +281,16 @@ public static void setCheckSigningCertificateRevocation (final boolean b)

/**
* Get the statically configured data as a
* {@link Phase4PeppolReceiverCheckData} instance. Returns <code>null</code>
* if the checks are disabled, or if at least one mandatory field is not
* set.<br>
* {@link Phase4PeppolReceiverConfiguration} instance. Returns
* <code>null</code> if the checks are disabled, or if at least one mandatory
* field is not set.<br>
* Changed to NonNull in 2.8.1
*
* @return The instance data or <code>null</code>.
* @since 0.9.13
*/
@Nonnull
public static Phase4PeppolReceiverCheckData getAsReceiverCheckData ()
public static Phase4PeppolReceiverConfiguration getAsReceiverCheckData ()
{
final ISMPServiceMetadataProvider aSMPClient = getSMPClient ();
final String sAS4EndpointURL = getAS4EndpointURL ();
Expand All @@ -304,13 +302,13 @@ public static Phase4PeppolReceiverCheckData getAsReceiverCheckData ()
else
bReceiverCheckEnabled = isReceiverCheckEnabled ();

return new Phase4PeppolReceiverCheckData (bReceiverCheckEnabled,
aSMPClient,
getWildcardSelectionMode (),
sAS4EndpointURL,
aAPCertificate,
isPerformSBDHValueChecks (),
isCheckSBDHForMandatoryCountryC1 (),
isCheckSigningCertificateRevocation ());
return new Phase4PeppolReceiverConfiguration (bReceiverCheckEnabled,
aSMPClient,
getWildcardSelectionMode (),
sAS4EndpointURL,
aAPCertificate,
isPerformSBDHValueChecks (),
isCheckSBDHForMandatoryCountryC1 (),
isCheckSigningCertificateRevocation ());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,22 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import javax.annotation.concurrent.Immutable;

import com.helger.commons.ValueEnforcer;
import com.helger.commons.string.ToStringGenerator;
import com.helger.phase4.v3.ChangePhase4V3;
import com.helger.smpclient.peppol.ISMPServiceMetadataProvider;
import com.helger.smpclient.peppol.PeppolWildcardSelector;

/**
* This class contains the "per-request" data of
* {@link Phase4PeppolServletConfiguration}.
* {@link Phase4PeppolDefaultReceiverConfiguration}.
*
* @author Philip Helger
* @since 0.9.13
*/
@ThreadSafe
@ChangePhase4V3 ("Rename to Phase4PeppolReceiverConfiguration; remove setter")
public final class Phase4PeppolReceiverCheckData
@Immutable
public final class Phase4PeppolReceiverConfiguration
{
private final boolean m_bReceiverCheckEnabled;
private final ISMPServiceMetadataProvider m_aSMPClient;
Expand Down Expand Up @@ -76,14 +74,14 @@ public final class Phase4PeppolReceiverCheckData
* performed.
* @since 2.8.1
*/
public Phase4PeppolReceiverCheckData (final boolean bReceiverCheckEnabled,
@Nullable final ISMPServiceMetadataProvider aSMPClient,
@Nonnull final PeppolWildcardSelector.EMode eWildcardSelectionMode,
@Nullable final String sAS4EndpointURL,
@Nullable final X509Certificate aAPCertificate,
final boolean bPerformSBDHValueChecks,
final boolean bCheckSBDHForMandatoryCountryC1,
final boolean bCheckSigningCertificateRevocation)
public Phase4PeppolReceiverConfiguration (final boolean bReceiverCheckEnabled,
@Nullable final ISMPServiceMetadataProvider aSMPClient,
@Nonnull final PeppolWildcardSelector.EMode eWildcardSelectionMode,
@Nullable final String sAS4EndpointURL,
@Nullable final X509Certificate aAPCertificate,
final boolean bPerformSBDHValueChecks,
final boolean bCheckSBDHForMandatoryCountryC1,
final boolean bCheckSigningCertificateRevocation)
{
if (bReceiverCheckEnabled)
ValueEnforcer.notNull (aSMPClient, "SMPClient");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public StandardBusinessDocument standardBusinessDocument ()

private ICommonsList <IPhase4PeppolIncomingSBDHandlerSPI> m_aHandlers;
private ISMPTransportProfile m_aTransportProfile = DEFAULT_TRANSPORT_PROFILE;
private Phase4PeppolReceiverCheckData m_aReceiverCheckData;
private Phase4PeppolReceiverConfiguration m_aReceiverCheckData;

/**
* Constructor. Uses all SPI implementations of
Expand Down Expand Up @@ -248,22 +248,22 @@ public final Phase4PeppolServletMessageProcessorSPI setTransportProfile (@Nonnul
* @since 0.9.13
*/
@Nullable
public final Phase4PeppolReceiverCheckData getReceiverCheckData ()
public final Phase4PeppolReceiverConfiguration getReceiverCheckData ()
{
return m_aReceiverCheckData;
}

/**
* Set the receiver check data to be used. If set, it overrides the global one
* defined by {@link Phase4PeppolServletConfiguration}.
* defined by {@link Phase4PeppolDefaultReceiverConfiguration}.
*
* @param aReceiverCheckData
* The customer receiver check data to use. May be <code>null</code>.
* @return this for chaining
* @since 0.9.13
*/
@Nonnull
public final Phase4PeppolServletMessageProcessorSPI setReceiverCheckData (@Nullable final Phase4PeppolReceiverCheckData aReceiverCheckData)
public final Phase4PeppolServletMessageProcessorSPI setReceiverCheckData (@Nullable final Phase4PeppolReceiverConfiguration aReceiverCheckData)
{
m_aReceiverCheckData = aReceiverCheckData;
return this;
Expand Down Expand Up @@ -551,8 +551,8 @@ public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final IAS4Incom
final String sLogPrefix = "[" + sMessageID + "] ";

// Start consistency checks if the receiver is supported or not
final Phase4PeppolReceiverCheckData aReceiverCheckData = m_aReceiverCheckData != null ? m_aReceiverCheckData
: Phase4PeppolServletConfiguration.getAsReceiverCheckData ();
final Phase4PeppolReceiverConfiguration aReceiverCheckData = m_aReceiverCheckData != null ? m_aReceiverCheckData
: Phase4PeppolDefaultReceiverConfiguration.getAsReceiverCheckData ();

// Debug log
if (LOGGER.isDebugEnabled ())
Expand Down Expand Up @@ -869,23 +869,17 @@ public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final IAS4Incom
.refToMessageInError (aState.getMessageID ())
.errorDetail (sDetails, ex)
.build ());

// Returned AS4 Error without a custom prefix
return AS4MessageProcessorResult.createFailure ();
}
catch (final Exception ex)
{
LOGGER.error (sLogPrefix + "Error invoking Peppol handler " + aHandler, ex);
if (aHandler.exceptionTranslatesToAS4Error ())
{
final String sDetails = "The incoming Peppol message could not be processed.";
LOGGER.error (sLogPrefix + sDetails, ex);
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.errorBuilder (aDisplayLocale)
.refToMessageInError (aState.getMessageID ())
.errorDetail (sDetails, ex)
.build ());
return AS4MessageProcessorResult.createFailure ();
}
final String sDetails = "The incoming Peppol message could not be processed.";
LOGGER.error (sLogPrefix + sDetails, ex);
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.errorBuilder (aDisplayLocale)
.refToMessageInError (aState.getMessageID ())
.errorDetail (sDetails, ex)
.build ());
return AS4MessageProcessorResult.createFailure ();
}
}

Expand Down
Loading

0 comments on commit b945d8a

Please sign in to comment.