论坛首页 入门技术论坛

简单EJB客户端调用的问题

浏览 3599 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2007-09-05  
写好了一个EJB并且也部署到了jboss下面,部署成功,简单说下组成
远程接口 Hello interface 定义了一个业务方法 public String hello()
本地接口 HelloLocal interface 和远程接口一样 public String hello()
Home接口 HelloHome interface
本地Home接口 HelloLocalHome interface
发布到jboss服务器底下成功
客户端代码如下
import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.rmi.*;
import java.util.*;

//import myejb.*;
import examples.HelloHome;
import examples.Hello;

class  HelloClientTest
{
    public static void main(String[] args) throws Exception {
System.setProperty("java.security.policy","client.policy");

if(System.getSecurityManager()==null)
System.setSecurityManager(new RMISecurityManager());
   
Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
        env.put(Context.PROVIDER_URL, "localhost:1099");
        env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
        
        Context ctx = new InitialContext(env);

Object obj = ctx.lookup("Hello");
System.out.println("2.......................................");
        HelloHome home = (HelloHome) PortableRemoteObject.narrow(obj,HelloHome.class);
System.out.println("3.......................................");
        Hello hello = home.create();
        System.out.println(hello.hello());
        hello.remove();
    }
}
如果我去掉上面的System.setSecurityManager(new RMISecurityManager());
出现的错误是
     [java] Exception in thread "main" java.security.AccessControlException: acc
ess denied (java.net.SocketPermission 230.0.0.4 connect,accept,resolve)
     [java]     at java.security.AccessControlContext.checkPermission(AccessCont
rolContext.java:323)
     [java]     at java.security.AccessController.checkPermission(AccessControll
er.java:546)
     [java]     at java.lang.SecurityManager.checkPermission(SecurityManager.jav
a:532)
     [java]     at java.lang.SecurityManager.checkMulticast(SecurityManager.java
:1188)
     [java]     at java.net.MulticastSocket.joinGroup(MulticastSocket.java:269)
     [java]     at org.jnp.interfaces.NamingContext.discoverServer(NamingContext
.java:1071)
     [java]     at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:
1199)
     [java]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:51
6)
     [java]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:50
9)
     [java]     at javax.naming.InitialContext.lookup(InitialContext.java:392)
     [java]     at HelloClientTest.main(Unknown Source)
     [java] Java Result: 1
如果我加上上面的System.setSecurityManager(new RMISecurityManager())
出现的错误如下
     [java] Exception in thread "main" java.security.AccessControlException: acc
ess denied (java.net.SocketPermission 230.0.0.4 connect,accept,resolve)
     [java]     at java.security.AccessControlContext.checkPermission(AccessCont
rolContext.java:323)
     [java]     at java.security.AccessController.checkPermission(AccessControll
er.java:546)
     [java]     at java.lang.SecurityManager.checkPermission(SecurityManager.jav
a:532)
     [java]     at java.lang.SecurityManager.checkMulticast(SecurityManager.java
:1188)
     [java]     at java.net.MulticastSocket.joinGroup(MulticastSocket.java:269)
     [java]     at org.jnp.interfaces.NamingContext.discoverServer(NamingContext
.java:1071)
     [java]     at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:
1199)
     [java]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:51
6)
     [java]     at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:50
9)
     [java]     at javax.naming.InitialContext.lookup(InitialContext.java:392)
     [java]     at HelloClientTest.main(Unknown Source)
     [java] Java Result: 1
希望大家帮我看看错误原因,thanks
论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics