2014-09-20 5 views
0

Для двух клиентов Java SE, подключающихся к Glassfish на localhost, только the ACC client example, очень похож на the Netbeans Creating and Running an Application Client on the GlassFish Server tutorial, подключается. RemoteJNDI, который подключается через CORBA, с явными параметрами подключения JNDI, получает NamingException. Как может RemoteJNDI подключиться к Netbeans на localhost, правильно найти компонент и выполнить компонент?Поиск JNDI для удаленного фанатичного bean (hello world)

RemoteJNDI эксплуатируется из Glassfish appclient. GlassFish показывает:

[email protected]:~/NetBeansProjects/HelloClient$ 
[email protected]:~/NetBeansProjects/HelloClient$ /home/thufir/glassfish-4.1/glassfish/bin/asadmin list-applications 
HelloEJB  <ejb>   
Command list-applications executed successfully. 
[email protected]:~/NetBeansProjects/HelloClient$ 

работает ant clean;ant run на примере клиента ACC дает хороший результат:

-run: 
    [java] hello world 

run: 

BUILD SUCCESSFUL 
Total time: 26 seconds 
[email protected]:~/NetBeansProjects/HelloClient$ 

(. Это также развертывает HelloClient к Glassfish)

однако, пытаясь повторить этот вывод с appclient и результаты поиска JNDI в NamingException: Lookup failed for 'hello.HelloBean', в то время как клиент ACC смог найти этот компонент через ACC. Почему не может RemoteJNDI искать фасоль? StackTrace:

[email protected]:~/NetBeansProjects/HelloClient$ /home/thufir/glassfish-4.1/glassfish/bin/appclient -client /home/thufir/NetBeansProjects/RemoteJNDI/dist/RemoteJNDI.jar 
Sep 20, 2014 8:05:12 AM net.bounceme.dur.jndi.RemoteJNDI main 
INFO: {org.omg.CORBA.ORBInitialPort=4848, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1} 
org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Connection abort vmcid: OMG minor code: 8 completed: Maybe 
    at com.sun.proxy.$Proxy35.connectionAbort(Unknown Source) 
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrategy(ConnectionImpl.java:1288) 
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doWork(ConnectionImpl.java:846) 
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497) 
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540) 
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: 00410011: IOException received when reading from connection SocketOrChannelConnectionImpl[ java.nio.channels.SocketChannel[connected local=/127.0.0.1:59218 remote=localhost/127.0.0.1:4848] ESTABLISHED true true] vmcid: OMG minor code: 11 completed: No 
    at com.sun.proxy.$Proxy35.ioexceptionWhenReadingConnection(Unknown Source) 
    at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(ConnectionImpl.java:1475) 
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrategy(ConnectionImpl.java:1242) 
    ... 3 more 
Caused by: java.io.IOException: End-of-stream 
    at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(ConnectionImpl.java:1468) 
    ... 4 more 
Sep 20, 2014 8:05:46 AM net.bounceme.dur.jndi.RemoteJNDI main 
SEVERE: null 
javax.naming.NamingException: Lookup failed for 'hello.HelloBean' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=4848, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1} [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=4848, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Connection abort vmcid: OMG minor code: 8 completed: Maybe]] 
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491) 
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438) 
    at javax.naming.InitialContext.lookup(InitialContext.java:411) 
    at net.bounceme.dur.jndi.RemoteJNDI.main(RemoteJNDI.java:17) 
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=4848, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1} [Root exception is org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Connection abort vmcid: OMG minor code: 8 completed: Maybe] 
    at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:334) 
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:477) 
    ... 3 more 
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: 00410008: Connection abort vmcid: OMG minor code: 8 completed: Maybe 
    at com.sun.proxy.$Proxy35.connectionAbort(Unknown Source) 
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrategy(ConnectionImpl.java:1288) 
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doWork(ConnectionImpl.java:846) 
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497) 
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540) 
Caused by: org.omg.CORBA.COMM_FAILURE: FINE: 00410011: IOException received when reading from connection SocketOrChannelConnectionImpl[ java.nio.channels.SocketChannel[connected local=/127.0.0.1:59218 remote=localhost/127.0.0.1:4848] ESTABLISHED true true] vmcid: OMG minor code: 11 completed: No 
    at com.sun.proxy.$Proxy35.ioexceptionWhenReadingConnection(Unknown Source) 
    at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(ConnectionImpl.java:1475) 
    at com.sun.corba.ee.impl.transport.ConnectionImpl.doOptimizedReadStrategy(ConnectionImpl.java:1242) 
    ... 3 more 
Caused by: java.io.IOException: End-of-stream 
    at com.sun.corba.ee.impl.transport.ConnectionImpl.nonBlockingRead(ConnectionImpl.java:1468) 
    ... 4 more 

[email protected]:~/NetBeansProjects/HelloClient$ 

Код клиента ACC:

package helloclient; 

import hello.HelloBeanRemote; 
import javax.ejb.EJB; 

public class Main { 
    @EJB 
    private static HelloBeanRemote helloBean; 

    public static void main(String... args) { 
     System.out.println(helloBean.Hi()); 
    } 

} 

Интерфейс:

package hello; 

import javax.ejb.Remote; 

@Remote 
public interface HelloBeanRemote { 

    public String Hi(); 

    public String Bye(); 
} 

EJB-:

package hello; 

import javax.ejb.Stateless; 

@Stateless 
public class HelloBean implements HelloBeanRemote { 

    @Override 
    public String Hi() { 
     return "hello world"; 
    } 

    @Override 
    public String Bye() { 
     return "goodbye"; 
    } 

} 

