2012-03-22 101 views
3

我正在使用在我的子網(192.168.1.3:3700)中運行的GlassFish-3.1.2服務器。我已經部署了一個企業應用程序,其中包括一個我定義業務方法的EJB。現在我想從我的Java應用程序客戶端遠程訪問EJB。我該如何設置JNDI和。用於查找EJB的InitialContext對象?我如何需要定義屬性?順便說一句。我必須運行「asadmin enabled-secure-admin」才能使GlassFish服務器在LAN上工作。也許我還需要發送我的憑據與屬性?如何訪問遠程服務器上的EJB?

這裏是我當前的「解決方案」,這似乎是completley錯誤:

Properties props = new Properties(); 
props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory"); 
props.setProperty("org.omg.CORBA.ORBInitialHost", "192.168.1.3"); 
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); 
InitialContext ctx = new InitialContext(props); 

TestentityFacadeRemote tfr = (TestentityFacadeRemote)ctx.lookup("java:global/TestEE/TestEE-ejb/TestentityFacadeRemote"); 

當我運行這個PROGRAMM,它只是等待無限......

任何幫助,不勝感激!

+0

退房http://stackoverflow.com/a/3783501/1037626 - 有那裏描述了更多的屬性。用於'IIOP'查找的 – mgaert 2012-03-22 23:22:39

回答

6

我解決了這個問題,通過設置主機和端口直接由System.setProperty()並使用默認構造函數初始化InitialContext()。請注意,以下行應該是在你的程序的第一個/ main方法:

public static void main(String[] args) { 
    System.setProperty("org.omg.CORBA.ORBInitialHost", "192.168.1.3"); 
    System.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); 
    InitialContext ctx = new InitialContext(); 
    TestentityFacadeRemote tfr = (TestentityFacadeRemote)ctx.lookup("java:global/TestEE/TestEE-ejb/TestentityFacadeRemote!com.acme.remote.TestentityFacade"); 
} 

希望這有助於...

+0

,您是否在Glassfish中配置了ORB - > IIOP或JNDI資源? – Thufir 2015-03-12 14:00:04

+0

我只配置ORB-> IIOP與服務器的IP地址。我沒有改變任何默認的JNDI設置。 – salocinx 2015-03-17 21:44:43