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!
Asked
Active
Viewed 1,972 times
2

azrosen92
- 8,357
- 4
- 26
- 45
2 Answers
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");

rmeakins
- 1,309
- 8
- 13
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");

Suzana
- 4,251
- 2
- 28
- 52
-
please change `X-Requestid` to `X-Request-ID` just not to make confusion – bkalcho Dec 23 '21 at 12:00