java - Centralizing getting of a session variable in a Jersey REST resource -


problem definition

I am changing a legacy app to use a restore API Where each method is required data from a session variable (I know that this is not actually a RES application, but it is legacy code).

I would like to keep the code DRY, so I tried to set the session variable in the constructor, but the HttpServletRequest is not ready during the construction. I can use the user < / Code> want to set the variable What is the right way to do this?

code sample

  @ path ("/ some resources") public classes someResource {@Conestext HttpServletRequest currentRequest; Private user user = null; Public SomeResource () {// // it does not work // session session = currentRequest.getSession (); // user = (user) session.getAttribute ("user"); } @GET @Produces (...) @PermitAll @Path (...) Read Public Search BIID (...) {Http session session = currentRequest.getSession (); User user = (user) session.getAttribute ("user"); ...} @GET @Produces (...) @PermitAll @Path (...) Find public bible read (...) {HTP session session = current. request. Session); User user = (user) session.getAttribute ("user"); ...} @GET @Produces (...) @PermitAll @Path (...) Find some resources public (all) ({...} {HTP session session = present. request. Session); User user = (user) session.getAttribute ("user"); ...} ... many other paths, etc ... checking each user session variable}  

API.

"Security information for a request is available by injection.

Hopes


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -