From 0f4a0f74cda892ab08b44bb2e3681b58a104ef71 Mon Sep 17 00:00:00 2001 From: Philip Helger Date: Tue, 7 May 2024 09:25:38 +0200 Subject: [PATCH] Make sure at least on error message is contained --- .../phase4/servlet/AS4RequestHandler.java | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) 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 82fd9fee1..1237554a4 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 @@ -666,8 +666,9 @@ private void _invokeSPIsForIncoming (@Nonnull final HttpHeaderMap aHttpHeaders, "Only one of User OR Signal Message may be present"); final boolean bIsUserMessage = aEbmsUserMessage != null; - final String sMessageID = bIsUserMessage ? aEbmsUserMessage.getMessageInfo ().getMessageId () - : aEbmsSignalMessage.getMessageInfo ().getMessageId (); + final String sMessageID = bIsUserMessage ? aEbmsUserMessage.getMessageInfo ().getMessageId () : aEbmsSignalMessage + .getMessageInfo () + .getMessageId (); // Get all processors final ICommonsList aAllProcessors = m_aProcessorSupplier.get (); @@ -723,23 +724,30 @@ private void _invokeSPIsForIncoming (@Nonnull final HttpHeaderMap aHttpHeaders, if (aProcessingErrorMessages.isNotEmpty () || aResult.isFailure ()) { - if (aProcessingErrorMessages.isNotEmpty ()) + if (aResult.isFailure () && aProcessingErrorMessages.isEmpty ()) { - if (LOGGER.isDebugEnabled ()) - LOGGER.debug ("AS4 message processor " + - aProcessor + - " had processing errors - breaking. Details: " + - aProcessingErrorMessages); + // For 2.7.6 - make sure that at least one processing error + // message is contained + aProcessingErrorMessages.add (EEbmsError.EBMS_OTHER.errorBuilder (m_aLocale) + .errorDetail ("An undefined generic error occurred") + .build ()); + } - if (aResult.isSuccess ()) - LOGGER.warn ("Processing errors are present but success was returned by a previous AS4 message processor " + - aProcessor + - " - considering the whole processing to be failed instead"); + if (LOGGER.isDebugEnabled ()) + LOGGER.debug ("AS4 message processor " + + aProcessor + + " had processing errors - breaking. Details: " + + aProcessingErrorMessages); - aEbmsErrorMessagesTarget.addAll (aProcessingErrorMessages); - } + if (aResult.isSuccess ()) + LOGGER.warn ("Processing errors are present but success was returned by a previous AS4 message processor " + + aProcessor + + " - considering the whole processing to be failed instead"); + + aEbmsErrorMessagesTarget.addAll (aProcessingErrorMessages); // Stop processing + aSPIResult.setSuccess (false); return; } @@ -883,8 +891,8 @@ private void _invokeSPIsForResponse (@Nonnull final IAS4MessageState aState, byte [] aResponsePayload = null; if (aResponseFactory != null) { - final HttpEntity aRealHttpEntity = aHttpEntity != null ? aHttpEntity - : aResponseFactory.getHttpEntityForSending (aMimeType); + final HttpEntity aRealHttpEntity = aHttpEntity != null ? aHttpEntity : aResponseFactory.getHttpEntityForSending ( + aMimeType); if (aRealHttpEntity.isRepeatable ()) { int nContentLength = (int) aRealHttpEntity.getContentLength (); @@ -1632,9 +1640,8 @@ private IAS4ResponseFactory _handleSoapMessage (@Nonnull final HttpHeaderMap aHt new ResponseHandlerXml ()); } AS4HttpDebug.debug ( () -> "SEND-RESPONSE [async sent] received: " + - (aAsyncResponse == null ? "null" - : XMLWriter.getNodeAsString (aAsyncResponse, - AS4HttpDebug.getDebugXMLWriterSettings ()))); + (aAsyncResponse == null ? "null" : XMLWriter.getNodeAsString (aAsyncResponse, + AS4HttpDebug.getDebugXMLWriterSettings ()))); }; final CompletableFuture aFuture = PhotonWorkerPool.getInstance () @@ -1851,8 +1858,8 @@ public void handleRequest (@Nonnull @WillClose final InputStream aServletRequest if (aResponder != null) { // Response present -> send back - final IAS4OutgoingDumper aRealOutgoingDumper = m_aOutgoingDumper != null ? m_aOutgoingDumper - : AS4DumpManager.getOutgoingDumper (); + final IAS4OutgoingDumper aRealOutgoingDumper = m_aOutgoingDumper != null ? m_aOutgoingDumper : AS4DumpManager + .getOutgoingDumper (); aResponder.applyToResponse (aHttpResponse, aRealOutgoingDumper); } else