⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 callhelloworld.java

📁 《Master EJB 第二版》
💻 JAVA
字号:
package examples;

import java.security.*;
import javax.naming.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;

/**
 * This is a helper class that knows how to call a
 * "Hello, World!" bean.  It does so in a secure manner,
 * automatically propagating the logged in security context
 * to the J2EE server.
 */
public class CallHelloWorld implements PrivilegedAction {
 
 /*
  * This is our one business method.  It performs an action
  * securely, and returns application-specific results.
  */
 public Object run() {
  String result = "Error";
  try {
   /*
    * Make a bean
    */
   Context ctx = new InitialContext(System.getProperties());
   Object obj = ctx.lookup("HelloHome");
   HelloHome home = (HelloHome)
    PortableRemoteObject.narrow(obj, HelloHome.class);
   Hello hello = home.create();

   /*
    * Call a business method, propagating the security context
    */
   result = hello.hello();
  }
  catch (Exception e) {
   e.printStackTrace();
  }
  
  /*
   * Return the result to the client
   */
  return result;
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -