title: How to determine whether an EJB call is from a remote or local client
body: <p>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).</p>
  
  <p>The code runs on Weblogic 12c servers and use RMI for method invocations.</p>
  
  <p>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.</p>
  
  <p>When the cursor is obtained it is used subsequently to request the underlying data (another call).</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>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).</p>
  
  <p>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.</p>
  
  <p>I tried RemoteServer.getClientHost() but it always throws the exception there is no connection.</p>
  
  <p>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).</p>
  
  <p>So the question is:</p>
  
  <p><strong>Is there a generic way to find out in an EJB interceptor that the origin of the call was from a different system</strong></p>