Enterprise Java Beans (EJB) specification includes remote client and local client views. In some cases, your Java application may need to have session and entity beans with local home and component interfaces and in other cases with remote ones.
Let’s clarify which interface to choose and when to choose it.
A local client view is good for cases when you are ensured that other EJBs and clients will only request your bean within a single JVM. Such access will be given by direct method calls, instead of RMI (remote method invocation). It also makes sense to use local clients for beans associated with each other.
Your EJB needs a remote client view when you are going to use this bean in distributed environments, i.e. when your client is located on the other Java Virtual Machine. RMI will handle all the methods’ calls from the remote home and/or component interface. We also recommend to use remote access client view for passed by value parameters, between the bean and the client application.
Of course, the final decision depends on your application’s qualities.
Today we’ll focus on how an EJB remote client works with Java Bean deployed to Jelastic ZEROCodeChange PaaS. This tutorial has been prepared for those readers who have some knowledge of Enterprise Java Beans technology.
1. As usual we start with creating an environment for our application. Log into your Jelastic account and click Create environment.
2. Select GlassFish server and specify the resource amount your Java EE application needs. Then switch on Public IP for the server for further connection from client application to EJB.
Wait a few minutes to see your environment, available from the dashboard.
3. To find your Public IP, expand your environment list and click on the additional button for GlassFish.
1. Firstly, create the directory where you plan to place your Enterprise Java Beans and client application files.
2. Create your Session Bean, which will be invoked by a remote client application to access an application that is deployed on the server. Session Bean performs work for the client by executing business tasks inside the server.
3. After that you have to create the EJB interface, it’s required for the beans which are accessed by remote clients. Here’s the example:
4. Compile your EJB module and package it into the .ear file for further deployment.
5. Create remote client application to access your bean. Here’s an example, which connects to EJB remotely via GlassFish Public IP and calls method getName(), which returns data to the client:
Note: Jelastic works with gfcluster only, so all of the port numbers include an additional number 2 at the beginning.
Our test EAR package can be downloaded here.
1. Go back to the Jelastic dashboard and upload your .ear to the Deployment manager.
2. Deploy the archive to the environment you’ve created earlier.
3. Once your application is successfully deployed, run your client application to check the results.
We hope the above article will provide useful guidelines for you. Of course these are not all of the nuances of remote interfaces usage, they are just the basics. If you need more details just let me know I’ll be happy to share my experience with you.