5 Replies Latest reply: May 9, 2012 4:52 PM by Serkan Yıldırım RSS

Preventing reconnect attempt of remote ejb client

Serkan Yıldırım Newbie

Hi,

I have a remote ejb client and a custom login module. I am testing my login module, i enter an invalid password in remote client. My login module runs correctly and send an exception. However, remote client attempts to recall login module again to login user. But i do not want this. Because when there is an exception in my custom login module, i update some values in my database. Therefore the same code in login module runs twice and my db has inconsistent values. So how can i prevent this reconnect attemp of remote ejb client? I use JBOSS 7.1.2 Final SNAPSHOT version in server and jboss 7.1.1 client maven dependencies. Thanks.

 

My Client code is like below:

 

Properties pr = new Properties();

pr.put("endpoint.name", "client-endpoint");

pr.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");

pr.put("remote.connections", "default");

pr.put("remote.connection.default.port", "4447");

pr.put("remote.connection.default.host", "localhost");

pr.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");

pr.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");

pr.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");

pr.put("remote.connection.default.username", "user1");

pr.put("remote.connection.default.password", "Test12345");

EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(pr);

ContextSelector < EJBClientContext > selector = new ConfigBasedEJBClientContextSelector(cc);

EJBClientContext.setSelector(selector);

 

 

Properties props = new Properties();

props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");

props.put("jboss.naming.client.ejb.context", true);

 

 

try {

      Context c = new InitialContext(props);

      kullaniciEJB = (KullaniciEJBRemote) c.lookup("ejb:merveys-kayit-tckkys/merveys-kayit-ejb-tckkys//KullaniciEJB!tr.gov.tubitak.bilgem.uekae.deys.tckk.merveys.common.controller.ejb.kullanici.KullaniciEJBRemote");

} catch (NamingException e) {

      e.printStackTrace();

}

 

