If the EJB exposes the @Remote interface, but you enter the EJB bean instead of your remote interface, will this cause a remote or local call?

I have an EJB bean that works with two interfaces, as shown below: The local interface for my web application, and the remote interface for my App Client

@Stateless public class CoreMainEJB implements CoreMainEJBRemote, CoreMainEJBLocal { //... } 

so my app client is as follows. In this case, the remote method is called.

 public class Main { @EJB private static CoreMainEJBRemote coreEJBRemote; public static void main(String[] args) { coreEJBRemote.process(args[0]); } } 

From my web application, I call as shown below. In this case, the local method is called.

 @ManagedBean @RequestScoped public class DisplayInbound { @EJB private CoreMainEJBLocal coreMainEJBLocal; public void processPackages() { coreMainEJBLocal.process(...); } } 

So, here is my question: If EJB only opened the @Remote interface, but in your web application you enter the EJB bean directly, and not its remote interface, will this cause a remote call or a local call? For instance:

 @Stateless public class CoreMainEJB implements CoreMainEJBRemote{ //... } 

and in a web application, I do it

 @EJB private CoreMainEJB coreMainEJB; public void processPackages() { coreMainEJB.process(...); //Is this local or remote invocation here? } 
+4
source share
2 answers

The last example just doesn't work. Since CoreMainEJB already implements a remote interface, the container will not create a view without an interface. This is exactly the case @LocalBean .

So, to answer the question "Is this a local or remote call here?" directly: it is not. The container will not be able to enter anything and may be disconnected during the deployment phase.

If you define your bean as:

 @Stateless @LocalBean public class CoreMainEJB implements CoreMainEJBRemote{ //... } 

Then local semantics will be applied here:

 @EJB private CoreMainEJB coreMainEJB; public void processPackages() { coreMainEJB.process(...); // Local semantics } 

(assuming the above code snippet is in the same application as CoreMainEJB )

+5
source

A call without an interface is a local call.

+4
source

All Articles