I would like to capture the user's IP address when downloading a bitstream from dspace. I have successfully captured the user's "Full name" by using this code:
EPerson loggedin = context.getCurrentUser();
String eperson = null;
if (loggedin != null)
{
eperson = loggedin.getFullName();
}
else eperson = "Anonymous";
Now, I would also like to capture the IP address like those seen from the Control panel > Current Activity. Please advise on how can I achieve this and what methods should I use?
EDIT: I will implement this in the cover page feature (available in DSpace 5, xmlui), where the user's IP address will be displayed if the user did not log in or is an anonymous user (eg Download by [User's IP address]) when downloading the PDF. Example of PDF with cover page from Taylor and Francis. Note the first line in the articles' cover page: This article was downloaded by: [your IP address].
Please note that I have very limited knowledge in java and will gladly appreciate any suggestions and help.
Thanks in advance.
UPDATE
I tried using the answer from this post but when I do an mvn build, I'm having this error:
method getClientIpAddr in class CoverPage cannot be applied to given types;
[ERROR] required: javax.servlet.http.HttpServletRequest
[ERROR] found: no arguments
Would really appreciate if you can help me with this, and I deleted my answer to this post because it will return the external IP of the server and not the client's IP address.