int count = kullaniciEJB.countKartIslemList(1L, null, null);

  • 1. Re: Preventing reconnect attempt of remote ejb client
    jaikiran pai Master

    The reconnect attempt will only be done if there is a subsequent request/invocation on the EJB, after the previous connection attempt failed. Are you invoking on the bean after the failed attempt? Is that the real code you posted? Can you post the rest of the code too?

  • 2. Re: Preventing reconnect attempt of remote ejb client
    Serkan Yıldırım Newbie

    Hi Jaikiran,

     

    Thank you for your reply. Sorry but I am not at work now, i will answer on Monday morning. Thanks...

  • 3. Re: Preventing reconnect attempt of remote ejb client
    Serkan Yıldırım Newbie

    Hi Jaikiran,

     

    You are right. At every subsequent request i got the exception. However, first exception occurs at:

     

    ContextSelector < EJBClientContext > selector = new ConfigBasedEJBClientContextSelector(cc);

     

    and i couldn't catch the exception. I must catch the exception, because i warn the user about entering wrong username/password or for other wrong things.

     

    I surround the code with try/catch like this:

     

    try {

         Properties pr = new Properties();

         pr.put("endpoint.name", "client-endpoint");

         pr.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");

         pr.put("remote.connections", "default");

         pr.put("remote.connection.default.port", "4447");

         pr.put("remote.connection.default.host", "localhost");

         pr.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");

         pr.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");

         pr.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");

         pr.put("remote.connection.default.username", "user1");

         pr.put("remote.connection.default.password", "Test12345");

         EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(pr);

         ContextSelector < EJBClientContext > selector = new ConfigBasedEJBClientContextSelector(cc);

         EJBClientContext.setSelector(selector);

    }

    catch (Exception ex) {

         // log ex

    }

     

    Exception occurs, but i couldn't catch it. I think it is catched in the api and logged there. Log is like below:

     

    log4j:ERROR Could not find value for key log4j.appender.file

    log4j:ERROR Could not instantiate appender named "file".

    07.05.2012 08:50:05: DEBUG logging [main] - Logging Provider: org.jboss.logging.Log4jLoggerProvider

    07.05.2012 08:50:05: DEBUG PropertiesBasedEJBClientConfiguration [main] - endpoint.create.options. has the following options {}

    07.05.2012 08:50:05: DEBUG PropertiesBasedEJBClientConfiguration [main] - remote.connectionprovider.create.options. has the following options {org.xnio.Options.SSL_ENABLED=>false}

    07.05.2012 08:50:05: DEBUG PropertiesBasedEJBClientConfiguration [main] - remote.connection.default.connect.options. has the following options {org.xnio.Options.SASL_DISALLOWED_MECHANISMS=>[JBOSS-LOCAL-USER],org.xnio.Options.SASL_POLICY_NOPLAINTEXT=>false,org.xnio.Options.SASL_POLICY_NOANONYMOUS=>false}

    07.05.2012 08:50:05: DEBUG PropertiesBasedEJBClientConfiguration [main] - remote.connection.default.channel.options. has the following options {}

    07.05.2012 08:50:05: DEBUG PropertiesBasedEJBClientConfiguration [main] - Connection org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration$RemotingConnectionConfigurationImpl@18a992f successfully created for connection named default

    07.05.2012 08:50:05: DEBUG PropertiesBasedEJBClientConfiguration [main] - No clusters configured in properties

    07.05.2012 08:50:05: DEBUG EJBClientPropertiesLoader [main] - Looking for jboss-ejb-client.properties using classloader sun.misc.Launcher$AppClassLoader@d9f9c3

    07.05.2012 08:50:05: DEBUG ConfigBasedEJBClientContextSelector [main] - EJB client context org.jboss.ejb.client.EJBClientContext@111a3ac will have no EJB receivers associated with it since there was no EJB client configuration available to create the receivers

    07.05.2012 08:50:05:  INFO xnio [main] - XNIO Version 3.0.3.GA

    07.05.2012 08:50:05:  INFO nio [main] - XNIO NIO Implementation Version 3.0.3.GA

    07.05.2012 08:50:05:  INFO remoting [main] - JBoss Remoting version 3.2.3.GA

    07.05.2012 08:50:05: DEBUG nio [Remoting "client-endpoint" read-1] - Started channel thread 'Remoting "client-endpoint" read-1', selector sun.nio.ch.WindowsSelectorImpl@16672d6

    07.05.2012 08:50:05: DEBUG nio [Remoting "client-endpoint" write-1] - Started channel thread 'Remoting "client-endpoint" write-1', selector sun.nio.ch.WindowsSelectorImpl@fd54d6

    07.05.2012 08:50:12: DEBUG client [Remoting "client-endpoint" read-1] - Client received authentication rejected for mechanism PLAIN

    07.05.2012 08:50:12: ERROR connection [Remoting "client-endpoint" read-1] - JBREM000200: Remote connection failed: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed

    07.05.2012 08:50:12:  WARN ConfigBasedEJBClientContextSelector [main] - Could not register a EJB receiver for connection to remote://localhost:4447

    java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed

        at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:91)

        at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:121)

        at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:78)

        at tr.gov.tubitak.bilgem.uekae.deys.tckk.kuvars.KuvarsEjbTestAS7.<init>(KuvarsEjbTestAS7.java:109)

        at tr.gov.tubitak.bilgem.uekae.deys.tckk.kuvars.KuvarsEjbTestAS7.main(KuvarsEjbTestAS7.java:430)

    Caused by: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed

        at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:315)

        at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:214)

        at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72)

        at org.xnio.channels.TranslatingSuspendableChannel.handleReadable(TranslatingSuspendableChannel.java:189)

        at org.xnio.channels.TranslatingSuspendableChannel$1.handleEvent(TranslatingSuspendableChannel.java:103)

        at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72)

        at org.xnio.nio.NioHandle.run(NioHandle.java:90)

        at org.xnio.nio.WorkerThread.run(WorkerThread.java:184)

        at ...asynchronous invocation...(Unknown Source)

        at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:270)

        at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:251)

        at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:349)

        at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:333)

        at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:119)

        ... 3 more

    07.05.2012 08:50:12: DEBUG ConfigBasedEJBClientContextSelector [main] - Registered a reconnect handler in EJB client context org.jboss.ejb.client.EJBClientContext@b61fd1 for remote://localhost:4447

    07.05.2012 08:50:12: DEBUG ConfigBasedEJBClientContextSelector [main] - Registered 0 remoting EJB receivers for EJB client context org.jboss.ejb.client.EJBClientContext@b61fd1

    07.05.2012 08:50:12:  INFO client [main] - JBoss EJB Client version 1.0.5.Final

    07.05.2012 08:50:12: DEBUG AutoConnectionCloser [Thread-1] - Closing endpoint "client-endpoint" <e91f5d>

     

    Could you please explain how i could catch the exception? Thanks...

  • 4. Re: Preventing reconnect attempt of remote ejb client
    jaikiran pai Master

    The EJB client API implementation which exposes certain APIs only guarantees certain exceptions. One of them is the non availability of a EJB receiver which can happen due to number of reasons, one of them being incorrect connection configurations. Auto connection setup using the properties file is one mechanism of setting up EJB receivers and in this mechanism we do not throw any exceptions and instead just log them as errors/warning and move on. So there isn't really any exception that can be caught in there. If you really want to fail/catch those exceptions yourself, then instead of letting the EJB client API auto create the connections, you can create the connections yourself in your code and then pass that connection object to EJBClientContext.registerConnection(Connection) method to register a receiver for it. Javadocs are available here http://docs.jboss.org/ejbclient/

  • 5. Re: Preventing reconnect attempt of remote ejb client
    Serkan Yıldırım Newbie

    Could you give a concrete example Jaikiran? Sorry, bu from javadocs it is difficult to find