Alachisoft NCache 4.1 - Online Documentation

NCache with Session Beans

 
This sample demonstrates the use of NCache with Session Beans, it uses EJB 3.0, you must be running Java EE 5 compatible application server. Following J2EE platforms are supported:
 
  • WebSphere
  • Web Logic
  • JBoss
 
 
Configuring Session Beans to use NCache:
 
You need to add reference to the required libraries in EJB module of the enterprise application.
 
 
Adding Libraries:
 
You need to add required libraries. You can find these Java libraries at following path. %INSTALL_PATH% is the location where NCache is installed. If you are using IDE just add references to these files in the project, if you are not using IDE then you need to copy these files to 'WEB-INF/lib' folder under the application root folder.
 
On Linux: %INSTALL_PATH%/ncache/lib/
On Windows: %INSTALL_PATH%/NCache/java/lib/
 
  • NCActivate.jar (The NCache java client library to validate licensing information)
  • NCClient.jar (The NCache java client library that actually implements NCache communication protocol)
  • NCacheSessionProvider.jar (The HTTP module implementation for session caching using NCache)
  • NCRuntime.jar (The NCache java client library that implements Read-through/Write-through caching and Cache Startup operations)
  • NCSerialization.jar (The NCache java client library that actually implements dynamic compact serialization and object sharing operations)
  • javassist.jar (The NCache java 3rd party library responsible for runtime code generation)
 
Add the following to 'classes' folder of your EJB module
 
  • javaReg.properties (The file containing licensing information. You can place this file under 'classes' directory of your web application)
 
 
Build application using NetBeans:
 
Follow the below mentioned steps to successfully build the project in NetBeans.
 
Windows:
 
  1. Open the project at the following location '%NCACHE_HOME%/samples/java/NetBeans/JavaAPIEJBTest' in the NetBeans environment.
  2. Under the Java EE Modules right click the JavaAPIEJBTest-war.war and open the project, project will now be added into the NetBeans projects list.
  3. Under the Java EE Modules right click the JavaAPIEJBTest-ejb.jar and open the project, project will now be added into the NetBeans projects list.
  4. Configure the application server for all the three projects by right clicking the project and opening the Properties --> Run and selecting the appropriate server with Java EE 5. The project will not build without the server selection.
  5. Make sure that 'JavaAPIEJBTest-ejb' project references the required 'NCClient.jar' and 'NCActivate.jar' files located at '%NCACHE_HOME%/java/lib/'.
  6. Add the 'javareg.Properties' file located at '%NCACHE_HOME%/java/lib/' in the default source package of the 'JavaAPIEJBTest-ejb' project.
  7. Build the JavaAPIEJBTest project, it will generate the 'JavaAPIEJBTest.ear' file in the following location:%NCACHE_HOME%/samples/java/NetBeans/JavaAPIEJBTest/JavaAPIEJBTest/dist
 
Linux:
 
  1. Open the project at the following location '%NCACHE_HOME%/samples/NetBeans/JavaAPIEJBTest' in the NetBeans environment.
  2. Under the Java EE Modules right click the JavaAPIEJBTest-war.war and open the project, project will now be added into the NetBeans projects list.
  3. Under the Java EE Modules right click the JavaAPIEJBTest-ejb.jar and open the project, project will now be added into the NetBeans projects list.
  4. Configure the application server for all the three projects by right clicking the project and opening the Properties --> Run and selecting the appropriate server with Java EE 5. The project will not build without the server selection.
  5. Make sure that 'JavaAPIEJBTest-ejb' project references the required 'NCClient.jar' and 'NCActivate.jar' files located at '%NCACHE_HOME%/lib/'.
  6. Add the 'javareg.Properties' file located at '%NCACHE_HOME%/lib/' in the default source package of the 'JavaAPIEJBTest-ejb' project.
  7. Build the JavaAPIEJBTest project, it will generate the 'JavaAPIEJBTest.ear' file in the following location%NCACHE_HOME%/samples/NetBeans/JavaAPIEJBTest/JavaAPIEJBTest/dist
 
 
Build application using Eclipse:
 
Follow the below mentioned steps to successfully build the project in Eclipse.
 
