Jboss 7 multiple threads on client side

Daniel Jipa

I have an swing application that connects to a Jboss 7 AS. Invoking some background threads causes a no such ejb error on client side. Here is an example

package com.asf.capone.client.util;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.asf.capone.common.exception.AppException;

import ro.asf.capone.ejb.beans.security.SecurityController;
import ro.asf.capone.ejb.beans.security.SecurityControllerRemote;

public class TestJndi {
public static void main(final String[] args) throws AppException {
    final Hashtable env = new Hashtable();
    env.put("java.naming.factory.initial", "org.jboss.naming.remote.client.InitialContextFactory");
    env.put("java.naming.provider.url", "remote://localhost:4447");
    env.put("java.naming.security.credentials", "c4ca4238a0b923820dcc509a6f75849b");
    env.put("java.naming.security.principal", "capone");
    env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    env.put("jboss.naming.client.ejb.context", "true");
    env.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");

    try {
        final InitialContext ctx = new InitialContext(env);
        System.out.println("ctx: " + ctx);
        final SecurityController o = (SecurityControllerRemote) ctx.lookup(
                "ejb:agency-ear/agency-ejb/SecurityControllerBean!ro.asf.capone.ejb.beans.security.SecurityControllerRemote");
        System.out.println("1outcome: " + o.getServerTimeMillis());

        new Thread(new Runnable() {

            @Override
            public void run() {
                System.out.println("2outcome: " + o.getServerTimeMillis());
            }
        }).start();

    } catch (final NamingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

The output for this is:

ctx: javax.naming.InitialContext@307f6b8c
1outcome: 1443465336127
Exception in thread "Thread-4" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:agency-ear, moduleName:agency-ejb, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@381dfddb
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:754)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:253)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:198)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
at com.sun.proxy.$Proxy2.getServerTimeMillis(Unknown Source)
at com.asf.capone.client.util.TestJndi$1.run(TestJndi.java:36)
at java.lang.Thread.run(Thread.java:745)

I am missing something that should allow me to get the same output on both calls but I cannot figure what is the problem. Thanks!

Daniel Jipa

It looks like this doesn't work on that version of Jboss (they've changed the remote) because my initial code worked in Jboss 7.3.0. My current Jboss version is JBoss EAP 6.4.0.GA (AS 7.5.0.Final-redhat-21) The code that works now is:

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.jboss.ejb.client.ContextSelector;
import org.jboss.ejb.client.EJBClientConfiguration;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration;
import org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector;

import ro.asf.capone.ejb.beans.security.SecurityControllerRemote;


public class AppJboss {
    public static void main(String[] args) throws NamingException {
       System.out.println("Hello World!");
       final String lookup = "ejb:agency-ear/agency-ejb//SecurityControllerBean!ro.asf.capone.ejb.beans.security.SecurityControllerRemote";

       final Properties clientProperties = new Properties();
       clientProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS",
            "JBOSS-LOCAL-USER");
       clientProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT",
            "false");
       clientProperties.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
       clientProperties.put("remote.connections", "default");
       clientProperties.put("endpoint.name", "client-endpoint");
       clientProperties.put("remote.connection.default.port", "4447");
       clientProperties.put("remote.connection.default.host", "127.0.0.1");
       clientProperties.put("remote.connection.default.username", "capone");
       clientProperties.put("remote.connection.default.password", "c4ca4238a0b923820dcc509a6f75849b");
       clientProperties.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS",
            "false");

       final EJBClientConfiguration ejbClientConfiguration = new PropertiesBasedEJBClientConfiguration(
            clientProperties);
       final ContextSelector<EJBClientContext> contextSelector = new ConfigBasedEJBClientContextSelector(
            ejbClientConfiguration);
       EJBClientContext.setSelector(contextSelector);

       final Properties properties = new Properties();
       properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
       final Context context = new InitialContext(properties);
       final SecurityControllerRemote myBean = (SecurityControllerRemote) context.lookup(lookup);
       final long result = myBean.getServerTimeMillis();
       System.out.println("result " + result);

       new Thread(new Runnable() {

          public void run() {
              final long result = myBean.getServerTimeMillis();
              System.out.println(result);
          }
       }).start();
    }
}

