I am using a Jetty 11 server which has a GET method called getObject().
When I receive a request on the server, I want to add a custom header to create a unique identify for the request. So I am trying to add something like x-request-id
with value obtained using UUID into the header.
I tried doing a pseudo search in the header itself using -
final String requestId;
if (!StringUtil.isEmpty(request.getHeader("request-id")) && !StringUtil.isEmpty(request.getHeader("request-id"))) {
requestId = request.getHeader(request.getHeader("request-id"));
}
else {
requestId = UUID.randomUUID().toString().toUpperCase(); //.replace("-", "");
}
request.setAttribute("Request-ID", requestId);
System.out.println("requestId - " + requestId);
But this does not seem to get added into the header of the request.
My ultimate target is to forward this request outside the server with this x-request-id
as my request switched the environment. Once I receive a response, I want to do some lookup on this request later.
My method looks like this -
public void handle(String target, Request jettyReq, HttpServletRequest request, HttpServletResponse response) {
// Redirect API control based on HTTP method type
if (request.getMethod().equals(constGetRequest)) {
doGetObject(jettyReq, request, response);
}
jettyReq.setHandled(true);
}
How do I achieve this with the HttpServletRequest
request in jetty?