最近在学习EJB的远程调用,写了一个无状态的会话bean(HelloWorldBean.java)
package com.chncloud.steven.bean;
import javax.ejb.Stateless;
@Stateless
public class HelloWorldBean implements HelloWorldBeanRemote {
public HelloWorldBean() {}
public String sayHelloWorld(){
return "Hello World!!!";
}
} 该BEAN实现的是远程接口(HelloWorldBeanRemote.java)
package com.chncloud.steven.bean;
import javax.ejb.Remote;
@Remote
public interface HelloWorldBeanRemote {
public String sayHelloWorld();
} 将该会话bean部署到websphere服务器上,版本是7.0的 然后自己在本机上编写一个客户端程序来远程调用该会话bean(HelloWorldBean.java)
将HelloWorldBean.java 和HelloWorldBeanRemote.java 打包成.jar文件 并添加到客户端项目路径中
将客户端远程调用EJB所需要的jar包
namingclient.jar
com.ibm.ws.ejb.thinclient_7.0.0.jar
com.ibm.ws.orb_7.0.0.jar等
导入到该项目路径中 然后用如下代码调用会话bean:
package com.chncloud.test;
import java.util.Properties; import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException; import com.chncloud.steven.bean.HelloWorldBeanRemote; public class TestEjb { public static void main(String[] args) {
InitialContext cxt = getContext(); if(cxt==null){
System.out.print("Context is null");
}else{
System.out.println("Context is not null");
try {
System.out.println(cxt.getNameInNamespace());
HelloWorldBeanRemote bean = (HelloWorldBeanRemote)cxt.lookup("ejb/HelloWorldBeanRemote");
System.out.println(bean.sayHelloWorld());
} catch (NamingException e) {
e.printStackTrace();
}
}
} public static InitialContext getContext(){
InitialContext ic = null;
try {
Properties props = new Properties();
props.put(Context.PROVIDER_URL, "iiop://localhost:2809/");
props.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
ic = new InitialContext(props);
} catch (Exception e) {
e.printStackTrace();
}
return ic;
}
} 每次调用都出现如下错误
Context is not null
javax.naming.NamingException: Error getting WsnNameService properties [Root exception is org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible vmcid: IBM minor code: E07 completed: No]
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1439)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:946)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:865)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:545)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:123)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:798)
at com.ibm.ws.naming.util.WsnInitCtx.getNameInNamespace(WsnInitCtx.java:739)
at javax.naming.InitialContext.getNameInNamespace(Unknown Source)
at com.chncloud.test.TestEjb.main(TestEjb.java:20)
Caused by: org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible vmcid: IBM minor code: E07 completed: No
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1250)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1321)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1146)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1287)
at com.ibm.rmi.corba.ClientDelegate.request(ClientDelegate.java:1853)
at com.ibm.CORBA.iiop.ClientDelegate.request(ClientDelegate.java:1243)
at org.omg.CORBA.portable.ObjectImpl._request(ObjectImpl.java:458)
at com.ibm.WsnBootstrap._WsnNameServiceStub.getProperties(_WsnNameServiceStub.java:38)
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1436)
... 8 more 断断续续的弄了好长一段时间,每次都让我大失所望,网上也找了好多资料,中英文的都找过了,参照了好多方法,还是无法解决
在这里再次向大家求助,如能解决问题,感激不尽. 问题描述如果有什么不清楚的地方,希望大家能提出来,我会尽量描述清楚.饥渴的等待解决问题的那一天,谢谢
package com.chncloud.steven.bean;
import javax.ejb.Stateless;
@Stateless
public class HelloWorldBean implements HelloWorldBeanRemote {
public HelloWorldBean() {}
public String sayHelloWorld(){
return "Hello World!!!";
}
} 该BEAN实现的是远程接口(HelloWorldBeanRemote.java)
package com.chncloud.steven.bean;
import javax.ejb.Remote;
@Remote
public interface HelloWorldBeanRemote {
public String sayHelloWorld();
} 将该会话bean部署到websphere服务器上,版本是7.0的 然后自己在本机上编写一个客户端程序来远程调用该会话bean(HelloWorldBean.java)
将HelloWorldBean.java 和HelloWorldBeanRemote.java 打包成.jar文件 并添加到客户端项目路径中
将客户端远程调用EJB所需要的jar包
namingclient.jar
com.ibm.ws.ejb.thinclient_7.0.0.jar
com.ibm.ws.orb_7.0.0.jar等
导入到该项目路径中 然后用如下代码调用会话bean:
package com.chncloud.test;
import java.util.Properties; import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException; import com.chncloud.steven.bean.HelloWorldBeanRemote; public class TestEjb { public static void main(String[] args) {
InitialContext cxt = getContext(); if(cxt==null){
System.out.print("Context is null");
}else{
System.out.println("Context is not null");
try {
System.out.println(cxt.getNameInNamespace());
HelloWorldBeanRemote bean = (HelloWorldBeanRemote)cxt.lookup("ejb/HelloWorldBeanRemote");
System.out.println(bean.sayHelloWorld());
} catch (NamingException e) {
e.printStackTrace();
}
}
} public static InitialContext getContext(){
InitialContext ic = null;
try {
Properties props = new Properties();
props.put(Context.PROVIDER_URL, "iiop://localhost:2809/");
props.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
ic = new InitialContext(props);
} catch (Exception e) {
e.printStackTrace();
}
return ic;
}
} 每次调用都出现如下错误
Context is not null
javax.naming.NamingException: Error getting WsnNameService properties [Root exception is org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible vmcid: IBM minor code: E07 completed: No]
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1439)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootContextFromServer(WsnInitCtxFactory.java:946)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getRootJndiContext(WsnInitCtxFactory.java:865)
at com.ibm.ws.naming.util.WsnInitCtxFactory.getInitialContextInternal(WsnInitCtxFactory.java:545)
at com.ibm.ws.naming.util.WsnInitCtx.getContext(WsnInitCtx.java:123)
at com.ibm.ws.naming.util.WsnInitCtx.getContextIfNull(WsnInitCtx.java:798)
at com.ibm.ws.naming.util.WsnInitCtx.getNameInNamespace(WsnInitCtx.java:739)
at javax.naming.InitialContext.getNameInNamespace(Unknown Source)
at com.chncloud.test.TestEjb.main(TestEjb.java:20)
Caused by: org.omg.CORBA.TRANSIENT: initial and forwarded IOR inaccessible vmcid: IBM minor code: E07 completed: No
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1250)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1321)
at com.ibm.rmi.corba.ClientDelegate.createRequest(ClientDelegate.java:1146)
at com.ibm.CORBA.iiop.ClientDelegate.createRequest(ClientDelegate.java:1287)
at com.ibm.rmi.corba.ClientDelegate.request(ClientDelegate.java:1853)
at com.ibm.CORBA.iiop.ClientDelegate.request(ClientDelegate.java:1243)
at org.omg.CORBA.portable.ObjectImpl._request(ObjectImpl.java:458)
at com.ibm.WsnBootstrap._WsnNameServiceStub.getProperties(_WsnNameServiceStub.java:38)
at com.ibm.ws.naming.util.WsnInitCtxFactory.mergeWsnNSProperties(WsnInitCtxFactory.java:1436)
... 8 more 断断续续的弄了好长一段时间,每次都让我大失所望,网上也找了好多资料,中英文的都找过了,参照了好多方法,还是无法解决
在这里再次向大家求助,如能解决问题,感激不尽. 问题描述如果有什么不清楚的地方,希望大家能提出来,我会尽量描述清楚.饥渴的等待解决问题的那一天,谢谢
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货