当前位置: 首页 > 知识库问答 >
问题:

JBoss 7.1 上的远程 JNDI 查找 - 无法连接到远程主机

邓崇凛
2023-03-14

我对JavaEE非常陌生,尝试运行一个小的EJB示例,但远程JNDI查找总是失败。

到目前为止,我做了什么?

  1. 我使用Eclipse for JavaEE,在Marketplace上安装了JBossTools并创建了一个JBoss EAP 7. x运行时服务器(我在安装过程中下载了一个7.1运行时)。
  2. 我写了一些Bean,将它们部署在服务器上并启动它。
  3. 我用JNDI-Lookup编写了一些客户端代码

这是代码:

HelloWorld.java

package com.ibytecode.business;  
import javax.ejb.Remote;  
@Remote  
public interface HelloWorld {  
    public String sayHello();  
} 

HelloWorldBean.java

package com.ibytecode.businesslogic;  
import com.ibytecode.business.HelloWorld;  
import javax.ejb.Stateless;  

@Stateless  
public class HelloWorldBean implements HelloWorld {  
    public HelloWorldBean() { }  
    @Override  
    public String sayHello() {  
        return "Hello World !!!!!";  
    }  
}

EJBApplicationClient.java

package com.ibytecode.client;  
import java.util.Properties;  
import javax.naming.Context;  
import javax.naming.InitialContext;  
import javax.naming.NamingException;  
import com.ibytecode.business.HelloWorld;  

public class EJBApplicationClient {  
    public static void main(String[] args) {  
          try {  
               Properties env = new Properties();  
               env.put(Context.INITIAL_CONTEXT_FACTORY, org.wildfly.naming.client.WildFlyInitialContextFactory.class.getName());  
               env.put(Context.PROVIDER_URL, "remote://localhost:4447");  
               env.put(Context.SECURITY_PRINCIPAL, "admin");  
               env.put(Context.SECURITY_CREDENTIALS, "admin");  
               InitialContext ic = new InitialContext(env);  
               ic.lookup("java:global/HelloWorldSessionBean/HelloWorldBean");  
          } catch (NamingException e) {  
               e.printStackTrace();  
          }
    }
}

部分pom.xml

    <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-ejb-client-bom</artifactId>
        <version>16.0.0.Final</version>
        <type>pom</type>
    </dependency>
    <dependency>
        <groupId>org.wildfly</groupId>
        <artifactId>wildfly-jms-client-bom</artifactId>
        <version>16.0.0.Final</version>
        <type>pom</type>
    </dependency>

以及启动JBoss服务器时的服务器日志:

