Я новичок в JavaEE и пытаюсь запустить небольшой пример EJB, но всегда терплю неудачу с удаленным JNDI-Lookup.
Что я делал до сих пор?
- Я использую Eclipse для JavaEE, установил JBossTools из Marketplace и создал JBoss EAP 7.x Runtime Server (я загрузил среду выполнения 7.1 во время установки).
- Я написал несколько Бинов, развернул их на сервере и запустил.
- Я написал некоторый код клиента с помощью 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.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
Полагаю, мне не хватает какой-то простой конфигурации.
Любая помощь высоко ценится! Спасибо!