• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jboss rar JNDI lookup

 
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have deployed a cicseci.rar file along with it the service xml file into the deploy directory of the default server.

cicseci-ds.xml looks like following.

<connection-factories>
<tx-connection-factory>
<jndi-name>cicseci_Santosh</jndi-name>
<use-java-context>false</use-java-context>
<rar-name>cicseci.rar</rar-name>
<connection-definition>javax.resource.cci.ConnectionFactory</connection-definition>
<max-pool-size>50</max-pool-size>
</tx-connection-factory>
</connection-factories>

I am trying to do a JNDI look up on this with a JUNIT test case:
I have the following in my code
ConnectionFactory cf = (ConnectionFactory)ctx.lookup("java:/cicseci_Santosh");

Connection conn = cf.getConnection();

when I try to use variable "cf" I get a null pointer exception. Am I doing the right lookup with respect to the JNDI name? Any suggestions/thoughts are welcome.
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<use-java-context>false</use-java-context>


Setting this to false would mean that the datasource will *not* be bound in the java: namespace. So your lookup should look like:



Note that the java:/ has been removed from the above lookup code.
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I modified the services xml file to following:

<connection-factories>
<tx-connection-factory>
<jndi-name>santosh</jndi-name>
<rar-name>cicseci.rar</rar-name>
<connection-definition>javax.resource.cci.ConnectionFactory</connection-definition>
<max-pool-size>50</max-pool-size>
</tx-connection-factory>
</connection-factories>


From the JBOSS logs following is the console message for JNDI binding:
----------------BOUND Message------------
08:43:07,843 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=santosh' to JNDI name 'java:santosh'
-----------------------------------------

I have written a JUNIT to test this and am doing the lookup the following way
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
prop.put(Context.URL_PKG_PREFIXES, "org.jboss.naming rg.jnp.interfaces");
prop.put(Context.PROVIDER_URL, "jnp://localhost:1099");
ctx = new InitialContext(prop);
Object ref = ctx.lookup("java:santosh");
//Object ref = ctx.lookup("java:/santosh");


If I try to do the lookup it gives me the NameNotFoundException


javax.naming.NameNotFoundException: santosh not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:514)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:522)
at org.jnp.server.NamingServer.getObject(NamingServer.java:528)
at org.jnp.server.NamingServer.lookup(NamingServer.java:281)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)Didn't flow

at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:610)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
at javax.naming.InitialContext.lookup(Unknown Source)
at com.amfam.sisautoe.integration.vehicleeligibility.test.CICSECITest.testJNDIConnection(CICSECITest.java:82)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)


-----------------------------------------------------------------''

1. Can we test a JNDI connection from a JUNIT class (I am using JBOSS)? If yes how?

[ July 25, 2006: Message edited by: Santosh Ram ]
[ July 25, 2006: Message edited by: Santosh Ram ]
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cant access the JNDI objects located in the java: namespace from outside the JVM(in this case, your JUnit test). You might want to change the config file and the code to:

Your -ds.xml file:



Your lookup code:

 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jai,
Thanks for your response and I modified the code as mentioned by you (it seems to pass through the connection factory lookup but when I try to use the connection factory it throws NULL POINTER).

<connection-factories>
<tx-connection-factory>
<jndi-name>santosh</jndi-name>
<use-java-context>false</use-java-context>
<rar-name>cicseci.rar</rar-name>
<connection-definition>javax.resource.cci.ConnectionFactory</connection-definition>
<max-pool-size>50</max-pool-size>
</tx-connection-factory>
</connection-factories>

----------------------server log for JNDI binding------------
09:18:20,426 INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=ConnectionFactoryBinding,name=santosh' to JNDI name 'santosh'
--------------------------------------------------------------

and I am doing the lookup in the following way::
ConnectionFactory cf = (ConnectionFactory)ctx.lookup("santosh");

and then I get a NULL POINTER at the following piece of code

Connection conn = cf.getConnection();


1. Why is that the connection Factory is null?
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if the jmx-console is of any help. Try this out:

