📄 appstestclient1.java
字号:
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("java:comp/env/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. }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -