From 990ff6d9128ed6a8badf9f7cb609889ad774449a Mon Sep 17 00:00:00 2001 From: GDLMadushanka Date: Thu, 2 Nov 2023 08:34:58 +0530 Subject: [PATCH] Introduce base error code and protocol state Introduce base error code and protocol state to fault message context. fixes wso2/micro-integrator/issues/3014 --- .../core/src/main/java/org/apache/synapse/FaultHandler.java | 4 ++++ .../src/main/java/org/apache/synapse/SynapseConstants.java | 5 +++++ .../apache/synapse/core/axis2/SynapseCallbackReceiver.java | 4 ++++ .../synapse/transport/passthru/PassThroughConstants.java | 5 +++++ .../synapse/transport/passthru/TargetErrorHandler.java | 4 ++++ 5 files changed, 22 insertions(+) diff --git a/modules/core/src/main/java/org/apache/synapse/FaultHandler.java b/modules/core/src/main/java/org/apache/synapse/FaultHandler.java index 8bdb309e70..743f9bc86a 100644 --- a/modules/core/src/main/java/org/apache/synapse/FaultHandler.java +++ b/modules/core/src/main/java/org/apache/synapse/FaultHandler.java @@ -90,6 +90,10 @@ public void handleFault(MessageContext synCtx, Exception e) { if (traceOrDebugOn) { traceOrDebugWarn(traceOn, "ERROR_CODE : " + synCtx.getProperty(SynapseConstants.ERROR_CODE)); + traceOrDebugWarn(traceOn,"BASE_ERROR_CODE : " + + synCtx.getProperty(SynapseConstants.BASE_ERROR_CODE)); + traceOrDebugWarn(traceOn,"PROTOCOL_STATE_ON_FAILURE : " + + synCtx.getProperty(SynapseConstants.PROTOCOL_STATE_ON_FAILURE)); traceOrDebugWarn(traceOn, "ERROR_MESSAGE : " + synCtx.getProperty(SynapseConstants.ERROR_MESSAGE)); traceOrDebugWarn(traceOn, "ERROR_DETAIL : " + diff --git a/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java b/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java index 07c061e189..7568257aac 100644 --- a/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java +++ b/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java @@ -227,6 +227,11 @@ public static final class Axis2Param { public static final String SENDING_FAULT = "SENDING_FAULT"; /** The message context property name which holds the error code for the last encountered exception */ public static final String ERROR_CODE = "ERROR_CODE"; + /** The message context property name which holds the error code for the last encountered exception + * without any protocol state specific alterations*/ + public static final String BASE_ERROR_CODE = "BASE_ERROR_CODE"; + /** The message context property name which holds the http protocol state upon a failure*/ + public static final String PROTOCOL_STATE_ON_FAILURE = "PROTOCOL_STATE_ON_FAILURE"; /** The MC property name which holds the error message for the last encountered exception */ public static final String ERROR_MESSAGE = "ERROR_MESSAGE"; /** The message context property name which holds the error detail (stack trace) for the last encountered exception */ diff --git a/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java b/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java index a0882554a3..77f234583a 100644 --- a/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java +++ b/modules/core/src/main/java/org/apache/synapse/core/axis2/SynapseCallbackReceiver.java @@ -320,6 +320,10 @@ private void handleMessage(String messageID ,MessageContext response, synapseOutMsgCtx.setProperty(SynapseConstants.SENDING_FAULT, Boolean.TRUE); synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_CODE, response.getProperty(SynapseConstants.ERROR_CODE)); + synapseOutMsgCtx.setProperty(SynapseConstants.BASE_ERROR_CODE, + response.getProperty(SynapseConstants.BASE_ERROR_CODE)); + synapseOutMsgCtx.setProperty(SynapseConstants.PROTOCOL_STATE_ON_FAILURE, + response.getProperty(SynapseConstants.PROTOCOL_STATE_ON_FAILURE)); synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_MESSAGE, response.getProperty(SynapseConstants.ERROR_MESSAGE)); synapseOutMsgCtx.setProperty(SynapseConstants.ERROR_DETAIL, diff --git a/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughConstants.java b/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughConstants.java index 6497fa51fd..3770b963b2 100644 --- a/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughConstants.java +++ b/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/PassThroughConstants.java @@ -75,6 +75,11 @@ public class PassThroughConstants { public static final String SENDING_FAULT = "SENDING_FAULT"; /** The message context property name which holds the error code for the last encountered exception */ public static final String ERROR_CODE = "ERROR_CODE"; + /** The message context property name which holds the error code for the last encountered exception + * without any protocol state specific alterations*/ + public static final String BASE_ERROR_CODE = "BASE_ERROR_CODE"; + /** The message context property name which holds the http protocol state upon a failure*/ + public static final String PROTOCOL_STATE_ON_FAILURE = "PROTOCOL_STATE_ON_FAILURE"; /** The MC property name which holds the error message for the last encountered exception */ public static final String ERROR_MESSAGE = "ERROR_MESSAGE"; /** The message context property name which holds the error detail (stack trace) for the last encountered exception */ diff --git a/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetErrorHandler.java b/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetErrorHandler.java index 765ebe6862..381d5537eb 100644 --- a/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetErrorHandler.java +++ b/modules/transports/core/nhttp/src/main/java/org/apache/synapse/transport/passthru/TargetErrorHandler.java @@ -135,6 +135,10 @@ public void run() { if (errorCode != -1) { faultMessageContext.setProperty( PassThroughConstants.ERROR_CODE, getErrorCode(errorCode, state)); + faultMessageContext.setProperty( + PassThroughConstants.BASE_ERROR_CODE, errorCode); + faultMessageContext.setProperty( + PassThroughConstants.PROTOCOL_STATE_ON_FAILURE, state.ordinal()); } if (exceptionToRaise != null) { faultMessageContext.setProperty(