Windows:
 
  1. Import the project at the following location '%NCACHE_HOME%/samples/java/Eclipse/JavaAPIEJBTest' in the Eclipse environment.
  2. Import the project at the following location '%NCACHE_HOME%/samples/java/Eclipse/JavaAPIEJBTest/JavaAPIEJBTest-ejb' in the Eclipse environment.
  3. Import the project at the following location '%NCACHE_HOME%/samples/java/Eclipse/JavaAPIEJBTest/JavaAPIEJBTest-war' in the Eclipse environment.
  4. Configure the application server for all the three projects by right clicking the project and opening the Server and selecting the appropriate server with Java EE 5. The project will not build without the server selection.
  5. Make sure that 'JavaAPIEJBTest-ejb' project references the required 'NCClient.jar' and 'NCActivate.jar' files located at '%NCACHE_HOME%/java/lib/'.
  6. Add the 'javareg.Properties' file located at '%NCACHE_HOME%/java/lib/' in the default source package of the 'JavaAPIEJBTest-ejb' project.
  7. Right click the JavaAPIEJBTest project and select Validate.
  8. Right click the JavaAPIEJBTest project and select Export --> EAR File.
  9. Provide the following destination path for the EAR file and click finish.%NCACHE_HOME%/samples/java/Eclipse/JavaAPIEJBTest/JavaAPIEJBTest/dist
 
Linux:
 
  1. Import the project at the following location '%NCACHE_HOME%/samples/Eclipse/JavaAPIEJBTest' in the Eclipse environment.
  2. Import the project at the following location '%NCACHE_HOME%/samples/Eclipse/JavaAPIEJBTest/JavaAPIEJBTest-ejb' in the Eclipse environment.
  3. Import the project at the following location '%NCACHE_HOME%/samples/Eclipse/JavaAPIEJBTest/JavaAPIEJBTest-war' in the Eclipse environment.
  4. Configure the application server for all the three projects by right clicking the project and opening the Server and selecting the appropriate server with Java EE 5. The project will not build without the server selection.
  5. Make sure that 'JavaAPIEJBTest-ejb' project references the required 'NCClient.jar' and 'NCActivate.jar' files located at '%NCACHE_HOME%/lib/'.
  6. Add the 'javareg.Properties' file located at '%NCACHE_HOME%/lib/' in the default source package of the 'JavaAPIEJBTest-ejb' project.
  7. Right click the JavaAPIEJBTest project and select Validate.
  8. Right click the JavaAPIEJBTest project and select Export --> EAR File.
  9. Provide the following destination path for the EAR file and click finish.%NCACHE_HOME%/samples/Eclipse/JavaAPIEJBTest/JavaAPIEJBTest/dist
 
 
Deploying Application:
 
By default this sample application uses 'mycache', So make sure that cache 'mycache' exist in the 'client.ncconf' file located at '%INSTALL_PATH%/config/' with correct server IP Address and this cache should be started. %INSTALL_PATH% is location where NCache is installed. Following is an example of how the 'client.ncconf' should look like.
 
<?xml version = "1.0" encoding = "UTF-8"?>
<configuration>
<ncache-server connection-retries = "5" retry-interval = "1" client-request-timeout = "90" connection-timeout = "5" port = "9800"/>
<cache id = "mycache" client-cache-id = "" client-cache-syncmode = "optimistic" load-balance = "true">
<server name = "20.200.20.41"/>
<!-- This is the server IP Address where mycache is running -->
</cache>
</configuration>
 
 
Windows:
 
Follow the below mentioned steps to deploy application on the respected server.
 
WebLogic:
 
For the following steps %WEBLOGIC_HOME% refers to the location where WebLogic is installed. %DOMAIN_NAME% is the domain already created on the server. %NCACHE_HOME% refers to the location where NCache is installed.
 
  1. Move the 'JavaAPIEJBTest.ear' file located at '%NCACHE_HOME%/ samples/java/bin' to the directory '%JBOSS_HOME%/server/default/deploy' .
  2. Open the web browser and try to access the following URL:
 
http://host:port/JavaAPIEJBTest-war/index.jsp
 