09:37:02,392 INFO  [org.jboss.modules] (main) JBoss Modules version 1.6.0.Final-redhat-1  
09:37:02,587 INFO  [org.jboss.msc] (main) JBoss MSC version 1.2.7.SP1-redhat-1  
09:37:02,667 INFO  [org.jboss.as] (MSC service thread 1-8) WFLYSRV0049: JBoss EAP 7.1.0.GA (WildFly Core 3.0.10.Final-redhat-1) starting  
09:37:03,402 INFO  [org.jboss.as.controller.management-deprecated] (Controller Boot Thread) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/core-service=management/management-interface=http-interface' is deprecated, and may be removed in future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.  
09:37:03,412 INFO  [org.wildfly.security] (ServerService Thread Pool -- 18) ELY00001: WildFly Elytron version 1.1.7.Final-redhat-1  
09:37:03,419 INFO  [org.jboss.as.controller.management-deprecated] (ServerService Thread Pool -- 24) WFLYCTL0028: Attribute 'security-realm' in the resource at address '/subsystem=undertow/server=default-server/https-listener=https' is deprecated, and may be removed in future version. See the attribute description in the output of the read-resource-description operation to learn more about the deprecation.  
09:37:03,482 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) WFLYDS0004: Found HelloWorldSessionBean.jar in deployment directory. To trigger deployment create a file called HelloWorldSessionBean.jar.dodeploy  
09:37:03,503 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0039: Creating http management service using socket-binding (management-http)  
09:37:03,512 INFO  [org.xnio] (MSC service thread 1-2) XNIO version 3.5.4.Final-redhat-1  
09:37:03,518 INFO  [org.xnio.nio] (MSC service thread 1-2) XNIO NIO Implementation Version 3.5.4.Final-redhat-1  
09:37:03,534 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 42) WFLYCLINF0001: Activating Infinispan subsystem.  
09:37:03,539 INFO  [org.jboss.as.jaxrs] (ServerService Thread Pool -- 43) WFLYRS0016: RESTEasy version 3.0.24.Final-redhat-1  
09:37:03,541 WARN  [org.jboss.as.txn] (ServerService Thread Pool -- 58) WFLYTX0013: The node-identifier attribute on the /subsystem=transactions is set to the default value. This is a danger for environments running multiple servers. Please make sure the attribute value is unique.  
09:37:03,541 INFO  [org.wildfly.extension.io] (ServerService Thread Pool -- 41) WFLYIO001: Worker 'default' has auto-configured to 16 core threads with 128 task threads based on your 8 available processors  
09:37:03,552 INFO  [org.jboss.as.jsf] (ServerService Thread Pool -- 48) WFLYJSF0007: Activated the following JSF Implementations: [main]  
09:37:03,553 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 50) WFLYNAM0001: Activating Naming Subsystem  
09:37:03,556 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 60) WFLYWS0002: Activating WebServices Extension  
09:37:03,559 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 57) WFLYSEC0002: Activating Security Subsystem  
09:37:03,580 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0003: Undertow 1.4.18.Final-redhat-2 starting  
09:37:03,586 INFO  [org.jboss.as.security] (MSC service thread 1-8) WFLYSEC0001: Current PicketBox version=5.0.2.Final-redhat-1  
09:37:03,593 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 36) WFLYJCA0004: Deploying JDBC-compliant driver class org.h2.Driver (version 1.4)  
09:37:03,595 INFO  [org.jboss.as.connector] (MSC service thread 1-2) WFLYJCA0009: Starting JCA Subsystem (WildFly/IronJacamar 1.4.6.Final-redhat-1)  
09:37:03,606 INFO  [org.jboss.as.connector.deployers.html" target="_blank">jdbc] (MSC service thread 1-1) WFLYJCA0018: Started Driver service with driver-name = h2  
09:37:03,608 INFO  [org.jboss.as.naming] (MSC service thread 1-1) WFLYNAM0003: Starting Naming Service  
09:37:03,613 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-1) WFLYMAIL0001: Bound mail session [java:jboss/mail/Default]  
09:37:03,638 INFO  [org.jboss.remoting] (MSC service thread 1-2) JBoss Remoting version 5.0.5.Final-redhat-1  
09:37:03,709 INFO  [org.jboss.as.ejb3] (MSC service thread 1-2) WFLYEJB0481: Strict pool slsb-strict-max-pool is using a max instance size of 128 (per class), which is derived from thread worker pool sizing.  
09:37:03,709 INFO  [org.jboss.as.ejb3] (MSC service thread 1-6) WFLYEJB0482: Strict pool mdb-strict-max-pool is using a max instance size of 32 (per class), which is derived from the number of CPUs on this host.  
09:37:03,725 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 59) WFLYUT0014: Creating file handler for path 'C:\Users\sbh\jboss-eap-7.1/welcome-content' with options [directory-listing: 'false', follow-symlink: 'false', case-sensitive: 'true', safe-symlink-paths: '[]']  
09:37:03,733 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0012: Started server default-server.  
09:37:03,736 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) WFLYUT0018: Host default-host starting  
09:37:03,898 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0006: Undertow HTTP listener default listening on 127.0.0.1:8080  
09:37:03,962 INFO  [org.jboss.as.patching] (MSC service thread 1-4) WFLYPAT0050: JBoss EAP cumulative patch ID is: base, one-off patches include: none  
09:37:03,972 WARN  [org.jboss.as.domain.management.security] (MSC service thread 1-3) WFLYDM0111: Keystore C:\Users\sbh\jboss-eap-7.1\standalone\configuration\application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost  
09:37:03,975 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-5) WFLYDS0013: Started FileSystemDeploymentService for directory C:\Users\sbh\jboss-eap-7.1\standalone\deployments  
09:37:03,983 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-6) WFLYSRV0027: Starting deployment of "HelloWorldSessionBean.jar" (runtime-name: "HelloWorldSessionBean.jar")  
09:37:04,002 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0006: Undertow HTTPS listener https listening on 127.0.0.1:8443  
09:37:04,012 INFO  [org.jboss.as.ejb3] (MSC service thread 1-7) WFLYEJB0493: EJB subsystem suspension complete  
09:37:04,056 INFO  [org.jboss.ws.common.management] (MSC service thread 1-3) JBWS022052: Starting JBossWS 5.1.9.Final-redhat-1 (Apache CXF 3.1.12.redhat-1)   
09:37:04,059 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-1) WFLYJCA0001: Bound data source [java:jboss/datasources/ExampleDS]  
09:37:04,168 INFO  [org.jboss.weld.deployer] (MSC service thread 1-4) WFLYWELD0003: Processing weld deployment HelloWorldSessionBean.jar  
09:37:04,194 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-4) HV000001: Hibernate Validator 5.3.5.Final-redhat-2  
09:37:04,238 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-4) WFLYEJB0473: JNDI bindings for session bean named 'HelloWorldBean' in deployment unit 'deployment "HelloWorldSessionBean.jar"' are as follows:  

    java:global/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld  
    java:app/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld  
    java:module/HelloWorldBean!com.ibytecode.business.HelloWorld  
    java:jboss/exported/HelloWorldSessionBean/HelloWorldBean!com.ibytecode.business.HelloWorld  
    java:global/HelloWorldSessionBean/HelloWorldBean  
    java:app/HelloWorldSessionBean/HelloWorldBean  
    java:module/HelloWorldBean  

