分享
 
 
 

初始化EJB客户端的Context

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

编写EJB客户端时取得那个Context对象是比较棘手的一个问题,对于不同的应用服务器,其工厂类和JNDI URL总是不同的,每次都得到处找资料,这次干脆一次性把所有资料都找了一下,写成一个类去获取InitialContext构造函数需要的那个Properties对象。查找的过程比我想象的艰难,这更坚定了我要将它们找出来的决心。目前已找出当今主流J2EE应用服务器的相关资料,有weblogic,websphere,jboss,sun one,oracle application server,JRun,IONA,对于Borland Enterprise Server(BES),大量资料表明它的客户端不需要为InitialContext构造函数提供参数,即Context ctx = new InitialContext()即可,对此我百思不得其解,Borland到底怎么实现获取其它机器上JNDI上下文的呢?所以我将BES对外隐藏了(private)。也许有我未知的东西,有知道的朋友请告知。另外,oracle application server有点特别,有些资料上没有写明它的JNDI端口,并且有时在其JNDI URL中会出现一个附加的Bean类名,这个服务器我没用过,也不知道原因,而JRun不需要提供JNDI服务的协议名,因此为了支持这些情况特地做了一些处理。

以下是这个ContextProperties类的代码:

import java.util.Properties;

import javax.naming.InitialContext;

public class ContextProperties{

public static final int WEBLOGIC = 0;

public static final int WEBSPHERE = 1;

public static final int JBOSS = 2;

public static final int SUNONE = 3;

public static final int ORACLE = 4;

public static final int JRUN = 5;

public static final int IONA = 6;

private static final int BES = 7;

//

public static final int NULL_PORT = Integer.MAX_VALUE;

private static final String WEBLOGIC_FACTORY = "weblogic.jndi.WLInitialContextFactory";

private static final String WEBLOGIC_PROTOCOL = "t3";

private static final int WEBLOGIC_PORT = 7001;

private static final String WEBSPHERE_FACTORY =

"com.ibm.websphere.naming.WsnInitialContextFactory";

private static final String WEBSPHERE_PROTOCOL = "iiop";

private static final int WEBSPHERE_PORT = 2809; //may be 900

private static final String JBOSS_FACTORY = "org.jnp.interfaces.NamingContextFactory";

private static final String JBOSS_PROTOCOL = "jnp";

private static final int JBOSS_PORT = 1099;

private static final String SUNONE_FACTORY = "com.sun.jndi.cosnaming.CNCtxFactory";

private static final String SUNONE_PROTOCOL = "iiop";

private static final int SUNONE_PORT = 3700;

private static final String BES_FACTORY = "";

private static final String BES_PROTOCOL = "";

private static final int BES_PORT = NULL_PORT;

private static final String ORACLE_FACTORY =

"com.evermind.server.rmi.RMIInitialContextFactory";

private static final String ORACLE_PROTOCOL = "ormi";

private static final int ORACLE_PORT = 23791; //may be no

private static final String JRUN_FACTORY = "jrun.naming.JRunContextFactory";

private static final String JRUN_PROTOCOL = "";

private static final int JRUN_PORT = 2908;

private static final String IONA_FACTORY =

"com.ejbhome.naming.spi.rmi.RMIInitCtxFactory";

private static final String IONA_PROTOCOL = "iiop";

private static final int IONA_PORT = 9070;

private static final String DEFAULT_IP = "localhost";

private ContextProperties(){

}

public static Properties newInstance(int serverType, String ip, int port, String addIn){

String factory = null;

String protocol = null;

switch (serverType) {

case WEBLOGIC :

factory = WEBLOGIC_FACTORY;

protocol = WEBLOGIC_PROTOCOL;

break;

case WEBSPHERE :

factory = WEBSPHERE_FACTORY;

protocol = WEBSPHERE_PROTOCOL;

break;

case JBOSS :

factory = JBOSS_FACTORY;

protocol = JBOSS_PROTOCOL;

break;

case SUNONE :

factory = SUNONE_FACTORY;

protocol = SUNONE_PROTOCOL;

break;

case ORACLE :

factory = ORACLE_FACTORY;

protocol = ORACLE_PROTOCOL;

break;

case JRUN :

factory = JRUN_FACTORY;

protocol = JRUN_PROTOCOL;

break;

case IONA :

factory = IONA_FACTORY;

protocol = IONA_PROTOCOL;

break;

case BES :

factory = BES_FACTORY;

protocol = BES_PROTOCOL;

break;

}

Properties props = new Properties();

if (factory != null){

String slash = "";

if (protocol.length() > 0){

slash = "://";

}

String portString = "";

if (port != NULL_PORT){

portString = ":" + port;

}

String additivePath = "";

if (addIn.length() > 0){

additivePath = "/" + addIn;

}

props.put(InitialContext.INITIAL_CONTEXT_FACTORY, factory);

props.put(InitialContext.PROVIDER_URL, protocol + slash + ip + portString

+ additivePath);

}

return props;

}

public static Properties newInstance(int serverType, String ip, int port){

return newInstance(serverType, ip, port, "");

}

public static Properties newInstance(int serverType, String ip){

int port = Integer.MIN_VALUE;

switch (serverType) {

case WEBLOGIC :

port = WEBLOGIC_PORT;

break;

case WEBSPHERE :

port = WEBSPHERE_PORT;

break;

case JBOSS :

port = JBOSS_PORT;

break;

case SUNONE :

port = SUNONE_PORT;

break;

case ORACLE :

port = ORACLE_PORT;

break;

case JRUN :

port = JRUN_PORT;

break;

case IONA :

port = IONA_PORT;

break;

case BES :

port = BES_PORT;

break;

}

Properties props = new Properties();

if (port != Integer.MIN_VALUE){

props = newInstance(serverType, ip, port);

}

return props;

}

public static Properties newInstance(int serverType){

return newInstance(serverType, DEFAULT_IP);

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有