diff options
author | 2018-10-10 17:07:15 +0100 | |
---|---|---|
committer | 2018-10-10 17:07:15 +0100 | |
commit | fbcc34c30ba2eacaaced5629c730a3bd4b9515c6 (patch) | |
tree | 35ae586dc90c2d4747983ee52c005a1baeb92e4f /src/main/java/org/onap/crud/service/JaxrsEchoService.java | |
parent | b83cf59d4b741c9faa2c3086115f8b01ed5a724a (diff) |
Return X-TransactionId header in REST response
If the transaction ID is not provided the reverse-proxy creates it.
This ensures that the transaction ID is provided back to the client.
Change-Id: I033a23bbb3920e264a51322a81f23ad220e59d34
Issue-ID: AAI-1732
Signed-off-by: Michael Arrastia <MArrasti@amdocs.com>
Diffstat (limited to 'src/main/java/org/onap/crud/service/JaxrsEchoService.java')
-rw-r--r-- | src/main/java/org/onap/crud/service/JaxrsEchoService.java | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/src/main/java/org/onap/crud/service/JaxrsEchoService.java b/src/main/java/org/onap/crud/service/JaxrsEchoService.java index dc01435..671b2fd 100644 --- a/src/main/java/org/onap/crud/service/JaxrsEchoService.java +++ b/src/main/java/org/onap/crud/service/JaxrsEchoService.java @@ -28,6 +28,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.UriInfo; import org.onap.aai.cl.api.Logger; @@ -39,23 +40,29 @@ import org.springframework.stereotype.Component; @Path("/services/gizmo/v1/echo-service/") public class JaxrsEchoService { - private static Logger logger = LoggerFactory.getInstance() - .getLogger(JaxrsEchoService.class.getName()); - private static Logger auditLogger = LoggerFactory.getInstance() - .getAuditLogger(JaxrsEchoService.class.getName()); - - @GET - @Path("echo/{input}") - @Produces("text/plain") - public String ping(@PathParam("input") String input, - @Context HttpHeaders headers, - @Context UriInfo info, - @Context HttpServletRequest req) { - - LoggingUtil.initMdcContext(req, headers); - LoggingUtil.logRestRequest(logger, auditLogger, req, Response.status(Status.OK) - .entity("OK").build()); - - return "Hello, " + input + "."; - } -}
\ No newline at end of file + private static Logger logger = LoggerFactory.getInstance().getLogger(JaxrsEchoService.class.getName()); + private static Logger auditLogger = LoggerFactory.getInstance().getAuditLogger(JaxrsEchoService.class.getName()); + + public static final String TRANSACTIONID_HEADER = "X-TransactionId"; + + @GET + @Path("echo/{input}") + @Produces("text/plain") + public Response ping(@PathParam("input") String input, @Context HttpHeaders headers, @Context UriInfo info, + @Context HttpServletRequest req) { + + LoggingUtil.initMdcContext(req, headers); + + ResponseBuilder responseBuilder = Response.status(Status.OK).entity("Hello, " + input + "."); + + String txId = headers.getHeaderString(TRANSACTIONID_HEADER); + if (txId != null) { + responseBuilder.header(TRANSACTIONID_HEADER, txId); + } + + Response response = responseBuilder.build(); + LoggingUtil.logRestRequest(logger, auditLogger, req, response); + + return response; + } +} |