2012-06-20 61 views
0

我在Linux上運行帶有JDK 1.6的JBoss 5.1 GA並嘗試調用會話bean(包含此會話bean的jar部署在jboss服務器上),現在我想從客戶端調用這個會話bean,但沒有工作。從客戶端調用部署在jboss 5.x上的Bean

Java代碼的在客戶端

public class CallingJbossSessionBeanFromClient { 

/** 
* @param args 
* @throws Exception 
*/ 
public static void main(String[] args) throws Exception 
{ 
    Properties p = new Properties(); 
    p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 
    p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); 
    p.put(Context.PROVIDER_URL, "jnp://182.158.93.41:8080"); 
    Context context = new InitialContext(p); 
    System.out.println("Successfully Lookup and going to call SessionBean Function deployed on JBoss-5.1.0 Server"); 
    SlsSessiongRemote remote=(SlsSessionRemote) context.lookup("SlsSessionBean/remote"); 
//SlsSessionBean/remote is RemoteBinding of session Bean 
    System.out.println("Called"); 
} 
} 

其中 'SlsSessionBean /遠程' 是遠程綁定部署JBoss服務器會話bean的。 @Stateless @RemoteBinding(jndiBinding = 「SlsSessionBean /遠程」)

但具有以下錯誤

Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory [Root exception is java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory] 
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657) 
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) 
at javax.naming.InitialContext.init(InitialContext.java:223) 
at javax.naming.InitialContext.<init>(InitialContext.java:197) 
at CallingJbossSessionBeanFromClient.main(CallingJbossSessionBeanFromClient.java:20) 
    Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory 
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:303) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316) 
at java.lang.Class.forName0(Native Method) 
at java.lang.Class.forName(Class.java:247) 
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46) 
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654) 
... 4 more 

最終看到上述錯誤i的 'CallingJbossSessionBeanFromClient' 的類路徑添加jbossjmx-的ant.jar後類和得到以下錯誤

Exception in thread "main" java.lang.NoClassDefFoundError: org/jboss/logging/Logger 
at org.jnp.interfaces.NamingContext.<clinit>(NamingContext.java:181) 
at org.jnp.interfaces.NamingContextFactory.getInitialContext(NamingContextFactory.java:55) 
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667) 
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288) 
at javax.naming.InitialContext.init(InitialContext.java:223) 
at javax.naming.InitialContext.<init>(InitialContext.java:197) 
at CallingJbossSessionBeanFromClient.main(CallingJbossSessionBeanFromClient.java:20) 
    Caused by: java.lang.ClassNotFoundException: org.jboss.logging.Logger 
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:303) 
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) 
at java.lang.ClassLoader.loadClass(ClassLoader.java:248) 
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316) 
... 7 more 

上述錯誤看到i之後加入的「CallingJbossSessionBeanFromClient」類類路徑的jboss-測井spi.jar,並得到下面的錯誤

Exception in thread "main" javax.naming.CommunicationException: Could not obtain connection to any of these urls: 182.158.93.41:8080 and discovery failed with error: javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out] [Root exception is javax.naming.CommunicationException: Failed to retrieve stub from server /182.158.93.41:8080 [Root exception is java.io.EOFException]] 
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1763) 
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:693) 
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:686) 
at javax.naming.InitialContext.lookup(InitialContext.java:392) 
at CallingJbossSessionBeanFromClient.main(CallingJbossSessionBeanFromClient.java:22) 
     Caused by: javax.naming.CommunicationException: Failed to retrieve stub from server /182.158.93.41:8080 [Root exception is java.io.EOFException] 
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:327) 
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1734) 
... 4 more 
    Caused by: java.io.EOFException 
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2281) 
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2750) 
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:780) 
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:280) 
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:312) 
... 5 more 

PLZ告訴我,我是從正確的方式調用客戶端Java類的sesion bean嗎? 我花了數小時在Google上尋找解決方案。然而,我似乎無法找到任何握住手的東西..更清楚,我對這個問題缺乏創意,即使它聽起來像是一個經典的 PLZ建議解決方案

+0

請回復...... – user752590

回答

0

此問題的解決方案是打開JMX控制檯並點擊service = Naming來查看命名服務的MBean視圖。檢查使用的端口是否仍然是1099 ..... 將URL更改爲jnp://182.158.93.41:1299,客戶端可以與EJB進行通信。

0

如果您正在運行JBoss AS 5.x 這裏是基於RMI的JNDI描述。

RMI端口:默認-1099 /如果動態端口改爲端口,01端口然後是1199

現在,剩下的事情都OK,修改代碼屁股下面

Properties p = new Properties(); 
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); 
p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces"); 
p.put(Context.PROVIDER_URL, "jnp://182.158.93.41:1199"); 

另一點是情況訪問

SlsSessiongRemote remote =(SlsSessionRemote)context.lookup(「SlsSessionBean/remote」); 如果 - @Stateless(名稱= 「SlsSessionBean」)

然後遠程JNDI- [SlsSessionBean /遠程]和本地JNDI - [SlsSessionBean /本地]

如果 - @Stateless(名稱= 「SlsSessionBean」,mappedName = 「SlsSessionBeanGlobal」)

然後遠程JNDI- [SlsSessionBeanGlobal]和本地JNDI - [SlsSessionBean /本地]