HP Integrity NonStop J-Series User Manual

Page 82

Advertising
background image

Creating Test class to Test the RMI service

1.

Create a com.hp.empinfo.domain package and an RmiClientTest class under it, as
described in

“Creating the Controller for EmpInfo” (page 54)

.

2.

Modify the RmiClientTest.java file to invoke the RMI service by adding the following
code:

package com.hp.empinfo.domain;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.hp.empinfo.service.EmployeeInfo;

public class RmiClientTest {

public static String [] configFileNames = new String [] {"applicationContext.xml","clientContext.xml"};
private static ApplicationContext applicationContext = null;

public static void main(String[] args) {
applicationContext = new ClassPathXmlApplicationContext(configFileNames);
EmployeeInfo empInfo = (EmployeeInfo)applicationContext.getBean("rmiProxy");
Employee employee = empInfo.getEmployee(2);

System.out.println("Employee First Name : "+employee.getFirstname());
System.out.println("Employee Last Name : "+employee.getLastname());
System.out.println("Employee Email : "+employee.getEmail());
System.out.println("Employee Id : "+employee.getEmpid());

}

}

Creating the clientContext.xml file

1.

Create the clientContext.xml file in the EmpInfo/WebContent/WEB-INF/ directory,
as described in

“Creating the EmpInfo-servlet.xml File” (page 48)

.

2.

Modify the clientContext.xml file to add the RMI client bean. After modification, the
clientContext.xml

file must appear as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">

<beans>

<!-- Resolves ${...} placeholders from client.properties -->
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location"><value>classpath:client.properties</value></property>
</bean>

<bean id="rmiProxy" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl">
<value>rmi://${serverName}:${rmiPort}/empDetail</value>
</property>
<property name="serviceInterface">
<value>com.hp.empinfo.service.EmployeeInfo</value>
</property>

</bean>
</beans>

Creating the client.properties file

1.

Create the client.properties file in the EmpInfo/WebContent/WEB-INF/ directory,
as described in

“Creating the jdbc.properties File” (page 66)

.

2.

Modify the client.properties file to add the NonStop System IP address (where your
RMI service is running) and the RMI port number.

serverName= <HP NonStop System IP Address>
rmiPort=<port number>

Adding Dependency JARs

Add the following dependency jars to the EmpInfo project library:

82

Spring Framework

Advertising
This manual is related to the following products: