AppsTestClient1.java~1~
上传用户:jnhyscl
上传日期:2010-03-08
资源大小:345k
文件大小:2k
- package web;
- import shiponline.*;
- import javax.naming.*;
- import java.util.Properties;
- import javax.rmi.PortableRemoteObject;
- public class AppsTestClient1 extends Object {
- private AppsHome appsHome = null;
- //Construct the EJB test client
- public AppsTestClient1() {
- initialize();
- }
- public void initialize() {
- try {
- //get naming context
- Context context = getInitialContext();
- //look up jndi name
- Object ref = context.lookup("Apps");
- //look up jndi name and cast to Home interface
- appsHome = (AppsHome) PortableRemoteObject.narrow(ref, AppsHome.class);
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- private Context getInitialContext() throws Exception {
- String hostname="fanhua02";
- String url = "iiop://fanhua02:9090";
- String user ="Guest";
- String password ="GuestPassword";
- Properties properties = null;
- try {
- properties = new Properties();
- properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sybase.ejb.InitialContextFactory");
- properties.put(Context.PROVIDER_URL, url);
- properties.put(Context.SECURITY_PRINCIPAL, user);
- properties.put(Context.SECURITY_CREDENTIALS, password);
- Thread curr=Thread.currentThread();
- ClassLoader l=curr.getContextClassLoader();
- ClassLoader c=l;
- java.net.URL classPath = new java.net.URL("http",hostname,8080,"/classes/");
- curr.setContextClassLoader(java.net.URLClassLoader.newInstance(new java.net.URL[]{classPath},l));
- return new InitialContext(properties);
- }
- catch(Exception e) {
- throw e;
- }
- }
- //----------------------------------------------------------------------------
- // Utility Methods
- //----------------------------------------------------------------------------
- public AppsHome getHome() {
- return appsHome;
- }
- //Main method
- public static void main(String[] args) {
- AppsTestClient1 client = new AppsTestClient1();
- // Use the getHome() method of the client object to call Home interface
- // methods that will return a Remote interface reference. Then
- // use that Remote interface reference to access the EJB.
- }
- }