09:37:04,335 INFO  [org.jboss.weld.Version] (MSC service thread 1-2) WELD-000900: 2.4.3 (redhat)  
09:37:04,358 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-7) ISPN000128: Infinispan version: Infinispan 'Chakra' 8.2.8.Final-redhat-1  
09:37:04,544 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 62) WFLYCLINF0002: Started client-mappings cache from ejb container  
09:37:04,787 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 37) WFLYSRV0010: Deployed "HelloWorldSessionBean.jar" (runtime-name : "HelloWorldSessionBean.jar")  
09:37:04,818 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server  
09:37:04,820 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management  
09:37:04,820 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990  
09:37:04,820 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: JBoss EAP 7.1.0.GA (WildFly Core 3.0.10.Final-redhat-1) started in 2688ms - Started 408 of 632 services (350 services are lazy, passive or on-demand)

所以,我认为bean和Lookup-Name的部署应该是正确的。但是当我运行客户端应用程序时,我会得到这样的输出:

Apr 11, 2019 9:40:38 AM org.wildfly.naming.client.Version   
INFO: WildFly Naming version 1.0.9.Final  
Apr 11, 2019 9:40:38 AM org.wildfly.security.Version   
INFO: ELY00001: WildFly Elytron version 1.1.7.Final-redhat-1  
Apr 11, 2019 9:40:38 AM org.xnio.Xnio   
INFO: XNIO version 3.6.5.Final  
Apr 11, 2019 9:40:38 AM org.xnio.nio.NioXnio   
INFO: XNIO NIO Implementation Version 3.6.5.Final  
Apr 11, 2019 9:40:38 AM org.jboss.threads.Version   
INFO: JBoss Threads version 2.3.3.Final  
Apr 11, 2019 9:40:38 AM org.jboss.remoting3.EndpointImpl   
INFO: JBoss Remoting version 5.0.8.Final  
javax.naming.CommunicationException: WFNAM00018: Failed to connect to remote host [Root exception is java.net.ConnectException: Connection refused: no further information]  
    at org.wildfly.naming.client.remote.RemoteNamingProvider.getPeerIdentityForNaming(RemoteNamingProvider.java:110)  
    at org.wildfly.naming.client.remote.RemoteNamingProvider.getPeerIdentityForNaming(RemoteNamingProvider.java:53)  
    at org.wildfly.naming.client.NamingProvider.getPeerIdentityForNamingUsingRetry(NamingProvider.java:105)  
    at org.wildfly.naming.client.remote.RemoteNamingProvider.getPeerIdentityForNamingUsingRetry(RemoteNamingProvider.java:91)  
    at org.wildfly.naming.client.remote.RemoteContext.lambda$lookupNative$0(RemoteContext.java:189)  
    at org.wildfly.naming.client.NamingProvider.performExceptionAction(NamingProvider.java:222)  
    at org.wildfly.naming.client.remote.RemoteContext.performWithRetry(RemoteContext.java:100)  
    at org.wildfly.naming.client.remote.RemoteContext.lookupNative(RemoteContext.java:188)  
    at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:74)  
    at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:60)  
    at org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:144)  
    at javax.naming.InitialContext.lookup(Unknown Source)  
    at com.ibytecode.client.EJBApplicationClient.testRemoteJNDILookup(EJBApplicationClient.java:27)  
    at com.ibytecode.client.EJBApplicationClient.main(EJBApplicationClient.java:16)  
