`
lym6520
  • 浏览: 704095 次
  • 性别: Icon_minigender_1
  • 来自: 福建
社区版块
存档分类
最新评论

远程调用ejb3

阅读更多
总结下远程调用ejb3的几种方式:

部署在jboss服务器上的ejb3应用程序:
/*设置属性信息*/
		Properties props = new Properties();
 		props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
 		props.put(Context.PROVIDER_URL, "jnp://localhost:1099");//部署在jboss服务器上的应用使用jnp协议
 		props.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
 		
 		try {
			InitialContext ctx=new InitialContext(props);
			/* 获得部署在Jboss服务器上的ejb3应用接口实例*/
			IRmiExampleSerivce rmiSerivce = (IRmiExampleSerivce)ctx.lookup("IRmiExampleSerivceImpl/remote"); //不同的服务器jndi名称不一样
 		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


部署在weblogic服务器上的ejb3应用:
/*设置属性信息*/
		Properties props = new Properties();
		props.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
 		props.put(Context.PROVIDER_URL, "t3://127.0.0.1:7001");//部署在weblogic服务器上的应用使用t3协议
 		props.put("java.naming.security.principal", "weblogic");//用户名
 		props.put("java.naming.security.credentials", "weblogic");//密码
 		
 		try {
			InitialContext ctx=new InitialContext(props);
			/* 获得部署在Jboss服务器上的ejb3应用接口实例*/
			IRmiExampleSerivce rmiSerivce = (IRmiExampleSerivce)ctx.lookup("IRmiExampleSerivce#com.rmi.IRmiExampleSerivce"); //不同的服务器jndi名称不一样
 		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


当然属性信息可以放在一个jndi.properties属性文件中,如:
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099

当然该文件放在src根目录下,然后我们在程序中就无需创建Properties的实例并设置相关熟悉,可以直接实例化InitialContext,调用默认的实例化构造函数,会默认查找src根目录下的jndi.properties属性文件。

当然在实际开发应用中不会直接通过以上方式来直接调用远程ejb3服务,在spring框架中可以通过JndiObjectFactoryBean来获得远程ejb3的实例,例如:
<bean id="jndiTemplate" class="org.springframework.jndi.JndiTemplate">
		<property name="environment">
			<props>
				<prop key="java.naming.provider.url">t3://127.0.0.1:7001</prop>
				<prop key="java.naming.factory.initial">weblogic.jndi.WLInitialContextFactory</prop>
				<prop key="java.naming.security.principal">weblogic</prop>
				<prop key="java.naming.security.credentials">weblogic</prop>
			</props>
		</property>
	</bean>
	 
	<bean id="rmiExampleSerivce" class="org.springframework.jndi.JndiObjectFactoryBean">
		<property name="jndiTemplate" ref="jndiTemplate"/>
		<property name="jndiName" value="IRmiExampleSerivce#com.rmi.IRmiExampleSerivce"></property>
	</bean>

0
7
分享到:
评论
1 楼 huazai_wow 2013-09-29  
楼主  在吗?
请教一个问题啊?  QQ:2598059791
在Servlet中
Properties props=new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
props.setProperty(Context.PROVIDER_URL, "t3://221.181.173.95:7001");
props.setProperty(Context.SECURITY_PRINCIPAL, "huazai_wow");
props.setProperty(Context.SECURITY_CREDENTIALS, "huazai_wow");
Context context=new InitialContext(props);
SayHelloRemoteTypeRemote sayHelloRemoteTypeRemoteRef=
(SayHelloRemoteTypeRemote) context.lookup("huazai_wow#publicinterface.SayHelloRemoteTypeRemote");

sayHelloRemoteTypeRemoteRef.sayHelloMethodRemote();
context.close();
远程sessionBean
   /**
*
* @author Administrator
* mappedName 属性值 代表在Weblogic中注册JNDI节点的名称
*
*/
@Stateless(mappedName="huazai_wow")
public class SayHelloRemoteType implements SayHelloRemoteTypeRemote {

public void sayHelloMethodRemote() {

System.out.println("高洪岩你好! 属于远程调用!");

}

}


在 weblogic 服务器  jndi 树节点中 可以看到这个树节点
但是运行的时候报这个错误啊?
2013-9-29 11:57:00 com.sun.corba.se.impl.encoding.CDRInputStream_1_0 read_value
警告: "IOP00810211: (MARSHAL) Exception from readValue on ValueHandler in CDRInputStream"
org.omg.CORBA.MARSHAL:   vmcid: SUN  minor code: 211 completed: Maybe
at com.sun.corba.se.impl.logging.ORBUtilSystemException.valuehandlerReadException(ORBUtilSystemException.java:6528)
at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1045)
at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:879)
at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_abstract_interface(CDRInputStream_1_0.java:873)
at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_abstract_interface(CDRInputStream_1_0.java:863)
at com.sun.corba.se.impl.encoding.CDRInputStream.read_abstract_interface(CDRInputStream.java:269)
at com.sun.corba.se.impl.util.Utility.readAbstractAndNarrow(Utility.java:948)
at com.sun.corba.se.impl.io.IIOPInputStream.inputObjectField(IIOPInputStream.java:1988)
at com.sun.corba.se.impl.io.IIOPInputStream.inputClassFields(IIOPInputStream.java:2216)
at com.sun.corba.se.impl.io.IIOPInputStream.inputObject(IIOPInputStream.java:1223)
at com.sun.corba.se.impl.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:400)
at com.sun.corba.se.impl.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:327)
at com.sun.corba.se.impl.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:293)
at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1034)
at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:879)
at com.sun.corba.se.impl.encoding.CDRInputStream.read_value(CDRInputStream.java:249)
at com.sun.corba.se.impl.corba.TCUtility.unmarshalIn(TCUtility.java:269)
at com.sun.corba.se.impl.corba.AnyImpl.read_value(AnyImpl.java:559)
at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_any(CDRInputStream_1_0.java:739)
at com.sun.corba.se.impl.encoding.CDRInputStream.read_any(CDRInputStream.java:220)
at weblogic.corba.cos.naming._NamingContextAnyStub.resolve_any(_NamingContextAnyStub.java:81)
at weblogic.corba.j2ee.naming.ContextImpl.lookup(ContextImpl.java:267)
at weblogic.corba.j2ee.naming.ContextImpl.lookup(ContextImpl.java:227)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at controller.test.doPost(test.java:35)
at controller.test.doGet(test.java:21)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:617)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1760)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: publicinterface.SayHelloRemoteType_u66dq_SayHelloRemoteTypeRemoteRIntf
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:247)
at weblogic.ejb.container.internal.RemoteBusinessIntfProxy.readObject(RemoteBusinessIntfProxy.java:266)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.corba.se.impl.io.IIOPInputStream.invokeObjectReader(IIOPInputStream.java:1696)
at com.sun.corba.se.impl.io.IIOPInputStream.inputObject(IIOPInputStream.java:1214)
at com.sun.corba.se.impl.io.IIOPInputStream.simpleReadObject(IIOPInputStream.java:400)
at com.sun.corba.se.impl.io.ValueHandlerImpl.readValueInternal(ValueHandlerImpl.java:327)
at com.sun.corba.se.impl.io.ValueHandlerImpl.readValue(ValueHandlerImpl.java:293)
at com.sun.corba.se.impl.encoding.CDRInputStream_1_0.read_value(CDRInputStream_1_0.java:1034)
... 38 more

相关推荐

Global site tag (gtag.js) - Google Analytics