0

How to get referrer URL from ContainerRequestContext object.

Please find the code snippet below,

public void filter(ContainerRequestContext requestContext) {
   ApplicationUser user = (ApplicationUser) CacheManagerBase.getInstance().getApplicationUserCache().getCurrentUser();
   requestContext.setSecurityContext(new UserContext(user));
}
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720

2 Answers2

5

There's a couple of different options, but the simplest is

String referrer = requestContext.getHeaderString("referer");

That might return null if the header isn't set.

sisyphus
  • 6,174
  • 1
  • 25
  • 35
  • Thanks for the reply. In my case i got to make it more secured and i got to take the actual referrer using the REST jersey framework and inturn J2EE, instead of me sending the referrer and fetching it. – Balaji Sudharsanam Jan 28 '16 at 04:08
0

Referer will not be available in all the cases, mentioned in the POST below,

In what cases will HTTP_REFERER be empty

Community
  • 1
  • 1