EJB客户端错误

发布于 2024-08-07 04:38:29 字数 1683 浏览 8 评论 0原文

我创建了一个 EJB 2。我将其部署在 JBoss-IDE 1.6 上,然后创建了一个 JUnit 测试来访问它。这是我用于客户端的代码:

   public class DossierBeanTest extends TestCase {
         protected DossierHome dossierHome;
         protected Dossier dossier;

         public DossierBeanTest(String argo){
                super(arg0);
         }

         protected void setUp() throws Exception {
                super.setUp();
                Hashtable env=new Hashtable();


               env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
                env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
                env.put(Context.PROVIDER_URL,"jnp://localhost:1199");
                Context context=new InitialContext(env);

                Object finderRef=context.lookup(dossierHome.JNDI_NAME);
                dossierHome=(DossierHome)PortableRemoteObject.narrow(finderRef,DossierHome.class);
                dossier=dossierHome.create();

          }

          public void testGetString() throws RemoteException {
                 assertEquals("Test",dossier.getTest());
          }

但问题是该客户端失败并出现错误:

      javax.naming.CommunicationException: Could not obtain connection to any of these  
      urls: localhost:1199 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 connect to server localhost:1199 
      ....


      at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1416) 

...

I created an EJB 2. I deployed it on JBoss-IDE 1.6 and then, I created a JUnit test to access it. here's the code I used for the client :

   public class DossierBeanTest extends TestCase {
         protected DossierHome dossierHome;
         protected Dossier dossier;

         public DossierBeanTest(String argo){
                super(arg0);
         }

         protected void setUp() throws Exception {
                super.setUp();
                Hashtable env=new Hashtable();


               env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
                env.put(Context.URL_PKG_PREFIXES,"org.jboss.naming:org.jnp.interfaces");
                env.put(Context.PROVIDER_URL,"jnp://localhost:1199");
                Context context=new InitialContext(env);

                Object finderRef=context.lookup(dossierHome.JNDI_NAME);
                dossierHome=(DossierHome)PortableRemoteObject.narrow(finderRef,DossierHome.class);
                dossier=dossierHome.create();

          }

          public void testGetString() throws RemoteException {
                 assertEquals("Test",dossier.getTest());
          }

but the problem is that this client fails with the error :

      javax.naming.CommunicationException: Could not obtain connection to any of these  
      urls: localhost:1199 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 connect to server localhost:1199 
      ....


      at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1416) 

....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

后eg是否自 2024-08-14 04:38:29

正如其他人已经指出的那样,JBoss 命名服务器 默认侦听端口 1099。所以,除非您在 conf/jboss-service.xml 中更改此值(服务名称 jboss:service=Naming),您应该这样写:

env.put(Context.PROVIDER_URL,"jnp://localhost:1099); 

话虽如此,我通常更喜欢提供 JNDI 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

并使用空参数构造函数 InitiatContext()

Context context = new InitialContext();

这使得代码可移植(在测试环境中可能不是问题,好吧,我更喜欢不硬编码这样的东西)。

As other already pointed out, JBoss naming server listens by default on port 1099. So, unless you changed this value in conf/jboss-service.xml (service name jboss:service=Naming), you should write:

env.put(Context.PROVIDER_URL,"jnp://localhost:1099); 

That being said, I usually prefer to provide the JNDI environment settings in a jndi.properties file (that you put on the classpath). In your case, with the following content:

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

And use the empty parameter constructor InitiatContext():

Context context = new InitialContext();

This makes the code portable (might not be an issue in a testing context, well, I prefer to not hard code such things).

当梦初醒 2024-08-14 04:38:29

我猜您使用了错误的端口号。您可以首先通过查看命令 netstat -a 的输出来检查这一点。如果没有进程正在侦听端口 1199,您必须检查 JBoss 配置。

I'd guess you are using the wrong port number. You can check this first by looking at the output of the command netstat -a. If no process is listening on port 1199 you have to inspect your JBoss configuration.

诺曦 2024-08-14 04:38:29

默认端口是1099,你改了吗?如果没有尝试从 1199 切换端口。

此外,如果您使用的是 Linux,您可能想尝试 127.0.0.1 而不是 localhost。

The default port is 1099, did you change it? if not try switching the port from 1199.

Also if you are on Linux you may want to try 127.0.0.1 instead of localhost.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文