精通ejb(8)

王朝other·作者佚名  2008-05-31
窄屏简体版  字體: |||超大  

精通ejb(8)

例子代码

rmi-iiop ejb客户端例子

A Java RMI-IIOP client with a proprietary EJB server.

package com.wiley.compBooks.roman.corba.helloworld;

import javax.ejb.*;

import javax.naming.*;

import javax.rmi.*;

import java.util.Properties;

import javax.transaction.UserTransaction;

/**

* This class is an example of client code that invokes

* methods on a simple stateless session bean.

*/

public class RMIClient {

public static void main(String[] args) {

try {

/*

* Get System properties for JNDI initialization

*/

Properties props = System.getProperties();

/*

* Use JNDI to look up the home object

*/

Context ctx = new InitialContext(props);

HelloHome home = (HelloHome)

javax.rmi.PortableRemoteObject.narrow(

ctx.lookup("HelloHome"),

HelloHome.class);

/*

* Use JNDI to look up the JTA

* UserTransaction interface

*/

UserTransaction userTran = (UserTransaction)

ctx.lookup("javax.transaction.UserTransaction");

/*

* Start the transaction

*/

userTran.begin();

/*

* Use the home object to create the Hello EJB Object

*/

Hello hello = home.create();

/*

* Call the hello() method, and print it

*/

System.out.println(hello.hello());

/*

* Done with EJB Object, so remove it

*/

hello.remove();

/*

* Commit the transaction

*/

userTran.commit();

} catch (Exception e) {

e.printStackTrace();

}

}

}

Example RMI-IIOP EJB client

A CORBA client with a CORBA-based EJB server.

package com.wiley.compBooks.roman.corba.helloworld;

import java.util.*;

import org.omg.CosNaming.*;

import org.omg.CosTransactions.*;

public class CORBAClient {

public static void main(String[] args) throws Exception {

/*

* Initialize the ORB.

*

* A more portable way to do this is:

*

* Properties p = new Properties();

* p.put("org.omg.CORBA.ORBClass", <..ORB class..>);

* org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, p);

*/

org.omg.CORBA.ORB orb = com.inprise.ejb.Global.orb();

/*

* Get a reference to a naming context

*/

NamingContext context = NamingContextHelper.narrow

(orb.resolve_initial_references("NameService"));

/*

* Look up the home object using COS Naming

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航