Access the SessionContext

The SessionContext may be used to perform lookups, manage Transactions, access the Timer Service, ...

@Resource
private SessionContext sessionContext;

To see if the SessionContext was correctly injected, I've added a simple trace in the greetMe Method :

public String greetMe(String me) {
    System.out.println("Message received: " + me + "n");

if (sessionContext != null) { System.out.println("SessionContext was injected by EasyBeans."); } return "Hello " + me; }

We will check with the output :

PostConstruct called by EasyBeans
Method 'greetMe' invoked 1 times.
Entering method : greetMe
Message received: Guillaume

EJBContext was injected by Easybeans. <---------- Here Leaving method : greetMe PreDestroy called by EasyBeans.

Access the WebServiceContext

The WebServiceContext is a Resource that can be accessed/injected like all other Resources : through an annotated field or setter :

@Resource
private WebServiceContext wsContext;

A simple check (simmilar to the one for SessionContext) has been added in the greetMe method.

Output :

PostConstruct called by EasyBeans
Method 'greetMe' invoked 1 times.
Entering method : greetMe
Message received: Guillaume

SessionContext was injected by Easybeans. WebServiceContext was injected by Celtix. <------------- Here Leaving method : greetMe PreDestroy called by EasyBeans.

Celtix is responsible for WebServiceContext injection.
EasyBeans ignores that @Resource when encountered !