Caused by: java.net.ConnectException: Connection refused: no further information  
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)  
    at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)  
    at org.xnio.nio.WorkerThread$ConnectHandle.handleReady(WorkerThread.java:327)  
    at org.xnio.nio.WorkerThread.run(WorkerThread.java:591)  
    at ...asynchronous invocation...(Unknown Source)  
    at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:571)  
    at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:537)  
    at org.jboss.remoting3.ConnectionInfo$None.getConnection(ConnectionInfo.java:82)  
    at org.jboss.remoting3.ConnectionInfo.getConnection(ConnectionInfo.java:55)  
    at org.jboss.remoting3.EndpointImpl.doGetConnection(EndpointImpl.java:488)  
    at org.jboss.remoting3.EndpointImpl.getConnectedIdentity(EndpointImpl.java:434)  
    at org.jboss.remoting3.UncloseableEndpoint.getConnectedIdentity(UncloseableEndpoint.java:52)  
    at org.wildfly.naming.client.remote.RemoteNamingProvider.getFuturePeerIdentityPrivileged(RemoteNamingProvider.java:151)  
    at org.wildfly.naming.client.remote.RemoteNamingProvider.lambda$getFuturePeerIdentity$0(RemoteNamingProvider.java:138)  
    at java.security.AccessController.doPrivileged(Native Method)  
    at org.wildfly.naming.client.remote.RemoteNamingProvider.getFuturePeerIdentity(RemoteNamingProvider.java:138)  
    at org.wildfly.naming.client.remote.RemoteNamingProvider.getPeerIdentity(RemoteNamingProvider.java:126)  
    at org.wildfly.naming.client.remote.RemoteNamingProvider.getPeerIdentityForNaming(RemoteNamingProvider.java:106)  
    ... 13 more

我想我只是缺少一些简单的配置。非常感谢任何帮助!谢谢!

共有2个答案

徐欣德
2023-03-14

你好,

对于JBoss EAP 7.1,锁定完全改变,Alister的答案只适用于JBoss EAP 6.4。

这是JBoss EAP 7.1的查找:然后是:

props.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
props.put(Context.PROVIDER_URL,"remote+http://localhost:8080");
props.put(Context.SECURITY_PRINCIPAL, "adm");
props.put(Context.SECURITY_CREDENTIALS, "adm");

突出显示 JBoss EAP 7.1 中Context.INITIAL_CONTEXT_FACTORY更改为 org.wildfly.nameing.client.WildFlyInitialContextFactory

您的查找将是(例如):

SumRemote remote = (SumRemote) getInitialContext().lookup("ejb:/EjbSum/Sum!SumRemote");

当 JBoss EAP 启动时,您可以在日志中看到它:

03:12:20,923 INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-6) WFLYEJB0473: JNDI bindings for session bean named 'Sum' in deployment unit 'deployment "EjbSum.jar"' are as follows:

    java:global/EjbSum/Sum!SumRemote
    java:app/EjbSum/Sum!SumRemote
    java:module/Sum!SumRemote
    java:jboss/exported/EjbSum/Sum!SumRemote
    ejb:/EjbSum/Sum!SumRemote
    java:global/EjbSum/Sum
    java:app/EjbSum/Sum
    java:module/Sum

