From 3a4f6fcd96a901f8839de2075f77840854a3d7ee Mon Sep 17 00:00:00 2001 From: Alejandro Revilla Date: Wed, 16 May 2018 20:35:29 -0300 Subject: [PATCH] return BAD_REQUEST on transaction manager ABORT Error details should be available in the TM's Context --- .../main/java/org/jpos/qrest/SendResponse.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modules/qrest/src/main/java/org/jpos/qrest/SendResponse.java b/modules/qrest/src/main/java/org/jpos/qrest/SendResponse.java index a05f78d4da..1c01bfe7e4 100644 --- a/modules/qrest/src/main/java/org/jpos/qrest/SendResponse.java +++ b/modules/qrest/src/main/java/org/jpos/qrest/SendResponse.java @@ -23,10 +23,13 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.*; +import org.jpos.rc.Result; import org.jpos.transaction.AbortParticipant; import org.jpos.transaction.Context; import java.io.Serializable; +import java.util.LinkedHashMap; +import java.util.Map; import static io.netty.buffer.Unpooled.copiedBuffer; import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE; @@ -77,6 +80,8 @@ private FullHttpResponse error (HttpResponseStatus rc) { private FullHttpResponse getResponse (Context ctx) { Object r = ctx.get(RESPONSE); FullHttpResponse httpResponse; + + if (r instanceof FullHttpResponse) { httpResponse = (FullHttpResponse) r; } else if (r instanceof Response) { @@ -102,10 +107,13 @@ private FullHttpResponse getResponse (Context ctx) { ctx.log(e); httpResponse = error(HttpResponseStatus.INTERNAL_SERVER_ERROR); } - } else - httpResponse = error(HttpResponseStatus.NOT_FOUND); - + } else { + Result result = ctx.getResult(); + if (result.hasFailures()) { + httpResponse = error(HttpResponseStatus.BAD_REQUEST); + } else + httpResponse = error(HttpResponseStatus.NOT_FOUND); + } return httpResponse; } } -