Wim Veldhuis February 2016

How to determine whether an EJB call is from a remote or local client

I have an interesting problem. We have a number of EJB's that are called both by local code (via local interface) and by client code (via remote interface).

The code runs on Weblogic 12c servers and use RMI for method invocations.

The system is in development already for many years, and along others implements browser functionality around user defined cursors (a kind of handle for a result set). There are already many calls to obtain such a cursor for various data types.

When the cursor is obtained it is used subsequently to request the underlying data (another call).

In our case we want to know whether the call is done from local code or from a remote client. We want to know this so we can preload the first n items, and thus reduce the number of calls to our server. Each call has an overhead of about 20ms, which we want to avoid.

The remote client code is generic (the cursor is wrapped in a kind of list) and could easily be adjusted to handle the preloaded data.

The local callers also call these EJB methods to obtain a cursor, but usually use other functionality to handle the cursor (wrapping in iterators, joins, etc). So they would become a lot more complex if they had to handle the preloading (and they often do not need it).

So we want to make an interceptor to do preloading of data in the cursor, but only if the call is made from a remote client. So far we could not find a way of doing so.

I tried RemoteServer.getClientHost() but it always throws the exception there is no connection.

I searched if the SessionContext could be extended with a field/value to be set by the caller to identify the remote client, but could find anything about doing this. (We have a homemade wrapper for the service interface which could be extended of inserting such information in a context).

So the question is:

Is there a generic way to find out in an EJB interceptor that the origin of t

Answers


Boris Pavlović February 2016

If the remote client uses any kind of authentication there should be some info in the security context about the principal which can be used to differentiate. Otherwise, before finding a better solution new Throwable().getStackTrace() returns an array of all callers. There must be a method upstream that could tell if the call is local or it's been done via remote call.

Post Status

Asked in February 2016
Viewed 3,132 times
Voted 10
Answered 1 times

Search




Leave an answer