尹雅健
2023-03-14

我有JNDI-Lookup的工作客户端代码。唯一的问题是它适用于jBoss EAP 6.4,而不是jBoss EAP 7.1。如果您使用正确的应用程序用户凭据,假设它足以更改ic.lookup("java: global/HelloWorldSessionBean/HelloWorldBean");

< code > IC . lookup(" HelloWorldSessionBean/hello world bean ");

在代码中。以下是我的工作示例

private static RepFormsEJBRemote lookupRemoteEJB() throws NamingException {
    RepFormsEJBRemote rf;
    Properties jndiProperties = new Properties();
    jndiProperties.put("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    jndiProperties.put("jboss.naming.client.ejb.context", true);
    jndiProperties.put(Context.PROVIDER_URL, "remote://172.21.0.12:4447");
    jndiProperties.put(Context.SECURITY_PRINCIPAL, "jmsuser"); //
    jndiProperties.put(Context.SECURITY_CREDENTIALS, "qwertyasd34,");  // 
    final Context context = new InitialContext(jndiProperties);
    rf = (RepFormsEJBRemote) context.lookup("ModuleEAR/ModuleWar/RepFormsEJB!com.somename.interfaces.RepFormsEJBRemote");
    return rf;
}
 类似资料:
  • 使用VisualVM,我可以看到两种类型来连接远程主机。 > jstatd 所以我正在尝试使用JMX,我学习了很多教程,但到目前为止还没有成功。 目前,有我的桌面和一个运行java服务器应用程序的linux盒子。我正在尝试在桌面上设置VisualVM客户端,以查看在linux Box上运行的java应用程序。 我为Linux上的java应用程序在start.sh脚本上添加了以下JAVA_OPTS脚

  • 问题内容: 我有以下骆驼对Redis进行投票: 而且效果很好。但是,当我将redisUri从 至 我收到以下错误: 我检查了通过telnet到并使用redis-cli可以访问elasticache。 连接到远程主机时出现此错误是什么? 我的本地redis和elasticache redis都运行2.8.24。运行骆驼2.17.1。 问题答案: 这是我的工作方式: 属性文件: 骆驼路线与以前相同。

  • 我在A机上设置了伪分布式模式的Hadoop和Hbase,我正在B机上运行我的客户端(Java程序)(A机和B机可以互相通信)。但我这样做面临问题。 我的客户端代码如下所示: 配置config=HBaseConfiguration.create(); config.set(“HBase.ZookeePer.quorum”,zookeeperLocation);config.set(“hbase.zo

  • 问题内容: 我正在尝试使用jstatd用jps查询远程JVM,以便最终使用VisualVM对其进行监视。 我让jstatd使用以下安全策略运行: jstatd在带有1.6.0_10版本的HotSpot vm的64位Linux机器上运行。jstatd命令是: 我正在尝试从Windows 7计算机运行jps。由于防火墙的限制,我通过SSH隧道将RMI数据通过隧道传输到我的Windows计算机,这样jp

  • 当我试图将我的一台机器用作WinRM客户端以连接到另一台机器时,我的一台机器出现问题。场景是: Window 7上的问题机器(VM A)已经启用了WinRM(已经运行winrm快速配置,Enable-PSRemoting),然后我将远程机器(VM C)的IP添加到VM A的受信任主机中,然后运行Test-WSMan,我得到这个错误Test-WSMan: 客户端无法连接到请求中指定的目标。验证目标上

  • 我正在尝试使用JProfiler分析远程主机/服务器上的Web应用程序,但该过程似乎比我想象的要复杂。 我已经设法在我的开发工作副本上本地评测了,但结果在那里没有用处。 有没有一种方法可以将JProfiler连接到该服务器,而无需将其安装在远程机器/服务器上,因为这不是我拥有的选项。类似于远程调试,我在其中配置主机和端口并连接。 提前感谢!