How to return EJB context data back to client in JBoss EAP 7.1
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 7.1
Issue
- How to return EJB context data back to client in JBoss EAP 7.1
Resolution
Apply CP4 or later as there was a bug.
The EJB Client Interceptor calls EJBClientInvocationContext.addReturnedContextDataKey to specify the context data keys that the client wants returned. Then when the Client Interceptor handleInvocationResult is invoked, the data can be retrieved with context.getContextData().get(...)
public class ClientInterceptor implements EJBClientInterceptor {
@Override
public void handleInvocation(EJBClientInvocationContext context) throws Exception {
context.addReturnedContextDataKey("returnData1");
context.addReturnedContextDataKey("returnData2");
context.getContextData().put("clientData", DATA);
// Must make this call
context.sendRequest();
}
@Override
public Object handleInvocationResult(EJBClientInvocationContext context) throws Exception {
Object result = context.getResult(); //in case there was an exception
// to check the returned data, context.getResult() must be called first
Object returnData1 = context.getContextData().get("returnData1");
Object returnData2 = context.getContextData().get("returnData2");
// The result could be modified or changed before sending back to the client
return result;
}
}
SBR
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.