use of io.narayana.lra.client.Current in project narayana by jbosstm.
the class ServerLRAFilter method filter.
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
// a request is leaving the container so clear any context on the thread and fix up the LRA response header
Object suspendedLRA = Current.getState("suspendedLRA");
Object newLRA = Current.getState("newLRA");
URL current = Current.peek();
try {
if (current != null) {
int status = responseContext.getStatus();
Response.Status.Family[] cancel0nFamily = (Response.Status.Family[]) requestContext.getProperty(CANCEL_ON_FAMILY_PROP);
Response.Status[] cancel0n = (Response.Status[]) requestContext.getProperty(CANCEL_ON_PROP);
Boolean closeCurrent = (Boolean) requestContext.getProperty(TERMINAL_LRA_PROP);
if (closeCurrent == null)
closeCurrent = false;
if (cancel0nFamily != null)
if (Arrays.stream(cancel0nFamily).anyMatch(f -> Response.Status.Family.familyOf(status) == f))
closeCurrent = true;
if (cancel0n != null && !closeCurrent)
if (Arrays.stream(cancel0n).anyMatch(f -> status == f.getStatusCode()))
closeCurrent = true;
if (closeCurrent) {
lraTrace(requestContext, (URL) newLRA, "ServerLRAFilter after: closing LRA becasue http status is " + status);
lraClient.cancelLRA(current);
if (current.equals(newLRA))
// don't try to cancle newKRA twice
newLRA = null;
}
}
if (newLRA != null) {
lraTrace(requestContext, (URL) newLRA, "ServerLRAFilter after: closing LRA");
lraClient.closeLRA((URL) newLRA);
}
if (responseContext.getStatus() == Response.Status.OK.getStatusCode() && NarayanaLRAClient.isAsyncCompletion(resourceInfo.getResourceMethod())) {
LRALogger.i18NLogger.warn_lraParticipantqForAsync(resourceInfo.getResourceMethod().getDeclaringClass().getName(), resourceInfo.getResourceMethod().getName(), Response.Status.ACCEPTED.getStatusCode(), Response.Status.OK.getStatusCode());
}
} finally {
if (suspendedLRA != null)
Current.push((URL) suspendedLRA);
Current.updateLRAContext(responseContext.getHeaders());
Current.popAll();
}
}
Aggregations