java – Passage value at the injected EJB

I have an EJB application consisting of two beans, Bean1 and Bean2, where Bean2 is injected into Bean1.

Bean1 receives HTTP requests from the browser, calls a method in Bean2, gets the result, and sends the HTTP response.

In addition, Bean1 has access to HttpSession object, where the user ID of the logged in user is stored. Bean2 does NOT have access to the HttpSession object.

The application should record the messages (with the help of sl4j / logback, for example). It could log the message in the Bean1 or Bean2 methods and, when it records a message, it must include the user ID of the session in the journal entry.

Since Bean2 does not have the user IDhe must get it from Bean1. The question is what is the best way to achieve this? What I do not want to do is add a user ID field to each method in Bean2, because there is a lot of Bean1 and Bean2 in the application, and it is not maintainable. All suggestions will be welcome.

@Path ("someurl")
@Produces ({MediaType.APPLICATION_JSON})
@Consumes ({MediaType.APPLICATION_JSON})
Public class Bean1 {

@The context
HttpServletRequest httpRequest;

private haricot bean2;

public Response someMethod1 () {
final session HttpSession = httpRequest.getSession ();
// get the user ID of the session

String s = bean2.someMethod2 ();

// return the answer


public class Bean2 {

public String someMethod2 () {
// ....
return "something";