Client如何访问Glassfish 提供的远程EJB

[b]EJB所有返回值必须实现 Serializable接口,否则会报些莫名其妙的错误.
并把 Glassfish 的 appserv-rt.jar 和 javaee.jar 包 客户程序的类路径[/b]

@Stateless(mappedName="ejb/MainActionJNDI")//远程JNDI
@Name("MainAction")

@Interceptors({org.jboss.seam.ejb.SeamInterceptor.class})
@AutoCreate
public class MainActionBean implements MainAction,MainActionRemote {




package cn.astrocom.ejb.client;

import java.util.List;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;

import cn.astrocom.extseam.MainActionRemote;
import cn.astrocom.extseam.bo.MainGrid;

/**
*
* @author fanzhi_kong
*
*/
public class MainActionClient {

/**
* @param args
*/
public static void main(String[] args) {

try {
Context jndiContext = getInitialJNDIFileContext();
// Context jndiContext = getInitialPropertiesContext();
/*
* 2.0 Object ref = jndiContext.lookup("ejb/MainActionJNDI");
* MainActionRemote mainAction = (MainActionRemote)
* PortableRemoteObject .narrow(ref, MainActionRemote.class);
*/
// 3.0
MainActionRemote mainAction = (MainActionRemote) jndiContext
.lookup("ejb/MainActionJNDI");

} catch (Exception ne) {
ne.printStackTrace();
}

}

// JNDI上下文 方式一
public static Context getInitialPropertiesContext()
throws javax.naming.NamingException {

Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");

//EJB容器的ip
props.setProperty("org.omg.CORBA.ORBInitialHost", "172.16.140.103");

//EJB容器端口,默认为:3700
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

InitialContext ic = new InitialContext(props);

return ic;
}

/**
* JNDI上下文 方式二读配置文件 文件为:jndi.properties
*
* @return
* @throws javax.naming.NamingException
*/
public static Context getInitialJNDIFileContext()
throws javax.naming.NamingException {

return new InitialContext();

}

}


# optional. Defaults to localhost. Only needed if web server is running
# on a different host than the appserver
org.omg.CORBA.ORBInitialHost=172.16.140.103

# optional. Defaults to 3700. Only needed if target orb port is not
# 3700.
org.omg.CORBA.ORBInitialPort=3700


java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值