6 Replies Latest reply on Dec 5, 2013 9:17 PM by hai_feng

    How to remote lookup resource adapter in Jboss 7.1.0.Final?

    mr.bee

      HI Everyone!

       

      I have deployed a resource adapter and added a connection definition in standalone.xml.

      Now i have to test it's connection using remote client.

       

      Following is the resource adapter configuration :

       

           <resource-adapter>

                <archive>insiteconnect.rar</archive>

                <transaction-support>NoTransaction</transaction-support>

                <connection-definitions>

                        <connection-definition class-name="com.lgc.dsl.services.teiid.resource.adapter.insite.InsiteManagedConnectionFactory" jndi-name="java:/insite" enabled="true" pool-name="insite">

                             <config-property name="InsiteServer">134.132.115.102</config-property>

                             <config-property name="PSLAttribute">8</config-property>

                             <config-property name="UserName">user</config-property>

                             <config-property name="Password">password</config-property>

                             <pool>

                                  <min-pool-size>5</min-pool-size>

                                  <max-pool-size>10</max-pool-size>

                             </pool>

                     </connection-definition>

                   </connection-definitions>

              <resource-adapter>

       

      -------------------------------------------------------------Jboss Console -------------------------------------------------------------------------------------------------------------------------

       

                12:11:36,868 INFO  [org.jboss.as.deployment.connector] (MSC service thread 1-4) JBAS010406: Registered connection factory java:/insite

                12:11:36,888 INFO  [org.jboss.as.deployment.connector] (MSC service thread 1-4) JBAS010401: Bound JCA ConnectionFactory [java:/insite]

      w

      -------------------------------------------------- Remote Client Application ----------------------------------------------------------------------------------------------------------------

       

           Properties jndiProps = new Properties();

           jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

           jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447");

       

           Context ctx = new InitialContext(jndiProps);

           Object object = ctx.lookup("java:/insite");

       

      ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

       

           Error:

      javax.naming.NameNotFoundException: insite -- service jboss.naming.context.java.jboss.exported.insite

                at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)

                at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)

                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$Worker.runTask(ThreadPoolExecutor.java:886)

                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

                at java.lang.Thread.run(Thread.java:662)

       

       

       

      ___________________________________________________________

       

      Is it possible to lookup resource connection using remote client?

      if yes, then what about Datasources? can we test dataSource connection in same way?

       

      regards,

       

      Nabeel

        • 1. Re: How to remote lookup resource adapter in Jboss 7.1.0.Final?
          anilallewar

          For JNDI resources to be available remote, JBoss requires them to be fufill 2 conditions

           

          1) Such objects should be bound under the java:jboss/exported/ namespace. For example, java:jboss/exported/NorthWind

          2) Objects bound to the java:jboss/exported/ namespace are expected to be serializable. This allows the objects to be sent over the wire to the remote clients; there is NO way around it. What it essentially means that if you are using datasources/resource adapters; these objects SHOULD be serializable.

           

          So I have used a H2 datasource defined as below

          ------------------------------------------------------------------------------------------------------------

          <datasource jndi-name="java:jboss/exported/Northwind" pool-name="Northwind" enabled="true" use-java-context="true">

          .

          .

          </datasource>

          -----------------------------------------------------------------------------------------------------------

          Here is the sample program that is able to access the JNDI remotely but fails because of serialization errors.

          -----------------------------------------------------------------------------------------------------------

          public void doLookup() throws NamingException {

                  Properties jndiProps = new Properties();

                  jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);

                  jndiProps.put(Context.PROVIDER_URL, "remote://134.132.100.29:4447");

                  // create a context passing these propertiesContext

                  InitialContext ctx = new InitialContext(jndiProps);

                  // Note that for remote JNDI lookups the client always starts with

                  // java:jboss/exported/ namespace and we don't provide it here

                  Object object = ctx.lookup("Northwind");

              }

          -----------------------------------------------------------------------------------------------------------

          And the exception I get because the datasource is NOT serializable while the Lookup is successful.

           

          4 Dec, 2012 3:14:07 PM org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver handleMessage

          ERROR: java.io.EOFException

          javax.naming.NamingException: Failed to lookup [Root exception is java.io.NotSerializableException: org.jboss.jca.core.connectionmanager.ccm.CachedConnectionManagerImpl]

              at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)

              at org.jboss.naming.remote.protocol.v1.Protocol$1.execute(Protocol.java:104)

              at org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1.lookup(RemoteNamingStoreV1.java:79)

              at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:79)

              at org.jboss.naming.remote.client.RemoteContext.lookup(RemoteContext.java:83)

              at javax.naming.InitialContext.lookup(Unknown Source)

              at com.anil.java.jndi.RemoteJNDILookUp.doLookup(RemoteJNDILookUp.java:19)

              at com.anil.java.jndi.RemoteJNDILookUp.main(RemoteJNDILookUp.java:25)

          Caused by: java.io.NotSerializableException: org.jboss.jca.core.connectionmanager.ccm.CachedConnectionManagerImpl

              at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:891)

              at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1063)

              at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)

              at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:998)

              at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:885)

              at org.jboss.marshalling.river.RiverMarshaller.doWriteFields(RiverMarshaller.java:1063)

              at org.jboss.marshalling.river.RiverMarshaller.doWriteSerializableObject(RiverMarshaller.java:1019)

              at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:885)

              at org.jboss.marshalling.AbstractObjectOutput.writeObject(AbstractObjectOutput.java:62)

              at org.jboss.marshalling.AbstractMarshaller.writeObject(AbstractMarshaller.java:119)

              at org.jboss.naming.remote.protocol.v1.Protocol$1$2.write(Protocol.java:138)

              at org.jboss.naming.remote.protocol.v1.WriteUtil.write(WriteUtil.java:61)

              at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:128)

              at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)

              at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

              at java.lang.Thread.run(Thread.java:662)

          Caused by: an exception which occurred:

              in field cachedConnectionManager

              in field cm

              in object org.jboss.jca.adapters.jdbc.WrapperDataSource@4d3f0635

           

          ----------------------------------------------------------------------------------------------------------------------------------------------------------

          On second thoughts, I also checked if you can access datasource through an MBean lookup. So while you can do that using object name like "jboss.as:subsystem=datasources,data-source=Northwind"; the only operation available on the datasource is "addConnectionProperties"

           

          So this again is of no use in case you are trying to access a connection from the datasource.

          • 2. Re: How to remote lookup resource adapter in Jboss 7.1.0.Final?
            wdfink

            Remote lookup of datasources is not supported in AS7. And I think that this is true for ResourceAdapters as well.

             

            The problem is that it will have a bad performance, transaction propagation, timeouts, pool control, ....

            So it will be not a good idea to have such resources outside the container.

            • 3. Re: How to remote lookup resource adapter in Jboss 7.1.0.Final?
              nickarls

              (and there are apparently no plans to support them in future versions either looking at some related posts)

              • 4. Re: How to remote lookup resource adapter in Jboss 7.1.0.Final?
                hai_feng

                Hi,nabeelhamad

                Is there some way to solve your problem?I also meet the same problem in my test,and my problem is NotSerializableException.If you have some way,please tell me,I hope your assistance!

                • 5. Re: How to remote lookup resource adapter in Jboss 7.1.0.Final?
                  wdfink

                  If you try to access a server resource you can use a StatelessSessionBean to handle the request and update the resource inside the container.

                  • 6. Re: How to remote lookup resource adapter in Jboss 7.1.0.Final?
                    hai_feng

                    Hi,Wolf-Dieter Fink,How could I do ? Can you tell me the methor?Thanks!