4

Can you pass some data from a javax.servlet.Filter to a Jersey endpoint without using ThreadLocal or HttpSession?

And because the first question will be "why do you want to do this?": mostly curious. In practice I think I could use this to pass some data generated during authentication to the endpoint. Not using ThreadLocal eliminates the temptation to use that down the chain (hope there's no need to explain why that's evil) and not using HttpSession is more of a quirk :)

Cristian Vrabie
  • 3,972
  • 5
  • 30
  • 49

1 Answers1

7

Try injecting with @Context. I'm not sure what object you will receive though (somewhere I saw WebServiceContext, which is jax-ws), but it should contain the HttpServletRequest. so you will be a able to set request attributes in the filter and read them in the rest service

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 1
    Ah. Cool. Basically use HttpServletRequest.setAttribute. I don't know why but I was under the impression that these go to HttpSession? – Cristian Vrabie Apr 05 '11 at 13:17
  • Nice. Then I can write a @Provider to give me the data as a parameter in the endpoint. – Cristian Vrabie Apr 05 '11 at 13:35
  • 2
    For whomever wants to do the provider, I found this useful: http://codahale.com/what-makes-jersey-interesting-injection-providers/ (don't forget that you can inject stuff like HttpContext or HttpServletRequest with @Context inside the provider itself) – Cristian Vrabie Apr 06 '11 at 19:18