Accessing Apache's unique_id from java code
Asked Answered
B

2

2

I need to access the mod_unique_id attribute for a request to my apache server. Is there a way to do that in the java code, something like request.UNIQUE_ID? I read through this already and couldn't find anything, I also didn't entirely understand the article, so I may have missed something. If anyone could clear this up for me, that would be great!

Battled answered 26/6, 2013 at 14:42 Comment(0)
P
3

You could add the UNIQUE_ID as a request header

Apache config:

    RequestHeader set UNIQUE_ID "%{UNIQUE_ID}e"

Then write some Java code to read this header:

    request.getHeader("UNIQUE_ID");
Playlet answered 5/11, 2013 at 4:13 Comment(0)
C
2

in /etc/apache2/apache2.conf:

<IfModule unique_id_module>
    SetEnvIf X-Requestid "^$" no_request_id
    RequestHeader set X-Requestid %{UNIQUE_ID}e env=no_request_id
</IfModule>
  • add the symlink in modes-enabled:
    unique_id.load -> ../mods-available/unique_id.load
  • in the shell, execute sudo a2enmod headers
  • restart apache

in Java Code:

import javax.servlet.http.HttpServletRequest;
String uniqueId = request.getHeader("x-requestid");
Congenital answered 11/1, 2017 at 11:58 Comment(1)
please change X-Requestid to X-Request-ID just not to make confusionUltun

© 2022 - 2024 — McMap. All rights reserved.