The client library was taken from jboss/bin/client/jboss-client.jar

The same code works in Wildfly also, just with the change of port and client library. Hope this helps others.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jboss 7 domain:threads configuration

From Dev

multiple threads, java chat client

From Dev

Accepting multiple simultaneous client sockets on their own threads

From Dev

How to make a Thrift client for multiple threads?

From Dev

Accepting multiple simultaneous client sockets on their own threads

From Dev

Multiple Client Threads can connect, threads are accepted in sequential order

From Dev

Unobtrusive client-side validation on multiple fields

From Dev

Should we always close javax.naming.InitialContext at client side of JBoss app?

From Dev

Accessing Multiple web applications on Jboss7 or Wildfly

From Dev

How to sort java object on client side by multiple fields?

From Dev

How does a single servlet handle multiple requests from client side

From Dev

Resource limits around multiple Firebase connections in client-side JavaScript

From Dev

How would i support multiple version of TLS on client side?

From Dev

Joining multiple audio files into a single audio file in client side

From Dev

Passing socket between multiple client side javascript files

From Dev

Sending multiple messages to a server using Java Websockets Client side?

From Dev

Yii2 client side validation for dynamically added multiple inputs

From Dev

Client authentication on JBoss server

From Dev

Java 7 Synchronized method seems to allow multiple threads access

From Dev

javax.security.sasl.SaslException: Authentic Failed while connecting to Jboss 7 server from remote client

From Dev

Windows 7 side Taskbar: how to have multiple icon columns?

From Dev

Server Side and Client Side MVC

From Dev

Server side or client side rendering

From Dev

Client side data to server side

From Dev

Restart jboss as 7 programmatically

From Dev

Jersey 2 on Jboss 7

From Dev

GroovyScriptEngine classloading in Jboss 7

From Dev

IntelliJ IDEA & JBoss AS 7

From Dev

Jboss 7 own authenticator

Related Related

  1. 1

    jboss 7 domain:threads configuration

  2. 2

    multiple threads, java chat client

  3. 3

    Accepting multiple simultaneous client sockets on their own threads

  4. 4

    How to make a Thrift client for multiple threads?

  5. 5

    Accepting multiple simultaneous client sockets on their own threads

  6. 6

    Multiple Client Threads can connect, threads are accepted in sequential order

  7. 7

    Unobtrusive client-side validation on multiple fields

  8. 8

    Should we always close javax.naming.InitialContext at client side of JBoss app?

  9. 9

    Accessing Multiple web applications on Jboss7 or Wildfly

  10. 10

    How to sort java object on client side by multiple fields?

  11. 11

    How does a single servlet handle multiple requests from client side

  12. 12

    Resource limits around multiple Firebase connections in client-side JavaScript

  13. 13

    How would i support multiple version of TLS on client side?

  14. 14

    Joining multiple audio files into a single audio file in client side

  15. 15

    Passing socket between multiple client side javascript files

  16. 16

    Sending multiple messages to a server using Java Websockets Client side?

  17. 17

    Yii2 client side validation for dynamically added multiple inputs

  18. 18

    Client authentication on JBoss server

  19. 19

    Java 7 Synchronized method seems to allow multiple threads access

  20. 20

    javax.security.sasl.SaslException: Authentic Failed while connecting to Jboss 7 server from remote client

  21. 21

    Windows 7 side Taskbar: how to have multiple icon columns?

  22. 22

    Server Side and Client Side MVC

  23. 23

    Server side or client side rendering

  24. 24

    Client side data to server side

  25. 25

    Restart jboss as 7 programmatically

  26. 26

    Jersey 2 on Jboss 7

  27. 27

    GroovyScriptEngine classloading in Jboss 7

  28. 28

    IntelliJ IDEA & JBoss AS 7

  29. 29

    Jboss 7 own authenticator

HotTag

Archive