package interejbs;
//Download by http://www.codefans.net
import javax.ejb.*;
import javax.naming.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
public class firstEJBBean implements SessionBean {
SessionContext sessionContext;
private secondEJBHome secondEJBHomeObject = null;
public void ejbCreate() throws CreateException {
try {
//得到名字上下文
Context ctx = getInitialContext();
//查询jndi名
Object ref = ctx.lookup("secondEJB");
//通过强制转型得到Home接口
secondEJBHomeObject = (secondEJBHome) PortableRemoteObject.narrow(ref, secondEJBHome.class);
}
catch(Exception e) {
e.printStackTrace();
}
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
//这个函数返回一个经过初始化的上下文
private Context getInitialContext() throws Exception {
String url = "t3://cgb-4wn01xj69v6:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
}
return new InitialContext(properties);
}
catch(Exception e) {
throw e;
}
}
//这个函数将调用secondEJB
public String MyPrint() {
String ret="This is a example for interEJBS:\n";
ret=ret+"This is firstEJB,now calling secondEJB\n";
try {
secondEJB secondEJB=secondEJBHomeObject.create();
ret=secondEJB.forFirst(ret)+"example is over!\n";
}
catch(Exception e) {
e.printStackTrace();
}
return ret;
}
//这个函数将被secondEJB调用
public String forSecond(String fromSecond) {
fromSecond=fromSecond+"This is firstEJB called by secondEJB\n";
return fromSecond;
}
}
基于Java的实例源码-各种EJB之间的调用示例.zip
173 浏览量
2023-06-30
21:54:52
上传
评论
收藏 6KB ZIP 举报
毕业课程设计
- 粉丝: 2247
- 资源: 1639
最新资源
- 51单片机学习(1)-软件keil下载
- 历届(第1-21届)希望杯数学竞赛初一试题及答案(最新整理).doc全国数学邀请赛(264页资料)
- 水滴.psd
- TokenPocket_V2.1.2_release.apk
- Apache-druid-kafka-rce.yaml
- 基于C#的ASP.NET数据库原理及应用技术课程指导平台的开发
- 基于ROS的智能车轨迹跟踪算法的仿真与设计源码运用PID跟踪算法.zip.zip
- Bug Bounty Tip - i春秋Self-XSS变废为宝的奇思妙想
- 1991-2015年全国初中化学竞赛复赛试题汇编(212页)(24年竞赛复赛真题).docx天原杯
- Apache Flink 未授权访问+远程代码执行.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