I'm late to the party, but I had this same issue working with Java 8.
This is what worked for me, on the HttpServletRequest request
object.
request.getHeader("origin");
and
request.getHeader("referer");
How I came to that conclusion:
I have a java app running on http://localhost:3000 making a Http Post to another java app I have running on http://localhost:8080.
From the Java code running on http://localhost:8080 I couldn't get the http://localhost:3000 from the HttpServletRequest using the answers above. For me using the getHeader
method with the correct string input worked.
request.getHeader("origin")
gave me "http://localhost:3000" which is what I wanted.
request.getHeader("referer")
gave me "http://localhost:3000/xxxx" where xxxx is full URL I have from the requesting app.