[JBoss] JBoss EAP 6.4 End to End HelloWorld RMI Example Not Working

Discussão em 'StackOverflow' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    What I tried already is having a simple HelloWorld application that has also java client code to try and invoke the session bean deployed in JBoss EAP 6.4 as shown in the details below but I couldn't get it to work. The error message I got was:

    Sep 18, 2024 11:58:55 AM org.xnio.Xnio <clinit>
    INFO: XNIO version 3.3.8.Final
    Sep 18, 2024 11:58:55 AM org.xnio.nio.NioXnio <clinit>
    INFO: XNIO NIO Implementation Version 3.3.8.Final
    Sep 18, 2024 11:58:55 AM org.jboss.remoting3.EndpointImpl <clinit>
    INFO: JBoss Remoting version 4.0.5.Final
    Sep 18, 2024 11:58:55 AM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
    INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
    Sep 18, 2024 11:58:55 AM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
    INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@343f4d3d, receiver=Remoting connection EJB receiver [connection=Remoting connection <6a64433e>,channel=jboss.ejb,nodename=developers-macbook-pro]} on channel Channel ID c3ce81a3 (outbound) of Remoting connection 72d818d1 to localhost/127.0.0.1:4447
    javax.naming.NameNotFoundException: global/jboss-helloworld/HelloWorldBean!org.example.HelloWorldRemote -- service jboss.naming.context.java.jboss.exported.global.jboss-helloworld."HelloWorldBean!org.example.HelloWorldRemote"
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:104)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:197)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:174)
    at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
    at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:750)

    Process finished with exit code 0


    This is probably a repeat question but from what I looked up before, I saw some questions regarding this but no specific answer that relates to JBoss EAP 6.4. Ultimately, what I intend to achieve is migrate an application that is using EJB2.x entity beans and ejb-jar.xml based configuration style for the beans from JBoss 5 to JBoss EAP 6.4.

    Apparently, what I intend to achieve is just having an end-to-end working HelloWorld example where I can invoke a session bean from a Java code client. I have tried a couple of things to no avail.

    Below is what I tried (maven based):

    pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>jboss-6-4-helloworld-2</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
    <!-- EJB API for Remote Lookup -->
    <dependency>
    <groupId>org.jboss.spec.javax.ejb</groupId>
    <artifactId>jboss-ejb-api_3.1_spec</artifactId>
    <version>1.0.2.Final</version>
    <scope>provided</scope>
    </dependency>

    <!-- JBoss EJB Client -->
    <dependency>
    <groupId>org.jboss</groupId>
    <artifactId>jboss-ejb-client</artifactId>
    <version>2.1.0.Final</version>
    </dependency>

    <!-- JBoss Remoting for Communication -->
    <dependency>
    <groupId>org.jboss.remoting3</groupId>
    <artifactId>jboss-remoting</artifactId>
    <version>3.3.12.Final</version>
    </dependency>

    <!-- Remote Naming -->
    <dependency>
    <groupId>org.jboss</groupId>
    <artifactId>jboss-remote-naming</artifactId>
    <version>2.0.4.Final</version>
    </dependency>

    <!-- XNIO (Non-blocking IO used by JBoss) -->
    <dependency>
    <groupId>org.jboss.xnio</groupId>
    <artifactId>xnio-api</artifactId>
    <version>3.3.8.Final</version>
    </dependency>
    <dependency>
    <groupId>org.jboss.xnio</groupId>
    <artifactId>xnio-nio</artifactId>
    <version>3.3.8.Final</version>
    </dependency>

    <!-- JBoss Logging -->
    <dependency>
    <groupId>org.jboss.logging</groupId>
    <artifactId>jboss-logging</artifactId>
    <version>3.1.4.GA</version>
    </dependency>

    <!-- SLF4J (Optional: if using with logging framework) -->
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.25</version>
    </dependency>

    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.7.25</version>
    </dependency>
    </dependencies>

    <build>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.1</version>
    <configuration>
    <source>1.8</source>
    <target>1.8</target>
    </configuration>
    </plugin>
    </plugins>
    <finalName>jboss-eap-client</finalName>
    </build>
    </project>


    HelloWorldClient.java

    package org.example.client;

    import org.example.HelloWorldRemote;

    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import java.util.Hashtable;

    public class HelloWorldClient {

    public static void main(String[] args) {
    try {
    // Set up the environment for creating the InitialContext
    Hashtable<String, String> env = new Hashtable<>();
    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    env.put(Context.PROVIDER_URL, "remote://localhost:4447"); // Update with your server's IP and port
    env.put(Context.SECURITY_PRINCIPAL, "xxx"); // Optional if authentication is required
    env.put(Context.SECURITY_CREDENTIALS, "xxxx"); // Optional if authentication is required
    env.put("jboss.naming.client.ejb.context", "true");

    // Create the InitialContext
    Context context = new InitialContext(env);

    // Lookup the EJB (using JNDI name)
    String jndiName = "java:global/jboss-helloworld/HelloWorldBean!org.example.HelloWorldRemote";
    HelloWorldRemote hello = (HelloWorldRemote) context.lookup(jndiName);

    // Call the remote method
    String response = hello.sayHello("JBoss EAP");
    System.out.println("Response from EJB: " + response);

    } catch (NamingException e) {
    e.printStackTrace();
    }
    }
    }


    HelloWorldRemote.java

    package org.example;

    import javax.ejb.Remote;

    @Remote
    public interface HelloWorldRemote {
    String sayHello(String name);
    }


    HelloWorldBean.java

    package org.example;

    import javax.ejb.Stateless;

    @Stateless
    public class HelloWorldBean implements HelloWorldRemote {

    @Override
    public String sayHello(String name) {
    return "Hello, " + name;
    }
    }


    I have JBoss EAP 6.4 installed on my local machine and I am deploying my application in standalone mode and using the standalone.xml configuration just for this HelloWorld POC.

    standalone.xml (Used it exactly as it comes - no modifications)

    Output from running my server:

    12:11:50,437 INFO [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named HelloWorldBean in deployment unit deployment "jboss-eap-client.jar" are as follows:

    java:global/jboss-eap-client/HelloWorldBean!org.example.HelloWorldRemote
    java:app/jboss-eap-client/HelloWorldBean!org.example.HelloWorldRemote
    java:module/HelloWorldBean!org.example.HelloWorldRemote
    java:jboss/exported/jboss-eap-client/HelloWorldBean!org.example.HelloWorldRemote
    java:global/jboss-eap-client/HelloWorldBean
    java:app/jboss-eap-client/HelloWorldBean
    java:module/HelloWorldBean

    12:11:50,533 INFO [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS015859: Deployed "jboss-eap-client.jar" (runtime-name : "jboss-eap-client.jar")
    12:11:50,540 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
    12:11:50,540 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
    12:11:50,541 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.4.0.GA (AS 7.5.0.Final-redhat-21) started in 1105ms - Started 201 of 239 services (59 services are lazy, passive or on-demand)


    mvn dependency:tree

    [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ jboss-6-4-helloworld-2 ---
    [INFO] org.example:jboss-6-4-helloworld-2:jar:1.0-SNAPSHOT
    [INFO] +- org.jboss.spec.javax.ejb:jboss-ejb-api_3.1_spec:jar:1.0.2.Final:provided
    [INFO] +- org.jboss:jboss-ejb-client:jar:2.1.0.Final:compile
    [INFO] | +- org.jboss.marshalling:jboss-marshalling:jar:1.4.3.Final:compile
    [INFO] | \- org.jboss.remoting:jboss-remoting:jar:4.0.5.Final:compile
    [INFO] +- org.jboss.remoting3:jboss-remoting:jar:3.3.12.Final:compile
    [INFO] +- org.jboss:jboss-remote-naming:jar:2.0.4.Final:compile
    [INFO] | +- org.jboss.marshalling:jboss-marshalling-river:jar:1.4.3.Final:compile
    [INFO] | \- org.jboss.sasl:jboss-sasl:jar:1.0.4.Final:compile
    [INFO] +- org.jboss.xnio:xnio-api:jar:3.3.8.Final:compile
    [INFO] +- org.jboss.xnio:xnio-nio:jar:3.3.8.Final:compile
    [INFO] +- org.jboss.logging:jboss-logging:jar:3.1.4.GA:compile
    [INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
    [INFO] \- org.slf4j:slf4j-simple:jar:1.7.25:compile
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------


    Also, I managed to add new users one management user and one other application user.

    Same username and password for both management and application users.

    The main reason why I am using JBoss EAP 6.4 is because according to the research I did it has got support for backward compatibility for entity beans as well support for JPA 2.0 and CDI annotations. Kindly advise also if there are other better ways to approach this.

    A link to a working example would be appreciated.

    Continue reading...

Compartilhe esta Página