10 Replies Latest reply on May 5, 2013 1:17 PM by gabfssilva Branched to a new discussion.

    ClassCastException: SingleOption cannot be cast to Option when accessing initial context from JBoss to JBoss

    sebbay

      Hello,

       

      I deployed 2 EAR's on one JBoss instance. The ejb's are included in A.ear. A class of B.ear is calling an ejb of A.ear.

       

      To access the initial context (from B.ear), I use the following code:

       

      InitialContext result = null;

      Properties h = new Properties();

      h.put(Context.INITIAL_CONTEXT_FACTORY, serverCtxFactory);

      h.put(Context.PROVIDER_URL, "remote://10.2.5.81:10106");

      h.put(Context.SECURITY_PRINCIPAL, appServerUser);

      h.put(Context.SECURITY_CREDENTIALS, appServerPassword);

       

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

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

      h.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");

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

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

       

      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", "10106");

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

      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", appServerUser);

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

       

      EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(pr);

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

      EJBClientContext.setSelector(selector);

       

      result = new InitialContext(h);

       

      This works, when accessing an ejb from a remote client, like a tomcat.

      But when access the ejb on the same JBoss instance, I get the following error:

       

      07:55:11,452 INFO  [stdout] (Thread-71) java.lang.ClassCastException: org.xnio.SingleOption cannot be cast to org.xnio.Option                                                          

      07:55:11,452 INFO  [stdout] (Thread-71)         at org.xnio.Option.fromString(Option.java:155)                                                                                         

      07:55:11,452 INFO  [stdout] (Thread-71)         at org.xnio.OptionMap$Builder.parseAll(OptionMap.java:316)                                                                             

      07:55:11,453 INFO  [stdout] (Thread-71)         at org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration.getOptionMapFromProperties(PropertiesBasedEJBClientConfiguration.java:175)

      07:55:11,453 INFO  [stdout] (Thread-71)         at org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration.parseProperties(PropertiesBasedEJBClientConfiguration.java:162)          

      07:55:11,453 INFO  [stdout] (Thread-71)         at org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration.<init>(PropertiesBasedEJBClientConfiguration.java:110)                   

      07:55:11,454 INFO  [stdout] (Thread-71)         at com.test.web.util.Translator.getInitialContext(Translator.java:880)                                                 

      07:55:11,454 INFO  [stdout] (Thread-71)         at com.test.web.util.Translator.getTranslationManager(Translator.java:962)                                             

      07:55:11,454 INFO  [stdout] (Thread-71)         at com.test.web.util.Translator$1.run(Translator.java:610)                                                             

      07:55:11,455 INFO  [stdout] (Thread-71)         at java.lang.Thread.run(Thread.java:662)                                                                                               

       

      Has someone a solution for this problem?

       

      Best regards,

      sebbay

        • 1. Re: ClassCastException: SingleOption cannot be cast to Option when accessing initial context from JBoss to JBoss
          wdfink

          In the same JBoss instance you use call-by-reference, remote it is call-by-value because of the selialization.

           

          You have two options, set the call-by-value for local calls, but I don't recommend this because of the performance.

           

          Second is to check how you package the application, I suppose that you include the org.xnio libraries in the deployed archives.

          In this case it will be loaded by different classloaders that cause this error.

          • 2. Re: ClassCastException: SingleOption cannot be cast to Option when accessing initial context from JBoss to JBoss
            sebbay

            I included jboss-client.jar in B.ear. In A.ear, there are no JBoss libs included.

            Remove jboss-client.jar from B.ear causes the following warnings and exceptions.

             

            How must B.ear be configured to find the class org.xnio.Options?

             

            09:10:33,616 INFO  [stdout] (Thread-71) now creating initial context

            09:10:33,626 WARN  [org.xnio.option.parse] (Thread-71) Invalid option 'org.xnio.Options.SSL_ENABLED' in property 'remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED': java.lang.IllegalArgumentException: Class 'org.xnio.Options' not found

            09:10:33,627 WARN  [org.xnio.option.parse] (Thread-71) Invalid option 'org.xnio.Options.SASL_POLICY_NOPLAINTEXT' in property 'remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT': java.lang.IllegalArgumentException: Class 'org.xnio.Options' not found

            09:10:33,628 WARN  [org.xnio.option.parse] (Thread-71) Invalid option 'org.xnio.Options.SASL_DISALLOWED_MECHANISMS' in property 'remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS': java.lang.IllegalArgumentException: Class 'org.xnio.Options' not found

            09:10:33,629 WARN  [org.xnio.option.parse] (Thread-71) Invalid option 'org.xnio.Options.SASL_POLICY_NOANONYMOUS' in property 'remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS': java.lang.IllegalArgumentException: Class 'org.xnio.Options' not found

            09:10:33,750 ERROR [org.jboss.remoting.remote.connection] (Remoting "dev-cob-vm-0081" read-1) JBREM000200: Remote connection failed: java.io.IOException: Received an invalid message length of -2140864253

            09:10:33,750 ERROR [org.jboss.remoting.remote.connection] (Remoting "client-endpoint" read-1) JBREM000200: Remote connection failed: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

            09:10:33,768 WARN  [org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector] (Thread-71) Could not register a EJB receiver for connection to remote://10.2.5.81:10106: java.lang.RuntimeException: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

                      at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:91) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                      at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.setupEJBReceivers(ConfigBasedEJBClientContextSelector.java:121) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                      at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<init>(ConfigBasedEJBClientContextSelector.java:78) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                      at com.test.web.util.Translator.getInitialContext(Translator.java:881) [b3struts.jar:]

                      at com.test.web.util.Translator.getTranslationManager(Translator.java:962) [b3struts.jar:]

                      at com.test.web.util.Translator$1.run(Translator.java:610) [b3struts.jar:]

                      at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_32]

            Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

                      at com.sun.net.ssl.internal.ssl.EngineInputRecord.bytesInCompletePacket(EngineInputRecord.java:152) [jsse.jar:1.6]

                      at com.sun.net.ssl.internal.ssl.SSLEngineImpl.readNetRecord(SSLEngineImpl.java:806) [jsse.jar:1.6]

                      at com.sun.net.ssl.internal.ssl.SSLEngineImpl.unwrap(SSLEngineImpl.java:721) [jsse.jar:1.6]

                      at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:607) [jsse.jar:1.6]

                      at org.xnio.ssl.JsseConnectedSslStreamChannel.unwrap(JsseConnectedSslStreamChannel.java:443)

                      at org.xnio.ssl.JsseConnectedSslStreamChannel.read(JsseConnectedSslStreamChannel.java:484)

                      at org.xnio.ssl.JsseConnectedSslStreamChannel.read(JsseConnectedSslStreamChannel.java:449)

                      at org.xnio.channels.FramedMessageChannel.receive(FramedMessageChannel.java:88)

                      at org.jboss.remoting3.remote.ClientConnectionOpenListener$Greeting.handleEvent(ClientConnectionOpenListener.java:138)

                      at org.jboss.remoting3.remote.ClientConnectionOpenListener$Greeting.handleEvent(ClientConnectionOpenListener.java:130)

                      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.channels.TranslatingSuspendableChannel.handleReadable(TranslatingSuspendableChannel.java:189)

                      at org.xnio.ssl.JsseConnectedSslStreamChannel.handleReadable(JsseConnectedSslStreamChannel.java:180)

                      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.safeRun(WorkerThread.java:205)

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

                      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) [jboss-ejb-client-1.0.5.Final.jar:1.0.5.Final]

                      ... 5 more

            • 3. Re: ClassCastException: SingleOption cannot be cast to Option when accessing initial context from JBoss to JBoss
              wdfink

              I suppose you use AS7.

              In that case you have to set a dependency to the org.xno module.

              See https://docs.jboss.org/author/display/AS71/Class+Loading+in+AS7

              • 4. Re: ClassCastException: SingleOption cannot be cast to Option when accessing initial context from JBoss to JBoss
                sebbay

                OK, I added the following to the jboss-deployment-structure.xml of B.ear:

                 

                  <sub-deployment name="[application].war">

                    <exclusions><module name="org.apache.log4j" /></exclusions>

                    <dependencies>

                      <module name="org.jboss.xnio" />

                    </dependencies>

                  </sub-deployment>

                 

                The error Class 'org.xnio.Options' not found no longer occurs. Now this is the problem:

                 

                10:01:34,894 INFO  [org.jboss.ejb.client.remoting.VersionReceiver] (Remoting "client-endpoint" task-4) Received server version 1 and marshalling strategies [river]

                10:01:34,899 INFO  [org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver] (Thread-71) Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@123dac34, receiver=Remoting connection EJB receiver [connection=Remoting connection <4f1cfc0d>,channel=jboss.ejb,nodename=dev-cob-vm-0081]} on channel Channel ID a2a303c0 (outbound) of Remoting connection 62736dde to /10.2.5.81:10106

                10:01:34,913 WARN  [org.jboss.ejb.client.remoting.ChannelAssociation] (Remoting "client-endpoint" task-2) Unsupported message received with header 0xffffffff

                10:01:34,919 INFO  [stdout] (Thread-71) 2012-06-21 10:01:34.913          819          ERROR          Translator          *** ERROR - Translator.getTranslation without member: Exception

                10:01:34,920 INFO  [stdout] (Thread-71) java.lang.SecurityException: EJB client context selector may not be changed

                10:01:34,920 INFO  [stdout] (Thread-71)           at org.jboss.ejb.client.EJBClientContext.setSelector(EJBClientContext.java:181)

                10:01:34,920 INFO  [stdout] (Thread-71)           at com.test.web.util.Translator.getInitialContext(Translator.java:882)

                10:01:34,920 INFO  [stdout] (Thread-71)           at com.test.web.util.Translator.getTranslationManager(Translator.java:962)

                10:01:34,921 INFO  [stdout] (Thread-71)           at com.test.web.util.Translator$1.run(Translator.java:610)

                10:01:34,921 INFO  [stdout] (Thread-71)           at java.lang.Thread.run(Thread.java:662)

                • 5. Re: ClassCastException: SingleOption cannot be cast to Option when accessing initial context from JBoss to JBoss
                  wdfink

                  There are only INFO messages. The WARN can be ignored it will be no longer a WARN message in further versions.

                   

                  But what about your application? Does it work?

                  • 6. Re: ClassCastException: SingleOption cannot be cast to Option when accessing initial context from JBoss to JBoss
                    sebbay

                    The error is logged as INFO, that is a problem of the application I think. The application catches the throwable.

                    What you see in the stacktrace is the error which occured when setSelector is executed.

                     

                    The application doesn't work.

                    • 7. Re: ClassCastException: SingleOption cannot be cast to Option when accessing initial context from JBoss to JBoss
                      wdfink

                      I think this is a false use of the ejb-client interface.

                      You should have a look into this documentation

                      • 8. Re: ClassCastException: SingleOption cannot be cast to Option when accessing initial context from JBoss to JBoss
                        sebbay

                        Thanks. This article describes the configuration, if A.ear and B.ear are on different JBoss instances.

                        Can I also use this configuration if A.ear and B.ear are on the same instance?

                        • 9. Re: ClassCastException: SingleOption cannot be cast to Option when accessing initial context from JBoss to JBoss
                          sebbay

                          I changed the "client"-code to:

                           

                          InitialContext result = null;

                          Properties h = new Properties();

                           

                          h.put("java.naming.security.principal", appServerUser);

                          h.put("java.naming.security.credentials", appServerPassword);

                          h.put("java.naming.factory.url.pkgs", "org.jboss.ejb.client.naming");

                           

                          result = new InitialContext(h);

                           

                          jboss-deployment-strucuture.xml has the following dependencies:

                           

                          <dependencies>

                            <module name="org.jboss.xnio" />

                            <module name="org.jboss.remote-naming" />

                            <module name="org.jboss.ejb-client" />

                          </dependencies>

                           

                          standalone.xml has these entries:

                           

                          <subsystem xmlns="urn:jboss:domain:remoting:1.1">

                              <connector name="remoting-connector" socket-binding="remoting" security-realm="TestRealm"/>

                              <outbound-connections>

                          <remote-outbound-connection name="remote-ejb-connection" outbound-socket-binding-ref="remote-ejb" security-realm="TestRealm">

                          <properties>

                          <property name="SASL_POLICY_NOANONYMOUS" value="false"/>

                          <property name="SSL_ENABLED" value="false"/>

                          </properties>

                          </remote-outbound-connection>

                              </outbound-connections>

                          </subsystem>

                           

                          <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">

                               ...

                            <socket-binding name="remoting" port="10106"/>

                               ...

                            <outbound-socket-binding name="remote-ejb">

                              <remote-destination host="10.2.5.81" port="10106"/>

                            </outbound-socket-binding>

                          </socket-binding-group>

                           

                          But I still get this error:

                           

                          15:40:04,842 INFO  [stdout] (Thread-71) 2012-06-21 15:40:04.839            808         ERROR  Translator           *** ERROR - Translator.getTranslation without member: Exception

                          15:40:04,843 INFO  [stdout] (Thread-71) javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException: Failed to setup EJB remote context]

                          15:40:04,843 INFO  [stdout] (Thread-71)              at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)

                          15:40:04,843 INFO  [stdout] (Thread-71)              at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121)

                          15:40:04,844 INFO  [stdout] (Thread-71)              at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)

                          15:40:04,844 INFO  [stdout] (Thread-71)              at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)

                          15:40:04,844 INFO  [stdout] (Thread-71)              at javax.naming.InitialContext.init(InitialContext.java:223)

                          15:40:04,844 INFO  [stdout] (Thread-71)              at javax.naming.InitialContext.<init>(InitialContext.java:197)

                          15:40:04,844 INFO  [stdout] (Thread-71)              at com.test.web.util.Translator.getInitialContext(Translator.java:879)

                          15:40:04,845 INFO  [stdout] (Thread-71)              at com.test.web.util.Translator.getTranslationManager(Translator.java:957)

                          15:40:04,845 INFO  [stdout] (Thread-71)              at com.test.web.util.Translator$1.run(Translator.java:605)

                          15:40:04,845 INFO  [stdout] (Thread-71)              at java.lang.Thread.run(Thread.java:662)

                          15:40:04,845 INFO  [stdout] (Thread-71) Caused by: java.lang.RuntimeException: Failed to setup EJB remote context

                          15:40:04,846 INFO  [stdout] (Thread-71)              at org.jboss.naming.remote.client.InitialContextFactory.setupEjbContext(InitialContextFactory.java:438)

                          15:40:04,846 INFO  [stdout] (Thread-71)              at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:115)

                          15:40:04,846 INFO  [stdout] (Thread-71)              ... 8 more

                          15:40:04,846 INFO  [stdout] (Thread-71) Caused by: java.lang.reflect.InvocationTargetException

                          15:40:04,847 INFO  [stdout] (Thread-71)              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                          15:40:04,847 INFO  [stdout] (Thread-71)              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

                          15:40:04,847 INFO  [stdout] (Thread-71)              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

                          15:40:04,847 INFO  [stdout] (Thread-71)              at java.lang.reflect.Method.invoke(Method.java:597)

                          15:40:04,847 INFO  [stdout] (Thread-71)              at org.jboss.naming.remote.client.InitialContextFactory.setupEjbContext(InitialContextFactory.java:420)

                          15:40:04,848 INFO  [stdout] (Thread-71)              ... 9 more

                          15:40:04,848 INFO  [stdout] (Thread-71) Caused by: java.lang.SecurityException: EJB client context selector may not be changed

                          15:40:04,848 INFO  [stdout] (Thread-71)              at org.jboss.ejb.client.EJBClientContext.setSelector(EJBClientContext.java:181)

                          15:40:04,848 INFO  [stdout] (Thread-71)              at org.jboss.naming.remote.client.ejb.RemoteNamingEjbClientContextSelector.setupSelector(RemoteNamingEjbClientContextSelector.java:18)

                          15:40:04,849 INFO [stdout] (Thread-71)              ... 14 more

                          • 10. Re: ClassCastException: SingleOption cannot be cast to Option when accessing initial context from JBoss to JBoss
                            gabfssilva

                            Did you solve your issue? I'm having the same here. :/