diff --git a/phase4-lib/src/main/java/com/helger/phase4/error/Ebms3ErrorBuilder.java b/phase4-lib/src/main/java/com/helger/phase4/error/Ebms3ErrorBuilder.java new file mode 100644 index 000000000..d04043bc2 --- /dev/null +++ b/phase4-lib/src/main/java/com/helger/phase4/error/Ebms3ErrorBuilder.java @@ -0,0 +1,135 @@ +/* + * Copyright (C) 2015-2023 Philip Helger (www.helger.com) + * philip[at]helger[dot]com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.helger.phase4.error; + +import java.util.Locale; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +import com.helger.commons.builder.IBuilder; +import com.helger.commons.string.StringHelper; +import com.helger.phase4.ebms3header.Ebms3Description; +import com.helger.phase4.ebms3header.Ebms3Error; +import com.helger.phase4.messaging.domain.MessageHelperMethods; + +/** + * Builder class for {@link Ebms3Error} + * + * @author Philip Helger + * @since 2.6.0 + */ +public class Ebms3ErrorBuilder implements IBuilder +{ + private Ebms3Description m_aDescription; + private String m_sErrorDetail; + private EEbmsErrorCategory m_eCategory; + private String m_sRefToMessageInError; + private String m_sErrorCode; + private String m_sOrigin; + private EEbmsErrorSeverity m_eSeverity; + private String m_sShortDescription; + + public Ebms3ErrorBuilder () + {} + + @Nonnull + public Ebms3ErrorBuilder description (@Nullable final String s, @Nullable final Locale aLocale) + { + return description (StringHelper.hasNoText (s) || aLocale == null ? null : MessageHelperMethods + .createEbms3Description (aLocale, + s)); + } + + @Nonnull + public Ebms3ErrorBuilder description (@Nullable final Ebms3Description a) + { + m_aDescription = a; + return this; + } + + @Nonnull + public Ebms3ErrorBuilder errorDetail (@Nullable final String s) + { + m_sErrorDetail = s; + return this; + } + + @Nonnull + public Ebms3ErrorBuilder category (@Nullable final EEbmsErrorCategory e) + { + m_eCategory = e; + return this; + } + + @Nonnull + public Ebms3ErrorBuilder refToMessageInError (@Nullable final String s) + { + m_sRefToMessageInError = s; + return this; + } + + @Nonnull + public Ebms3ErrorBuilder errorCode (@Nullable final String s) + { + m_sErrorCode = s; + return this; + } + + @Nonnull + public Ebms3ErrorBuilder origin (@Nullable final String s) + { + m_sOrigin = s; + return this; + } + + @Nonnull + public Ebms3ErrorBuilder severity (@Nullable final EEbmsErrorSeverity e) + { + m_eSeverity = e; + return this; + } + + @Nonnull + public Ebms3ErrorBuilder shortDescription (@Nullable final String s) + { + m_sShortDescription = s; + return this; + } + + @Nonnull + public Ebms3Error build () + { + if (m_eSeverity == null) + throw new IllegalStateException ("Severity is required"); + if (StringHelper.hasNoText (m_sErrorCode)) + throw new IllegalStateException ("Error Code is required"); + + final Ebms3Error aEbms3Error = new Ebms3Error (); + // Default to shortDescription if none provided + aEbms3Error.setDescription (m_aDescription); + aEbms3Error.setErrorDetail (m_sErrorDetail); + if (m_eCategory != null) + aEbms3Error.setCategory (m_eCategory.getDisplayName ()); + aEbms3Error.setRefToMessageInError (m_sRefToMessageInError); + aEbms3Error.setErrorCode (m_sErrorCode); + aEbms3Error.setOrigin (m_sOrigin); + aEbms3Error.setSeverity (m_eSeverity.getSeverity ()); + aEbms3Error.setShortDescription (m_sShortDescription); + return aEbms3Error; + } +} diff --git a/phase4-lib/src/main/java/com/helger/phase4/error/IEbmsError.java b/phase4-lib/src/main/java/com/helger/phase4/error/IEbmsError.java index 4e3ce9637..fd6c42136 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/error/IEbmsError.java +++ b/phase4-lib/src/main/java/com/helger/phase4/error/IEbmsError.java @@ -76,16 +76,52 @@ public interface IEbmsError @Nonnull EEbmsErrorCategory getCategory (); + /** + * Convert the EBMS Error into an {@link IError}. + * + * @param aContentLocale + * The locale used to resolve the error text, in case the text is + * multilingual. The locale may be ignored. + * @return The created {@link IError}. + */ @Nonnull + @Deprecated (forRemoval = true, since = "2.6.0") default IError getAsError (@Nonnull final Locale aContentLocale) { + return getAsError (null, aContentLocale); + } + + /** + * Convert the EBMS Error into an {@link IError}. + * + * @param sAdditionalErrorText + * An optional additional error text to be appended to the default + * text. May be null. + * @param aContentLocale + * The locale used to resolve the error text, in case the text is + * multilingual. The locale may be ignored. + * @return The created {@link IError}. + * @since 2.6.0 + */ + @Nonnull + default IError getAsError (@Nullable final String sAdditionalErrorText, @Nonnull final Locale aContentLocale) + { + String sErrorText = "[" + + getCategory ().getDisplayName () + + "] " + + StringHelper.getNotNull (getErrorDetail ().getDisplayText (aContentLocale), + getShortDescription ()); + if (StringHelper.hasText (sAdditionalErrorText)) + { + if (!sErrorText.endsWith (".")) + sErrorText += '.'; + sErrorText += sAdditionalErrorText; + } + return SingleError.builder () .errorLevel (getSeverity ().getErrorLevel ()) .errorID (getErrorCode ()) - .errorText ("[" + - getCategory ().getDisplayName () + - "] " + - StringHelper.getNotNull (getErrorDetail ().getDisplayText (aContentLocale), getShortDescription ())) + .errorText (sErrorText) .build (); } @@ -112,8 +148,9 @@ default Ebms3Error getAsEbms3Error (@Nonnull final Locale aContentLocale, return getAsEbms3Error (aContentLocale, sRefToMessageInError, sOrigin, - sErrorDescription == null ? null - : MessageHelperMethods.createEbms3Description (aContentLocale, sErrorDescription)); + sErrorDescription == null ? null : MessageHelperMethods.createEbms3Description ( + aContentLocale, + sErrorDescription)); } @Nonnull @@ -124,9 +161,9 @@ default Ebms3Error getAsEbms3Error (@Nonnull final Locale aContentLocale, { final Ebms3Error aEbms3Error = new Ebms3Error (); // Default to shortDescription if none provided - aEbms3Error.setDescription (aEbmsDescription != null ? aEbmsDescription - : MessageHelperMethods.createEbms3Description (aContentLocale, - getShortDescription ())); + aEbms3Error.setDescription (aEbmsDescription != null ? aEbmsDescription : MessageHelperMethods + .createEbms3Description (aContentLocale, + getShortDescription ())); aEbms3Error.setErrorDetail (getErrorDetail ().getDisplayText (aContentLocale)); aEbms3Error.setErrorCode (getErrorCode ()); aEbms3Error.setSeverity (getSeverity ().getSeverity ()); diff --git a/phase4-lib/src/main/java/com/helger/phase4/servlet/AS4IncomingHandler.java b/phase4-lib/src/main/java/com/helger/phase4/servlet/AS4IncomingHandler.java index 13e2a5e60..09d56396d 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/servlet/AS4IncomingHandler.java +++ b/phase4-lib/src/main/java/com/helger/phase4/servlet/AS4IncomingHandler.java @@ -488,19 +488,13 @@ private static void _processSoapHeaderElements (@Nonnull final SOAPHeaderElement final Locale aLocale = aState.getLocale (); for (final IError aError : aErrorList) { - final EEbmsError ePredefinedError = EEbmsError.getFromErrorCodeOrNull (aError.getErrorID ()); - if (ePredefinedError != null) - aErrorMessages.add (ePredefinedError.getAsEbms3Error (aLocale, sRefToMessageID)); - else - { - final Ebms3Error aEbms3Error = new Ebms3Error (); - aEbms3Error.setErrorDetail (aError.getErrorText (aLocale)); - aEbms3Error.setErrorCode (aError.getErrorID ()); - aEbms3Error.setSeverity (aError.getErrorLevel ().getID ()); - aEbms3Error.setOrigin (aError.getErrorFieldName ()); - aEbms3Error.setRefToMessageInError (sRefToMessageID); - aErrorMessages.add (aEbms3Error); - } + final Ebms3Error aEbms3Error = new Ebms3Error (); + aEbms3Error.setErrorDetail (aError.getErrorText (aLocale)); + aEbms3Error.setErrorCode (aError.getErrorID ()); + aEbms3Error.setSeverity (aError.getErrorLevel ().getID ()); + aEbms3Error.setOrigin (aError.getErrorFieldName ()); + aEbms3Error.setRefToMessageInError (sRefToMessageID); + aErrorMessages.add (aEbms3Error); } // Stop processing of other headers @@ -511,14 +505,14 @@ private static void _processSoapHeaderElements (@Nonnull final SOAPHeaderElement { // upon failure, the element stays unprocessed and sends back a signal // message with the errors - LOGGER.error ("Error processing SOAP header element " + aQName.toString () + " with processor " + aProcessor, - ex); - + final String sDetails = "Error processing SOAP header element " + + aQName.toString () + + " with processor " + + aProcessor; + LOGGER.error (sDetails, ex); aErrorMessages.add (EEbmsError.EBMS_OTHER.getAsEbms3Error (aState.getLocale (), aState.getMessageID (), - "Error processing SOAP header element " + - aQName.toString ())); - + sDetails)); // Stop processing of other headers break; } @@ -667,21 +661,21 @@ public static IAS4MessageState processEbmsMessage (@Nonnull @WillNotClose final (aEbmsError != null ? 1 : 0); if (nCountData != 1) { - final String sMsg = "Expected a UserMessage(" + - (aEbmsUserMessage != null ? 1 : 0) + - "), a PullRequest(" + - (aEbmsPullRequest != null ? 1 : 0) + - "), a Receipt(" + - (aEbmsReceipt != null ? 1 : 0) + - ") or an Error(" + - (aEbmsError != null ? 1 : 0) + - ")"; - LOGGER.error (sMsg); + final String sDetails = "Expected a UserMessage(" + + (aEbmsUserMessage != null ? 1 : 0) + + "), a PullRequest(" + + (aEbmsPullRequest != null ? 1 : 0) + + "), a Receipt(" + + (aEbmsReceipt != null ? 1 : 0) + + ") or an Error(" + + (aEbmsError != null ? 1 : 0) + + ")"; + LOGGER.error (sDetails); // send EBMS:0001 error back aErrorMessagesTarget.add (EEbmsError.EBMS_VALUE_NOT_RECOGNIZED.getAsEbms3Error (aLocale, aState.getMessageID (), - sMsg)); + sDetails)); } // Determine AS4 profile ID (since 0.13.0) diff --git a/phase4-lib/src/main/java/com/helger/phase4/servlet/AS4RequestHandler.java b/phase4-lib/src/main/java/com/helger/phase4/servlet/AS4RequestHandler.java index 52617f405..71a40627a 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/servlet/AS4RequestHandler.java +++ b/phase4-lib/src/main/java/com/helger/phase4/servlet/AS4RequestHandler.java @@ -847,9 +847,12 @@ private void _invokeSPIsForIncoming (@Nonnull final HttpHeaderMap aHttpHeaders, } catch (final AS4DecompressException ex) { - LOGGER.error ("Failed to decompress AS4 payload", ex); + final String sDetails = "Failed to decompress AS4 payload"; + LOGGER.error (sDetails, ex); // Hack for invalid GZip content from WSS4JAttachment.getSourceStream - aErrorMessagesTarget.add (EEbmsError.EBMS_DECOMPRESSION_FAILURE.getAsEbms3Error (m_aLocale, sMessageID)); + aErrorMessagesTarget.add (EEbmsError.EBMS_DECOMPRESSION_FAILURE.getAsEbms3Error (m_aLocale, + sMessageID, + sDetails)); return; } catch (final RuntimeException ex) diff --git a/phase4-lib/src/main/java/com/helger/phase4/servlet/soap/SOAPHeaderElementProcessorExtractEbms3Messaging.java b/phase4-lib/src/main/java/com/helger/phase4/servlet/soap/SOAPHeaderElementProcessorExtractEbms3Messaging.java index 661d3f3a3..8fb6a6886 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/servlet/soap/SOAPHeaderElementProcessorExtractEbms3Messaging.java +++ b/phase4-lib/src/main/java/com/helger/phase4/servlet/soap/SOAPHeaderElementProcessorExtractEbms3Messaging.java @@ -175,9 +175,10 @@ private static ESuccess _checkMPCOfPMode (@Nonnull final PModeLeg aPModeLeg, final String sPModeMPC = aPModeLeg.getBusinessInfo ().getMPCID (); if (sPModeMPC != null && !aMPCMgr.containsWithID (sPModeMPC)) { - LOGGER.error ("Error processing the usermessage, PMode-MPC ID '" + sPModeMPC + "' is invalid!"); + final String sDetails = "Error processing the usermessage, PMode-MPC ID '" + sPModeMPC + "' is invalid!"; + LOGGER.error (sDetails); - aErrorList.add (EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getAsError (aLocale)); + aErrorList.add (EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } } @@ -251,8 +252,9 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, final int nUserMessages = aMessaging.getUserMessageCount (); if (nUserMessages > 1) { - LOGGER.error ("Too many UserMessage objects (" + nUserMessages + ") contained."); - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "Too many UserMessage objects (" + nUserMessages + ") contained."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -260,16 +262,18 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, final int nSignalMessages = aMessaging.getSignalMessageCount (); if (nSignalMessages > 1) { - LOGGER.error ("Too many SignalMessage objects (" + nSignalMessages + ") contained."); - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "Too many SignalMessage objects (" + nSignalMessages + ") contained."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } if (nUserMessages + nSignalMessages == 0) { // No Message was found - LOGGER.error ("Neither UserMessage nor SignalMessage object contained."); - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "Neither UserMessage nor SignalMessage object contained."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -295,8 +299,9 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, if (aFromPartyIdList.size () > 1 || aToPartyIdList.size () > 1) { - LOGGER.error ("More than one PartyId is containted in From or To Recipient please check the message."); - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "More than one PartyId is containted in From or To Recipient please check the message."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -331,8 +336,9 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, // Should be screened by the XSD conversion already if (aPMode == null) { - LOGGER.error ("Failed to resolve PMode '" + sPModeID + "' using resolver " + m_aPModeResolver); - aErrorList.add (EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getAsError (aLocale)); + final String sDetails = "Failed to resolve PMode '" + sPModeID + "' using resolver " + m_aPModeResolver; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -356,8 +362,9 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, // both are present if (aPMode.getMEPBinding ().getRequiredLegs () == 2 && aPModeLeg2 == null) { - LOGGER.error ("Error processing the UserMessage, PMode does not contain leg 2."); - aErrorList.add (EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getAsError (aLocale)); + final String sDetails = "Error processing the UserMessage, PMode does not contain leg 2."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -366,8 +373,11 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, final int nLegNum = bUseLeg1 ? 1 : 2; if (aEffectiveLeg == null) { - LOGGER.error ("Error processing the UserMessage, PMode does not contain effective leg " + nLegNum + "."); - aErrorList.add (EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getAsError (aLocale)); + final String sDetails = "Error processing the UserMessage, PMode does not contain effective leg " + + nLegNum + + "."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_PROCESSING_MODE_MISMATCH.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -383,8 +393,11 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, aEffectiveMPC = aMPCMgr.getMPCOrDefaultOfID (sEffectiveMPCID); if (aEffectiveMPC == null) { - LOGGER.error ("Error processing the UserMessage, effective MPC ID '" + sEffectiveMPCID + "' is unknown!"); - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "Error processing the UserMessage, effective MPC ID '" + + sEffectiveMPCID + + "' is unknown!"; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } } @@ -397,8 +410,9 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, { if (bHasSoapBodyPayload) { - LOGGER.error ("No PayloadInfo/PartInfo is specified, so no SOAP body payload is allowed."); - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "No PayloadInfo/PartInfo is specified, so no SOAP body payload is allowed."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -406,8 +420,9 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, // attachments in the message if (aAttachments.isNotEmpty ()) { - LOGGER.error ("No PayloadInfo/PartInfo is specified, so no attachments are allowed."); - aErrorList.add (EEbmsError.EBMS_EXTERNAL_PAYLOAD_ERROR.getAsError (aLocale)); + final String sDetails = "No PayloadInfo/PartInfo is specified, so no attachments are allowed."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_EXTERNAL_PAYLOAD_ERROR.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } } @@ -416,12 +431,13 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, // Check if there are more Attachments then specified if (aAttachments.size () > aEbms3PayloadInfo.getPartInfoCount ()) { - LOGGER.error ("Error processing the UserMessage, the amount of specified attachments does not correlate with the actual attachments in the UserMessage. Expected " + - aEbms3PayloadInfo.getPartInfoCount () + - " but having " + - aAttachments.size () + - " attachments."); - aErrorList.add (EEbmsError.EBMS_EXTERNAL_PAYLOAD_ERROR.getAsError (aLocale)); + final String sDetails = "Error processing the UserMessage, the amount of specified attachments does not correlate with the actual attachments in the UserMessage. Expected " + + aEbms3PayloadInfo.getPartInfoCount () + + " but having " + + aAttachments.size () + + " attachments."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_EXTERNAL_PAYLOAD_ERROR.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -435,8 +451,9 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, // Check if there is a BodyPayload as specified in the UserMessage if (!bHasSoapBodyPayload) { - LOGGER.error ("Error processing the UserMessage. Expected a SOAPBody Payload but there is none present."); - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "Error processing the UserMessage. Expected a SOAPBody Payload but there is none present."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } } @@ -480,13 +497,13 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, final EAS4CompressionMode eCompressionMode = EAS4CompressionMode.getFromMimeTypeStringOrNull (sPropertyValue); if (eCompressionMode == null) { - LOGGER.error ("Error processing the UserMessage, CompressionType '" + - sPropertyValue + - "' of attachment '" + - sAttachmentID + - "' is not supported."); - - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "Error processing the UserMessage, CompressionType '" + + sPropertyValue + + "' of attachment '" + + sAttachmentID + + "' is not supported."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -501,14 +518,15 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, final Charset aCharset = CharsetHelper.getCharsetFromNameOrNull (sPropertyValue); if (aCharset == null) { - LOGGER.error ("Value '" + - sPropertyValue + - "' of property '" + - MessageHelperMethods.PART_PROPERTY_CHARACTER_SET + - "' of attachment '" + - sAttachmentID + - "' is not supported"); - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "Value '" + + sPropertyValue + + "' of property '" + + MessageHelperMethods.PART_PROPERTY_CHARACTER_SET + + "' of attachment '" + + sAttachmentID + + "' is not supported"; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } else @@ -524,11 +542,11 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, // got compressed if (bCompressionTypePresent && !bMimeTypePresent) { - LOGGER.error ("Error processing the UserMessage, MimeType for a compressed attachment ('" + - sAttachmentID + - "') is not present."); - - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "Error processing the UserMessage, MimeType for a compressed attachment ('" + + sAttachmentID + + "') is not present."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } } @@ -539,13 +557,13 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, // This may also be an indicator for "external payloads" if (nSpecifiedAttachments != aAttachments.size ()) { - LOGGER.error ("Error processing the UserMessage: the amount of specified attachments does not correlate with the actual attachments in the UserMessage. Expected " + - aEbms3PayloadInfo.getPartInfoCount () + - " but having " + - aAttachments.size () + - " attachments. This is an indicator, that an external attached was provided."); - - aErrorList.add (EEbmsError.EBMS_EXTERNAL_PAYLOAD_ERROR.getAsError (aLocale)); + final String sDetails = "Error processing the UserMessage: the amount of specified attachments does not correlate with the actual attachments in the UserMessage. Expected " + + aEbms3PayloadInfo.getPartInfoCount () + + " but having " + + aAttachments.size () + + " attachments. This is an indicator, that an external attached was provided."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_EXTERNAL_PAYLOAD_ERROR.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } } @@ -574,10 +592,10 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, final IMPC aMPC = aMPCMgr.getMPCOfID (sMPC); if (aMPC == null) { - LOGGER.error ("Failed to resolve the PullRequest MPC '" + sMPC + "'"); - // Return value not recognized when MPC is not currently saved - aErrorList.add (EEbmsError.EBMS_VALUE_NOT_RECOGNIZED.getAsError (aLocale)); + final String sDetails = "Failed to resolve the PullRequest MPC '" + sMPC + "'"; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_NOT_RECOGNIZED.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -601,9 +619,9 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, if (aPMode == null) { - LOGGER.error ("Failed to resolve PMode for PullRequest with MPC '" + sMPC + "'"); - - aErrorList.add (EEbmsError.EBMS_VALUE_NOT_RECOGNIZED.getAsError (aLocale)); + final String sDetails = "Failed to resolve PMode for PullRequest with MPC '" + sMPC + "'"; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_NOT_RECOGNIZED.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } } @@ -613,9 +631,9 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, final String sRefToMessageID = aSignalMessage.getMessageInfo ().getRefToMessageId (); if (StringHelper.hasNoText (sRefToMessageID)) { - LOGGER.error ("The Receipt does not contain a RefToMessageId"); - - aErrorList.add (EEbmsError.EBMS_INVALID_RECEIPT.getAsError (aLocale)); + final String sDetails = "The Receipt does not contain a RefToMessageId"; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_INVALID_RECEIPT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } } @@ -634,7 +652,9 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc, if (false) if (StringHelper.hasNoText (aError.getRefToMessageInError ())) { - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "The Error does not contain a RefToMessageInError"; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } } diff --git a/phase4-lib/src/main/java/com/helger/phase4/servlet/soap/SOAPHeaderElementProcessorWSS4J.java b/phase4-lib/src/main/java/com/helger/phase4/servlet/soap/SOAPHeaderElementProcessorWSS4J.java index a005222e7..e3bfa7f29 100644 --- a/phase4-lib/src/main/java/com/helger/phase4/servlet/soap/SOAPHeaderElementProcessorWSS4J.java +++ b/phase4-lib/src/main/java/com/helger/phase4/servlet/soap/SOAPHeaderElementProcessorWSS4J.java @@ -256,9 +256,6 @@ private ESuccess _verifyAndDecrypt (@Nonnull final Document aSOAPDoc, } catch (final IndexOutOfBoundsException | IllegalStateException | WSSecurityException ex) { - // Decryption or Signature check failed - LOGGER.error ("Error processing the WSSSecurity Header", ex); - /** * Error processing the WSSSecurity Header * @@ -313,17 +310,21 @@ private ESuccess _verifyAndDecrypt (@Nonnull final Document aSOAPDoc, * */ + // Decryption or Signature check failed + final String sDetails = "Error processing the WSSSecurity Header"; + LOGGER.error (sDetails, ex); // TODO we need a way to differentiate signature and decrypt // WSSecurityException provides no such thing - aErrorList.add (EEbmsError.EBMS_FAILED_DECRYPTION.getAsError (aLocale)); + aErrorList.add (EEbmsError.EBMS_FAILED_DECRYPTION.getAsError (sDetails + ": " + ex.getMessage (), aLocale)); aState.setSoapWSS4JException (ex); return ESuccess.FAILURE; } catch (final IOException ex) { // Decryption or Signature check failed - LOGGER.error ("IO error processing the WSSSecurity Header", ex); - aErrorList.add (EEbmsError.EBMS_OTHER.getAsError (aLocale)); + final String sDetails = "IO error processing the WSSSecurity Header"; + LOGGER.error (sDetails, ex); + aErrorList.add (EEbmsError.EBMS_OTHER.getAsError (sDetails + ": " + ex.getMessage (), aLocale)); aState.setSoapWSS4JException (ex); return ESuccess.FAILURE; } @@ -371,12 +372,13 @@ public ESuccess processHeaderElement (@Nonnull final Document aSOAPDoc, final ECryptoAlgorithmSign eSignAlgo = ECryptoAlgorithmSign.getFromURIOrNull (sAlgorithm); if (eSignAlgo == null) { - LOGGER.error ("Error processing the Security Header, your signing algorithm '" + - sAlgorithm + - "' is incorrect. Expected one of the following '" + - Arrays.toString (ECryptoAlgorithmSign.values ()) + - "' algorithms"); - aErrorList.add (EEbmsError.EBMS_FAILED_AUTHENTICATION.getAsError (aLocale)); + final String sDetails = "Error processing the Security Header, your signing algorithm '" + + sAlgorithm + + "' is incorrect. Expected one of the following '" + + Arrays.toString (ECryptoAlgorithmSign.values ()) + + "' algorithms"; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_FAILED_AUTHENTICATION.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } if (LOGGER.isDebugEnabled ()) @@ -389,10 +391,12 @@ public ESuccess processHeaderElement (@Nonnull final Document aSOAPDoc, final ECryptoAlgorithmSignDigest eSignDigestAlgo = ECryptoAlgorithmSignDigest.getFromURIOrNull (sAlgorithm); if (eSignDigestAlgo == null) { - LOGGER.error ("Error processing the Security Header, your signing digest algorithm is incorrect. Expected one of the following'" + - Arrays.toString (ECryptoAlgorithmSignDigest.values ()) + - "' algorithms"); - aErrorList.add (EEbmsError.EBMS_FAILED_AUTHENTICATION.getAsError (aLocale)); + final String sDetails = "Error processing the Security Header - the signing digest algorithm is incorrect." + + " Expected one of the following algorithms: '" + + Arrays.toString (ECryptoAlgorithmSignDigest.values ()) + + "'"; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_FAILED_AUTHENTICATION.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -412,32 +416,35 @@ public ESuccess processHeaderElement (@Nonnull final Document aSOAPDoc, String sAttachmentID = aAttachments.get (i).getHeaders ().get (AttachmentUtils.MIME_HEADER_CONTENT_ID); if (StringHelper.hasNoText (sAttachmentID)) { - LOGGER.error ("The provided attachment ID in the 'Content-ID' header may not be empty."); - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "The provided attachment ID in the 'Content-ID' header may not be empty."; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } // Starts with ""? if (!sAttachmentID.endsWith (WSS4JAttachment.CONTENT_ID_SUFFIX)) { - LOGGER.error ("The provided attachment ID '" + - sAttachmentID + - "' in the 'Content-ID' header does not end with the required suffix '" + - WSS4JAttachment.CONTENT_ID_SUFFIX + - "'"); - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "The provided attachment ID '" + + sAttachmentID + + "' in the 'Content-ID' header does not end with the required suffix '" + + WSS4JAttachment.CONTENT_ID_SUFFIX + + "'"; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } @@ -452,12 +459,13 @@ public ESuccess processHeaderElement (@Nonnull final Document aSOAPDoc, .getHref (); if (!sHref.contains (sAttachmentID)) { - LOGGER.error ("The usermessage part information '" + - sHref + - "' does not reference the respective attachment ID '" + - sAttachmentID + - "'"); - aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (aLocale)); + final String sDetails = "The usermessage part information '" + + sHref + + "' does not reference the respective attachment ID '" + + sAttachmentID + + "'"; + LOGGER.error (sDetails); + aErrorList.add (EEbmsError.EBMS_VALUE_INCONSISTENT.getAsError (sDetails, aLocale)); return ESuccess.FAILURE; } }