[JAVA-3155] JNDI ObjectFactory Broken for Tomcat Created: 29/Jan/19  Updated: 27/Oct/23  Resolved: 04/Mar/19

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 3.9.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: James Smith Assignee: Jeffrey Yemin
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

When entering into `getObjectInstance()` method for `ObjectFactory` implementations, Tomcat / TomEE is not using `environment`, so it gets passed in as `null`. A quick fix to this bug would be to check if `environment` is null before trying to access the hashtable.

Example Stack Trace:

29-Jan-2019 11:39:54.452 SEVERE [localhost-startStop-1] org.apache.tomee.catalina.TomcatResourceFactory.create Can't create resource null
 java.lang.NullPointerException
	at com.mongodb.client.jndi.MongoClientFactory.getObjectInstance(MongoClientFactory.java:72)
...



 Comments   
Comment by James Smith [ 04/Mar/19 ]

So, current resolution is to do the same thing for Tomcat, as TomEE can also make use of context.xml. I'm currently waiting for responses for the following question to see if the TomEE dev's have alternative solutions.

Comment by Ian Whalen (Inactive) [ 04/Mar/19 ]

Closing as gone away, but please comment/reopen if you have more info.

Comment by Jeffrey Yemin [ 04/Feb/19 ]

OK, let us know what you find in your investigations.

Thanks,
Jeff

Comment by James Smith [ 01/Feb/19 ]

Hey Jeff! Thanks for responding so quickly! So, after some digging, I was able to find an extremely easy alternative to context.xml. With TomEE, I took advantage of using resources.xml. The below code can be shown as an example in the documentation for TomEE. I'm sure this can be used for other application servers as well, but my use is for TomEE.

<resources>
    <Resource id="mongodb/MyMongoClient"
              class-name="com.mongodb.MongoClient"
              factory="com.mongodb.client.jndi.MongoClientFactory"
              connectionString="mongodb://localhost"/>
</resources>

I think it would also be great to add additional properties that can't be supplied in the connection string, as shown in the JavaDoc for MongoClientFactory.

Note: Not all options that can be specified via {@link com.mongodb.MongoClientOptions} can be specified via the connection string.

If you can possibly add that to either this task, or create a new task for it, that would be fantastic! Much appreciated!

 

EDIT: I'm validating my tests, and it still doesn't seem to be working. I believe TomEE is just lazily creating the object. I'm going to keep looking into it, but for now, this isn't working either.

Comment by Jeffrey Yemin [ 29/Jan/19 ]

Bumping priority down to Major, as we reserve Blocker for production-down/data loss type bugs.

Comment by Jeffrey Yemin [ 29/Jan/19 ]

james-r-smith,

Interesting. We did test this a while back in this repo. Not sure what's changed, so we will have to investigate. If you see anything off or missing in that repo though, please let us know.

Generated at Thu Feb 08 08:58:55 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.