1) Go to http://localhost:8080/jmx-console
2) Look for the "service=JNDIView" MBean on this page
3) Click on it
4) On the page that comes up, click on the 'Invoke' button beside the list() method.
5) This will show you a listing of the JNDI names and the object bound to the names.
6) Search for the jndi-name "santosh" and see what's bound to it.

If you are unable to understand the listing, then, you can post the JNDI list output here.
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jai,
Thanks again and following is find with your instructions:

Under Global JNDI Namespace

I saw this::::

+- santosh (class: com.ibm.connector2.cics.ECIConnectionFactory)
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JNDI listing looks fine. Please post the entire exception stacktrace that you are seeing, and also post the relevant code.
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exception stack
--------------------------------------------------------------

java.lang.NullPointerExceptionDidn't flow

at com.amfam.sisautoe.integration.vehicleeligibility.test.CICSECITest.testJNDIConnection(CICSECITest.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
-----------------------------------------------------------------------


Code

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

public void testJNDIConnection(){


String requestStr = genRequest();
try {
init();
byte[] requestByte = requestStr.getBytes("Cp037");
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
//prop.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
prop.put(Context.PROVIDER_URL, "jnp://localhost:1099");
ctx = new InitialContext(prop);
Object ref = ctx.lookup("santosh");

ECIConnectionFactory ecf= (ECIConnectionFactory) ctx.lookup("santosh");

Connection conn = cf.getConnection(); //line 102

---------------------------------------------------
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

java.lang.NullPointerExceptionDidn't flow


Was there something more in the exception stacktrace that you removed while posting. If yes, then that part might be useful. It might mean that there is a NullpointerException inside the getConnection() method or later on in the method invocation hierarchy.
Just to make sure that the object returned by the lookup is not null, add the following statement after the lookup, and post the output:



By the way, i guess that the code that you have posted in not the exact one that you are using, since cf is never declared in that method.



If not, then use:
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jai,

With the System.out for object here is the o/p full stack trace(it is returning null)

Out size=68
java.lang.NullPointerException
at com.amfam.sisautoe.integration.vehicleeligibility.test.CICSECITest.testJNDIConnection(CICSECITest.java:105)
Got reference
Lookup object returned is: null
Didn't flow
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

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

I am using

Connection conn = ecf.getConnection();


earlier post was a typo where I tried to remove some commented code.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried the same thing at my end. Strange, even though it does not throw any NameNotFound sort of exceptions, it *returns NULL*.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like i finally got to know the reason behind this issue. The com.ibm.connector2.cics.ECIConnectionFactory(which implements the javax.resource.cci.ConnectionFactory) is meant to be used in a *managed environment* (i.e. Servlets/EJBs). You cannot use it in a standalone/JUnit clients. Found more information about this by looking at ECIManagedConnectionFactory, which is a parameter to the constructor of ECIConnectionFactory.

This is just my take on this issue, after googling a bit and thanks to the hint by Weston Price at JBoss JCA Forum. You might still want to confirm about the same.
[ July 26, 2006: Message edited by: jaikiran pai ]
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jai,
Thanks a lot for your help and I am looking into it.
 
Santosh Ramachandrula
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jai,
I haven't had much luck testing it out of JVM, I pushed the code to with in the container and it works.

For these kind of connections (JNDI) if I want to write UNIT testing it may not be possible if Managed environment refers to in container code.
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of JUnit, you may use Cactus - Server side testing. Its as simple as JUnit and lets you test server side components.
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I went thru the entire post and replies, modified my code accordingly but am still getting the NameNotFoundException.
In my case my local client code tries to lookup the EJB object on a remote JVM. I have checked the JBoss Global JNDI Namespace and found that the requested EJB name does feature in the list. I fail to understand the reason for error now!

Anybody please help! Thanks

Below is exception in my eclipse console :



Below is the local client code :



Below is the Global JNDI Namespace list :

+- CustomerSessionBean (proxy: $Proxy190 implements interface com.eagle.gps.customer.ejb.sls.CustomerSessionHome,interface javax.ejb.Handle)
 
Jaikiran Pai
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yogesh,

Although its a NameNotFoundException that you are running into, it's not the same as what the original poster raised this thread for. Please create a new thread in this forum for discussing your issue.
 
reply
    Bookmark Topic Watch Topic
  • New Topic