利用 WebSphere Process Server 7 轻松定做属于自己的 EJB service
2010-05-21 00:00:00 来源:WEB开发网图 8. 生成 Dynamic Web Project
按照下图所示配置该动态 Web Project:
图 9. 配置 Dynamic Web Project
在生成的 Java Resources/src 文件夹下,新建一个 Java 类 “EJBExportInvoker”, 并写入如下代码以调用前面所创建的 EJB3.0 Remote Export Binding:
清单 2. EJB Export Invoker Class 的代码片断
try{
String jndiName = "
li1627uc14075ejb3remotewsdltwowayexport.ejb3remotetwoway.binding.EJB3RemoteTwoWayRemote
";
Context initialContext = newInitialContext();
java.lang.Object ejbBusIntf = initialContext.lookup(jndiName);
System.out.println(ejbBusIntf);
System.out.println(ejbBusIntf.getClass());
System.out.println(ejbBusIntf.getClass().getName());
EJB3RemoteTwoWay busI = (EJB3RemoteTwoWay) javax.rmi.PortableRemoteObject
.narrow(ejbBusIntf, EJB3RemoteTwoWay.class);
System.out.println(busI);
System.out.println(busI.getClass());
System.out.println(busI.getClass().getName());
Customer customer = newCustomer();
customer.setCustId("custId-" + input);
customer.setEmail("email-" + input);
Address address = newAddress();
address.setAddressId("addressId-" + input);
address.setAddressType(newInteger(100));
customer.setHomeAddress(address);
Customer response = busI.e3Remotetwoway(customer);
if(response != null) {
if(customer.getCustId().equals(response.getCustId())
&& customer.getEmail().equals(response.getEmail())
&& (response.getHomeAddress() != null&& (customer
.getHomeAddress().getAddressId().equals(
response.getHomeAddress().getAddressId()) && customer
.getHomeAddress().getAddressType().equals(
response.getHomeAddress().getAddressType())))) {
System.out.println("@@@@@@@@@@@Response success!");
} else{
System.out.println(response.getCustId());
System.out.println(response.getEmail());
System.out.println(response.getHomeAddress().getAddressId());
System.out.println(response.getHomeAddress().getAddressType());
}
} else{
System.out.println("@@@@@@@@@@@@@@response is null!!!");
}
System.out.println("===================>> end of client");
} catch(NamingException e) {
e.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
}
更多精彩
赞助商链接