RemoteJNDI должны явно иметь ту же конфигурацию, HelloClient, клиент ACC , implicitly has. Why is the ACC client able to execute the bean, while RemoteJNDI` не может?

Код для RemoteJNDI:

package net.bounceme.dur.jndi; 

import hello.HelloBean; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import javax.naming.InitialContext; 
import javax.naming.NamingException; 

public class RemoteJNDI { 

    private static final Logger log = Logger.getLogger(RemoteJNDI.class.getName()); 

    public static void main(String[] args) { 
     try { 
      InitialContext ctx = new InitialContext(); 
      log.info(ctx.getEnvironment().toString()); 
      HelloBean bean = (HelloBean) ctx.lookup("hello.HelloBean"); 
      log.info(bean.Hi()); 
     } catch (NamingException ex) { 
      Logger.getLogger(RemoteJNDI.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } 

} 

ли параметры подключения правильно для Glassfish работает на локальном хосте?

[email protected]:~/NetBeansProjects/HelloClient$ 
[email protected]:~/NetBeansProjects/HelloClient$ /home/thufir/glassfish-4.1/glassfish/bin/appclient -client /home/thufir/NetBeansProjects/RemoteJNDI/dist/RemoteJNDI.jar 
Sep 20, 2014 8:05:12 AM net.bounceme.dur.jndi.RemoteJNDI main 
INFO: {org.omg.CORBA.ORBInitialPort=4848, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1} 

------------------------------------------- ----------- редактировать -----------------------------

след:

[email protected]:~$ 
[email protected]:~$ /home/thufir/glassfish-4.1/glassfish/bin/appclient -client /home/thufir/NetBeansProjects/RemoteJNDI/dist/RemoteJNDI.jar 
javax.naming.NamingException: Lookup failed for 'HelloBeanRemote' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1} [Root exception is javax.naming.NameNotFoundException: HelloBeanRemote not found] 
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491) 
    at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438) 
    at javax.naming.InitialContext.lookup(InitialContext.java:411) 
    at net.bounceme.dur.jndi.RemoteJNDI.main(RemoteJNDI.java:18) 
Caused by: javax.naming.NameNotFoundException: HelloBeanRemote not found 
    at com.sun.enterprise.naming.impl.TransientContext.doLookup(TransientContext.java:237) 
    at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:204) 
    at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:66) 
    at com.sun.enterprise.naming.impl.RemoteSerialContextProviderImpl.lookup(RemoteSerialContextProviderImpl.java:109) 
    at sun.reflect.GeneratedMethodAccessor113.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie.dispatchToMethod(ReflectiveTie.java:143) 
    at com.sun.corba.ee.impl.presentation.rmi.ReflectiveTie._invoke(ReflectiveTie.java:173) 
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatchToServant(ServerRequestDispatcherImpl.java:528) 
    at com.sun.corba.ee.impl.protocol.ServerRequestDispatcherImpl.dispatch(ServerRequestDispatcherImpl.java:199) 
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequestRequest(MessageMediatorImpl.java:1549) 
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:1425) 
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleInput(MessageMediatorImpl.java:930) 
    at com.sun.corba.ee.impl.protocol.giopmsgheaders.RequestMessage_1_2.callback(RequestMessage_1_2.java:213) 
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.handleRequest(MessageMediatorImpl.java:694) 
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.dispatch(MessageMediatorImpl.java:496) 
    at com.sun.corba.ee.impl.protocol.MessageMediatorImpl.doWork(MessageMediatorImpl.java:2222) 
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.performWork(ThreadPoolImpl.java:497) 
    at com.sun.corba.ee.impl.threadpool.ThreadPoolImpl$WorkerThread.run(ThreadPoolImpl.java:540) 
[email protected]:~$ 
[email protected]:~$ 

ex.printstacktrace;

package net.bounceme.dur.jndi; 

import hello.HelloBean; 
import java.util.logging.Logger; 
import javax.naming.InitialContext; 
import javax.naming.NamingException; 
import javax.rmi.PortableRemoteObject; 

public class RemoteJNDI { 

    private static final Logger log = Logger.getLogger(RemoteJNDI.class.getName()); 

    public static void main(String... args) { 
     try { 
      InitialContext ctx = new InitialContext(); 
      log.fine(ctx.getEnvironment().toString()); 
      Object obj = ctx.lookup("HelloBeanRemote"); 
      HelloBean bean = (HelloBean) PortableRemoteObject.narrow(obj, HelloBean.class); 
      log.info(bean.Hi()); 
     } catch (NamingException ex) { 
      ex.printStackTrace(); 
     } 
    } 

} 

---------------------------------------- edit-- ------------------------------------

+0

просто для того, чтобы отметить, я добавил модуль EJB, «HelloEJB» и его интерфейс, в «RemoteJNDI» для поиска компонента. – Thufir

ответ

1

Используйте имя удаленного интерфейса для поиска через JNDI. Затем используйте метод PortableRemoteObject.narrow(), чтобы передать его удаленному компоненту.

Object obj = ctx.lookup("HelloBeanRemote"); 
HelloBean bean = (HelloBean) PortableRemoteObject.narrow(obj, HelloBean.class); 
+0

см. Редактирование для вывода, я думаю, что та же ошибка. Я попробовал порт 3700 вместо 4848, но до сих пор не могу найти bean-компонент.Мне нравится использовать имя интерфейса, чтобы посмотреть его. Почему «HelloBeanRemote», а не «hello.HelloBeanRemote»? – Thufir

+0

Сервер автоматически определяет имя пакета для любого удаленного интерфейса сеансового компонента, и это так, как я делаю, и оно работает. Также HelloBeanRemote намного опрятен. Приходите к проблеме, можете ли вы предоставить трассировку после редактирования. – ares

+0

Больше не было вывода, если только я не передаю параметры компилятора или не изменю то, что зарегистрировано в цикле try. Сделаю. – Thufir