Where 'host' will be the address/IP of the machine where JBoss is installed in case of local machine it should be 'localhost', and 'port' where JBoss is listening the request. The default port for JBoss is 8080.
 
WebSphere:
 
For the following steps %WEBSPHERE_HOME% refers to the location where WebSphere is installed and %NCACHE_HOME% refers to the location where NCache is installed.
 
  1. If WebSphere is installed properly, you will be able to access the admin console through browser with the help of the following URL:  http://ip-address:port/ibm/console/. By default, 9060 is the port used by WAS. Make sure that your are using the correct port if you changed it during installation.
  2. You can go to Applications --> New Application --> New Enterprise Application.
  3. Specify the path of the 'JavaAPIEJBTest.ear' file and click Next. You can locate the 'JavaAPIEJBTest.ear' file at the following location'%NCACHE_HOME%/samples/java/bin'
  4. Select Fast Path installation mode and click Next.
  5. Specify the Application Name and Application Directory and click Next. Both Application Name and Application Directory should be 'JavaAPIEJBTest'.
  6. Map the application to the server, Select 'JavaAPIEJBTest-ejb.jar' and 'JavaAPIEJBTest-war.war' from the list with the default settings and click Next.
  7. Map the application to the virtual host, Select 'JavaAPIEJBTest-war.war' from the list with the default settings and click Next.
  8. Click the Finish button to complete the deployment.
  9. Go to Applications --> Application Types --> WebSphere enterprise applications.
  10. You should see the 'JavaAPIEJBTest' application in the list, select the 'JavaAPIEJBTest' application by clicking on the checkbox and press the start button at the top left; you should see a green icon showing that application has started.
  11. Open the web browser and try to access the following URL:http://host:port/JavaAPIEJBTest-war/index.jsp
    Where 'host' will be the address/IP of the machine where WebSphere is installed in case of local machine it should be 'localhost', and 'port' where WebSphere is listening the request. Make sure that you are using the correct port. The default port for WebSphere is 9080.
 
JBoss:
 
For the following steps %JBOSS_HOME% refers to the location where JBoss is installed and %NCACHE_HOME% refers to the location where NCache is installed.
 
1. Move the 'JavaAPIEJBTest.ear' file located at '%NCACHE_HOME%/ samples/java/bin' to the directory '%JBOSS_HOME%/server/default/deploy'.
 
2. Open the web browser and try to access the following url:
 
http://host:port/JavaAPIEJBTest-war/index.jsp
 
where 'host' will be the address/IP of the machine where JBoss is installed in case of local machine it should be 'localhost'.
and 'port' where JBoss is listening the request. Make sure that you are using the correct port. The default port for JBoss is 8080.
 
 
Linux:
 
Follow the below mentioned steps to deploy application on the respected server.
 
WebLogic:
 
For the following steps %WEBLOGIC_HOME% refers to the location where WebLogic is installed. %DOMAIN_NAME% is the domain already created on the server. %NCACHE_HOME% refers to the location where NCache is installed.
 
  1. Move the 'JavaAPIEJBTest.ear' file located at '%NCACHE_HOME%/ samples/bin' to the directory '%JBOSS_HOME%/server/default/deploy'.
  2. Open the web browser and try to access the following URL:
    http://host:port/JavaAPIEJBTest-war/index.jsp
    Where 'host' will be the address/IP of the machine where JBoss is installed in case of local machine it should be 'localhost', and 'port' where JBoss is listening the request. The default port for JBoss is 8080.
 
JBoss:
 
For the following steps %JBOSS_HOME% refers to the location where JBoss is installed and %NCACHE_HOME% refers to the location where NCache is installed.
 
  1. Move the 'JavaAPIEJBTest.ear' file located at '%NCACHE_HOME%/ samples/bin' to the directory '%JBOSS_HOME%/server/default/deploy'.
  2. Open the web browser and try to access the following URL:
    http://host:port/JavaAPIEJBTest-war/index.jsp
    where 'host' will be the address/IP of the machine where JBoss is installed in case of local machine it should be 'localhost'.
    and 'port' where JBoss is listening the request. Make sure that you are using the correct port. The default port for JBoss is 8080.
 
 
See Also

 
Copyright © 2005-2012 Alachisoft. All rights reserved.