Не удается получить доступ к удаленному EJB - PullRequest
1 голос
/ 01 февраля 2012

Я создал EJB с удаленным и локальным интерфейсами.

@Stateless
public class VendorBean implements VendorBeanLocal, VendorBeanRemote {

    ...

}

@Local
public interface VendorBeanLocal {

    ...

}

@Remote
public interface VendorBeanRemote {

   ...

}

Есть несколько методов вместо точек (в данном случае это не имеет значения).

Затем разверните его на Glassfish 3.1. Он доступен из моего клиентского веб-приложения (развернута как война на том же сервере) и работает нормально. Но я не могу получить к нему доступ из своих интеграционных тестов.

Я написал интеграционный тест, который должен запускать Maven 2. Я посмотрел имя JNDI этого компонента в файле glassfish server.log:

java:global/<my business module name>/VendorBean!<package>.VendorBeanRemote

и написал тест. Но я всегда получаю исключение при поиске:

javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
    at com.sun.jndi.cosnaming.ExceptionMapper.mapException(ExceptionMapper.java:61)
    at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:501)
    at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:540)
    at com.sun.jndi.cosnaming.CNCtx.lookup(CNCtx.java:518)
    at javax.naming.InitialContext.lookup(InitialContext.java:409)
    at com.widewebtech.mercury.core.test.ejb.VendorBeanIntegrationTest.manageVendor(VendorBeanIntegrationTest.java:126)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Caused by: org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0
    at org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(NotFoundHelper.java:72)
    at org.omg.CosNaming._NamingContextExtStub.resolve(_NamingContextExtStub.java:406)
    at com.sun.jndi.cosnaming.CNCtx.callResolve(CNCtx.java:487)
    ... 33 more

код теста:

Properties p = new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.cosnaming.CNCtxFactory");
p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
p.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
Context context = new InitialContext(p);

Object o = context.lookup("java:global/<my business module name>/VendorBean!<package>.VendorBeanRemote");

Я в замешательстве. Я прочитал много статей, перепробовал много предложений, но ничего не работает.

Я также пытался перечислить контекст в тесте:

NamingEnumeration<NameClassPair> list = context.list(""); 
while (list.hasMore()) { 
    NameClassPair ncPair = (NameClassPair) list.next(); 
    System.out.print(ncPair.getName() + " (type "); 
    System.out.println(ncPair.getClassName() + ")"); 
}

Результат:

<package>.VendorBeanRemote__3_x_Internal_RemoteBusinessHome__ (type com.sun.corba.se.impl.corba.CORBAObjectImpl)
SerialContextProvider (type com.sun.corba.se.impl.corba.CORBAObjectImpl)
java:global (type com.sun.jndi.cosnaming.CNCtx)
INITIAL_GIS (type com.sun.corba.se.impl.corba.CORBAObjectImpl)

Итак, в контексте выглядит как боб.

Что я делаю не так? Пожалуйста, помогите!

Ответы [ 2 ]

1 голос
/ 02 февраля 2012

В конце концов мне удалось решить эту проблему. Итак, код:

Properties p = new Properties();
p.setProperty(Context.PROVIDER_URL, "corbaname:iiop:localhost:3700");
context = new InitialContext(p);

VendorBeanRemote vendorBean = (VendorBeanRemote) context.lookup("java:global/<my business module name>/VendorBean!<package>.VendorBeanRemote");

Важная вещь, gf-client.jar должен находиться в пути к классам. Это можно взять из Каталог libfish Glassfish.

0 голосов
/ 04 сентября 2013

Если кто-то борется с удаленными вызовами EJB между 2 разными хостами на glassfish, за исключением указанного выше: Установите сетевой адрес orb-listener-1 на ваш IP. (Раздел слушателей ORB / IIOP в конфигурации)

...