Skip to content

Commit

Permalink
Replaced checkFailure(String) with checkFailure(); #162
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Sep 15, 2023
1 parent 8c3be6e commit 7a5c857
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ public static void parseAS4Message (@Nonnull final IAS4IncomingAttachmentFactory
final IMimeType aPlainContentType = aContentType.getCopyWithoutParameters ();

// Fallback to global dumper if none is provided
final IAS4IncomingDumper aRealIncomingDumper = aIncomingDumper != null ? aIncomingDumper
: AS4DumpManager.getIncomingDumper ();
final IAS4IncomingDumper aRealIncomingDumper = aIncomingDumper != null ? aIncomingDumper : AS4DumpManager
.getIncomingDumper ();

Document aSoapDocument = null;
ESoapVersion eSoapVersion = null;
Expand Down Expand Up @@ -416,8 +416,7 @@ private static void _processSoapHeaderElements (@Nonnull final SOAPHeaderElement
aHeader.getNode (),
aIncomingAttachments,
aState,
aErrorList)
.isSuccess ())
aErrorList).isSuccess ())
{
// Mark header as processed (for mustUnderstand check)
aHeader.setProcessed (true);
Expand Down Expand Up @@ -593,6 +592,8 @@ public static IAS4MessageState processEbmsMessage (@Nonnull @WillNotClose final
// Handle all headers - modifies the state
_processSoapHeaderElements (aRegistry, aSoapDocument, aIncomingAttachments, aState, aErrorMessagesTarget);

// Here we know, if the message was signed and/or decrypted

// Remember if header processing was successful or not
final boolean bSoapHeaderElementProcessingSuccess = aErrorMessagesTarget.isEmpty ();
aState.setSoapHeaderElementProcessingSuccessful (bSoapHeaderElementProcessingSuccess);
Expand Down Expand Up @@ -633,6 +634,17 @@ public static IAS4MessageState processEbmsMessage (@Nonnull @WillNotClose final
LOGGER.debug ("Determined AS4 profile ID '" + sProfileID + "' for current message");
aState.setProfileID (sProfileID);

if (StringHelper.hasText (sProfileID))
{
final IAS4Profile aProfile = MetaAS4Manager.getProfileMgr ().getProfileOfID (sProfileID);
if (aProfile != null)
{

}
else
LOGGER.warn ("Weird - the AS4 profile ID '" + sProfileID + "' could not be resolved to an object.");
}

final IPMode aPMode = aState.getPMode ();
final PModeLeg aEffectiveLeg = aState.getEffectivePModeLeg ();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -739,18 +739,6 @@ private void _invokeSPIsForIncoming (@Nonnull final HttpHeaderMap aHttpHeaders,
aErrorMessagesTarget.addAll (aProcessingErrorMessages);
}

if (aResult.isFailure () && aResult.hasErrorMessage ())
{
aErrorMessagesTarget.add (EEbmsError.EBMS_OTHER.getAsEbms3Error (m_aLocale,
sMessageID,
"Invoked AS4 message processor SPI " +
aProcessor +
" on '" +
sMessageID +
"' returned a failure: " +
aResult.getErrorMessage ()));
}

// Stop processing
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ protected AS4MessageProcessorResult (@Nonnull final ESuccess eSuccess,
@Nullable final ICommonsList <WSS4JAttachment> aAttachments,
@Nullable final String sAsyncResponseURL)
{
m_eSuccess = ValueEnforcer.notNull (eSuccess, "Success");
ValueEnforcer.notNull (eSuccess, "Success");

m_eSuccess = eSuccess;
m_sErrorMsg = sErrorMsg;
m_aAttachments = aAttachments;
m_sAsyncResponseURL = sAsyncResponseURL;
Expand All @@ -79,11 +81,13 @@ public boolean isSuccess ()
* failure.
*/
@Nullable
@Deprecated (forRemoval = true, since = "2.3.0")
public String getErrorMessage ()
{
return m_sErrorMsg;
}

@Deprecated (forRemoval = true, since = "2.3.0")
public boolean hasErrorMessage ()
{
return StringHelper.hasText (m_sErrorMsg);
Expand Down Expand Up @@ -172,16 +176,36 @@ public static AS4MessageProcessorResult createSuccessExt (@Nullable final ICommo
}

/**
* Create a negative response with the provided error message.
* Create a negative response with the provided error message. This method is
* deprecated, because the error message is never used.
*
* @param sErrorMsg
* The error message to send back. May be <code>null</code> or empty
* since v1.3.1.
* @return Never <code>null</code>.
*/
@Nonnull
@Deprecated (forRemoval = true, since = "2.3.0")
public static AS4MessageProcessorResult createFailure (@Nullable final String sErrorMsg)
{
return new AS4MessageProcessorResult (ESuccess.FAILURE, sErrorMsg, (ICommonsList <WSS4JAttachment>) null, (String) null);
return new AS4MessageProcessorResult (ESuccess.FAILURE,
sErrorMsg,
(ICommonsList <WSS4JAttachment>) null,
(String) null);
}

/**
* Create a negative response.
*
* @return Never <code>null</code>.
* @since 2.3.0
*/
@Nonnull
public static AS4MessageProcessorResult createFailure ()
{
return new AS4MessageProcessorResult (ESuccess.FAILURE,
(String) null,
(ICommonsList <WSS4JAttachment>) null,
(String) null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public Ebms3UserMessage getPullReturnUserMessage ()
@Override
public String toString ()
{
return ToStringGenerator.getDerived (super.toString ()).append ("m_aPullReturnUserMessage", m_aPullReturnUserMessage).getToString ();
return ToStringGenerator.getDerived (super.toString ())
.append ("m_aPullReturnUserMessage", m_aPullReturnUserMessage)
.getToString ();
}

@Nonnull
Expand All @@ -86,13 +88,24 @@ public static AS4SignalMessageProcessorResult createSuccess (@Nullable final ICo
@Nullable final String sAsyncResponseURL,
@Nullable final Ebms3UserMessage aPullReturnUserMessage)
{
return new AS4SignalMessageProcessorResult (ESuccess.SUCCESS, null, aAttachments, sAsyncResponseURL, aPullReturnUserMessage);
return new AS4SignalMessageProcessorResult (ESuccess.SUCCESS,
null,
aAttachments,
sAsyncResponseURL,
aPullReturnUserMessage);
}

@Nonnull
@Deprecated (forRemoval = true, since = "2.3.0")
public static AS4SignalMessageProcessorResult createFailure (@Nonnull final String sErrorMsg)
{
ValueEnforcer.notNull (sErrorMsg, "ErrorMsg");
return new AS4SignalMessageProcessorResult (ESuccess.FAILURE, sErrorMsg, null, null, null);
}

@Nonnull
public static AS4SignalMessageProcessorResult createFailure ()
{
return new AS4SignalMessageProcessorResult (ESuccess.FAILURE, null, null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final IAS4Incom
LOGGER.error (sLogPrefix + "Failed to decompress the payload of attachment #" + nAttachmentIndex);
aProcessingErrorMessages.add (EEbmsError.EBMS_DECOMPRESSION_FAILURE.getAsEbms3Error (aDisplayLocale,
aState.getMessageID ()));
return AS4MessageProcessorResult.createFailure (null);
return AS4MessageProcessorResult.createFailure ();
}

// Read data as SBDH
Expand Down Expand Up @@ -589,7 +589,7 @@ public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final IAS4Incom
}
}

return AS4MessageProcessorResult.createFailure (null);
return AS4MessageProcessorResult.createFailure ();
}

aReadAttachments.add (a);
Expand Down Expand Up @@ -620,7 +620,10 @@ public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final IAS4Incom
aReadAttachments.size () +
" attachments";
LOGGER.error (sLogPrefix + sMsg);
return AS4MessageProcessorResult.createFailure (sMsg);
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.getAsEbms3Error (aDisplayLocale,
aState.getMessageID (),
sMsg));
return AS4MessageProcessorResult.createFailure ();
}

// The one and only
Expand Down Expand Up @@ -649,8 +652,11 @@ public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final IAS4Incom
ex.getClass ().getName () +
" - " +
ex.getMessage ();
LOGGER.error (sLogPrefix + sMsg);
return AS4MessageProcessorResult.createFailure (sMsg);
LOGGER.error (sLogPrefix + sMsg, ex);
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.getAsEbms3Error (aDisplayLocale,
aState.getMessageID (),
sMsg));
return AS4MessageProcessorResult.createFailure ();
}

{
Expand Down Expand Up @@ -685,7 +691,10 @@ public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final IAS4Incom
m_aTransportProfile.getID () +
") - not handling incoming AS4 document";
LOGGER.error (sLogPrefix + sMsg);
return AS4MessageProcessorResult.createFailure (sMsg);
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.getAsEbms3Error (aDisplayLocale,
aState.getMessageID (),
sMsg));
return AS4MessageProcessorResult.createFailure ();
}

