Originally posted by sarah Marsh:
If I have Tomcat and Weblogic on the same machine, when servlet/JSP call the EJB, we should use Local or Remote interface?
What if Tomcat and Weblogic sitting on different machine but with network connection?
This is a great case for using the Business Delegate
pattern. Instead of clients looking up a local or remote interface and using it directly, they get a delegate from a Service Locator. For this case, you basically take the local interface and use it as the base delegate interface. The local delegate implementation simply proxies the call to the local object. The remote implementation should do the same but catch RemoteException and throw a different exception that is already listed in the throws (or is added to the base interface).
This way the clients don't have to know whether they have a local or remote object. The Service Locator decides either via configuration or at runtime which one to give to the client, but both implementations have the same interface.
Here's an simple example:
Of course you'll need to provide the code to look up the EJBs in each implementation, but you already need that.