Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass caller's info from web tier to EJB tier?

In our enterprise application there are Service tier (EJB3.0 including business logic and database access) and Web tier (Servlet/JSP). Seperated ear and war are deployed in JBoss AS 7 in distributed machines.

Service tier contains both Stateful and Stateless EJB.

We have EJB interceptor for methods invoking. For user that logged in from the Web tier the user info is saved in HttpSession (user validation is simply processed by query his account & password in DB).

Now the performance tuning needs to know which user has called those EJB methods, the user info, date info etc. These will be extracted and logged or stored in DB for our anylize.

Now my question is:

How to distinguish the caller's info in EJB tier?

The EJB interceptor can get the EJB method's parameters and when it's called. But we don't know who has called it.

We know it's ugly to combine EJB tier with Web tier. So we won't pass HttpSession/HttpRequest to EJB layer even that may help to get what we need from the Session/Request object.

And there are so many EJB methods that we can not pass an TuningInfo(include request info, user info etc) as parameter from web to every EJB method.

Is it possible to get the caller's info in EJB tier?

Thanks in advance.

like image 539
bradkevin Avatar asked Nov 12 '22 20:11

bradkevin


1 Answers

If Web layer and EJB layer is on the same JVM, the you can pass the user information via thread local. http://javacodesamples.wordpress.com/2012/07/11/understanding-the-concept-behind-threadlocal/

like image 167
Cris Avatar answered Nov 15 '22 11:11

Cris