// Check if the message is for us
Expand All @@ -700,8 +709,11 @@ public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final IAS4Incom
ex.getClass ().getName () +
" - " +
ex.getMessage ();
LOGGER.error (sLogPrefix + sMsg);
return AS4MessageProcessorResult.createFailure (sMsg);
LOGGER.error (sLogPrefix + sMsg, ex);
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.getAsEbms3Error (aDisplayLocale,
aState.getMessageID (),
sMsg));
return AS4MessageProcessorResult.createFailure ();
}
}
else
Expand Down Expand Up @@ -736,11 +748,14 @@ public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final IAS4Incom
}
catch (final Phase4PeppolClientException ex)
{
final String sMsg = ex.getMessage ();
LOGGER.error (sLogPrefix + "Error invoking Peppol handler " + aHandler + ": " + sMsg);
final String sMsg = "Error invoking Peppol handler " + aHandler + ": " + ex.getMessage ();
LOGGER.error (sLogPrefix + sMsg, ex);
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.getAsEbms3Error (aDisplayLocale,
aState.getMessageID (),
sMsg));

// Returned AS4 Error without a custom prefix
return AS4MessageProcessorResult.createFailure (sMsg);
return AS4MessageProcessorResult.createFailure ();
}
catch (final Exception ex)
{
Expand All @@ -751,8 +766,11 @@ public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final IAS4Incom
ex.getClass ().getName () +
" - " +
ex.getMessage ();
LOGGER.error (sLogPrefix + sMsg);
return AS4MessageProcessorResult.createFailure (sMsg);
LOGGER.error (sLogPrefix + sMsg, ex);
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.getAsEbms3Error (aDisplayLocale,
aState.getMessageID (),
sMsg));
return AS4MessageProcessorResult.createFailure ();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import com.helger.phase4.ebms3header.Ebms3PullRequest;
import com.helger.phase4.ebms3header.Ebms3SignalMessage;
import com.helger.phase4.ebms3header.Ebms3UserMessage;
import com.helger.phase4.error.EEbmsError;
import com.helger.phase4.messaging.IAS4IncomingMessageMetadata;
import com.helger.phase4.messaging.domain.MessageHelperMethods;
import com.helger.phase4.model.pmode.IPMode;
Expand Down Expand Up @@ -112,7 +113,10 @@ public AS4MessageProcessorResult processAS4UserMessage (@Nonnull final IAS4Incom
// To test returning with a failure works as intended
if (aUserMessage.getCollaborationInfo ().getAction ().equals (ACTION_FAILURE))
{
return AS4MessageProcessorResult.createFailure (ACTION_FAILURE);
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.getAsEbms3Error (aState.getLocale (),
aState.getMessageID (),
ACTION_FAILURE));
return AS4MessageProcessorResult.createFailure ();
}
return AS4MessageProcessorResult.createSuccess ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.helger.phase4.ebms3header.Ebms3PullRequest;
import com.helger.phase4.ebms3header.Ebms3SignalMessage;
import com.helger.phase4.ebms3header.Ebms3UserMessage;
import com.helger.phase4.error.EEbmsError;
import com.helger.phase4.messaging.IAS4IncomingMessageMetadata;
import com.helger.phase4.messaging.domain.MessageHelperMethods;
import com.helger.phase4.model.EMEPBinding;
Expand Down Expand Up @@ -107,7 +108,10 @@ public AS4SignalMessageProcessorResult processAS4SignalMessage (@Nonnull final I
{
if (aPullRequest.getMpc ().equals (MPC_FAILURE))
{
return AS4SignalMessageProcessorResult.createFailure ("Error in creating the usermessage - mock MPC 'failure' was used!");
aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.getAsEbms3Error (aState.getLocale (),
aState.getMessageID (),
"Error in creating the usermessage - mock MPC 'failure' was used!"));
return AS4SignalMessageProcessorResult.createFailure ();
}

// Empty MPC
Expand Down

0 comments on commit 7a5c857

Please sign in to comment.