Skip to content

Commit

Permalink
Merge pull request #2197 from IsuruMaduranga/issue#3358
Browse files Browse the repository at this point in the history
Fix failing of requeue on rollback if auth endpoint gives 401
  • Loading branch information
chanikag authored Jul 15, 2024
2 parents 0fa1973 + 070716e commit 79b38e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public void send(MessageContext synCtx) {
}

// Clone the original MessageContext and save it to do a retry after a token refresh
MessageContext cloneMessageContext = MessageHelper.cloneMessageContext(synCtx);
MessageCache.getInstance().addMessageContext(synCtx.getMessageID(), cloneMessageContext);
MessageContext clonedMessageContext = MessageHelper.cloneMessageContext(synCtx);
MessageCache.getInstance().addMessageContext(synCtx.getMessageID(), clonedMessageContext);

super.send(synCtx);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,10 @@ public void send(EndpointDefinition endpointDefinition, MessageContext synapseIn

if (originalMC != null && OAuthUtils.retryOnOAuthFailure(httpEndpoint, synapseInMsgCtx,
synapseInMsgCtx)) {
MessageContext messageContext = httpEndpoint.retryCallWithNewToken(originalMC);
((Axis2MessageContext) synapseInMsgCtx).setAxis2MessageContext(
((Axis2MessageContext) messageContext).getAxis2MessageContext());
originalMC.getEnvelope().build();

resetMessageContext((Axis2MessageContext) synapseInMsgCtx, (Axis2MessageContext) originalMC);
httpEndpoint.retryCallWithNewToken(synapseInMsgCtx);
}
}

Expand All @@ -489,6 +490,19 @@ public void send(EndpointDefinition endpointDefinition, MessageContext synapseIn
}
}

private static void resetMessageContext(Axis2MessageContext synapseInMsgCtx, Axis2MessageContext originalMC) throws AxisFault {
// Replace envelope and headers with original envelope and headers before retrying
org.apache.axis2.context.MessageContext originalAxisMC =
originalMC.getAxis2MessageContext();

org.apache.axis2.context.MessageContext synapseInAxisMC =
synapseInMsgCtx.getAxis2MessageContext();

synapseInAxisMC.setEnvelope(originalAxisMC.getEnvelope());
synapseInAxisMC.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS,
originalAxisMC.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS));
}

private void sendRobust(org.apache.axis2.context.MessageContext axisOutMsgCtx,
Options clientOptions, AxisService anonymousService,
ServiceContext serviceCtx, MessageContext synapseInMsgCtx) throws AxisFault {
Expand Down

0 comments on commit 79b38e4

Please sign in to comment.