Skip to content

Commit

Permalink
Merge pull request #2220 from malakaganga/fix_json_nf
Browse files Browse the repository at this point in the history
Remove JSON Stream when JsonSyntaxException occurs
  • Loading branch information
malakaganga authored Oct 7, 2024
2 parents 15a5b06 + bca7b22 commit 54546e3
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.apache.synapse.SynapseLog;
import org.apache.synapse.aspects.flow.statistics.collectors.RuntimeStatisticCollector;
import org.apache.synapse.aspects.flow.statistics.data.artifact.ArtifactHolder;
import org.apache.synapse.commons.json.Constants;
import org.apache.synapse.config.SynapsePropertiesLoader;
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.core.axis2.Axis2MessageContext;
Expand All @@ -54,7 +55,11 @@ public abstract class AbstractListMediator extends AbstractMediator
implements ListMediator {

private static final String MSG_BUILD_FAILURE_EXCEPTION_PATTERN = ".*(Wstx)(.*Exception)" +
"|.*MalformedJsonException|.*(synapse\\.commons\\.staxon\\.core)|.*(com\\.fasterxml\\.jackson\\.core)";
"|.*MalformedJsonException|.*(synapse\\.commons\\.staxon\\.core)|.*(com\\.fasterxml\\.jackson\\.core)" +
"|.*JsonSyntaxException";

private static final String ORG_APACHE_SYNAPSE_COMMONS_JSON_IS_JSON_OBJECT =
"org.apache.synapse.commons.json.JsonInputStream.IsJsonObject";

// Create a Pattern object
protected Pattern msgBuildFailureExpattern = Pattern.compile(MSG_BUILD_FAILURE_EXCEPTION_PATTERN);
Expand Down Expand Up @@ -274,6 +279,13 @@ private void consumeInputOnOmException(MessageContext synCtx) {
} catch (AxisFault axisFault) {
log.error("Exception while consuming the input stream on Om Exception", axisFault);
}
//removing JSONstream from the message Context since it is outdated.
org.apache.axis2.context.MessageContext axis2MessageContext =
((Axis2MessageContext) synCtx).getAxis2MessageContext();
axis2MessageContext.removeProperty(Constants.ORG_APACHE_SYNAPSE_COMMONS_JSON_JSON_INPUT_STREAM);
axis2MessageContext.removeProperty(ORG_APACHE_SYNAPSE_COMMONS_JSON_IS_JSON_OBJECT);
//Clearing the buffered input stream when there is an build exception occurred.
axis2MessageContext.setProperty(PassThroughConstants.BUFFERED_INPUT_STREAM, null);
SOAPEnvelope soapEnvelope;
if (synCtx.isSOAP11()) {
soapEnvelope = OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope();
Expand Down

0 comments on commit 54546e3

Please sign in to comment.