[ 
https://issues.apache.org/jira/browse/BSF-45?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17051134#comment-17051134
 ] 

Bernd Eckenfels commented on BSF-45:
------------------------------------

hm, strangely i cant edit this issue. I would close it, since the beanshell 
syntax is nothing BSF itself can/wants to change. Thanks for responding, 
Kleyson, if you can close it as invalid that would be fine.

> Error trying to access a MongoDB collection under Apache BSF script
> -------------------------------------------------------------------
>
>                 Key: BSF-45
>                 URL: https://issues.apache.org/jira/browse/BSF-45
>             Project: Commons BSF
>          Issue Type: Bug
>          Components: BSF-2.x
>    Affects Versions: BSF-2.4
>         Environment: Java 8
> BSF 2.4.0
>            Reporter: Kleyson Rios
>            Priority: Major
>         Attachments: exception.txt
>
>
> I'm trying to access a MongoDB collection from a java code to be 'eval' by 
> BSF.
> I tried configure the MongoDB connection in both ways coding the driver 
> connection and following the tutorial 
> [https://mongodb.github.io/mongo-java-driver/3.10/driver/tutorials/jndi/] , 
> but in both cases the same error.
> Below the code to be executed by BSF:
>  
> {code:java}
> import javax.naming.InitialContext;
> import com.mongodb.MongoClient;
> import com.mongodb.client.MongoDatabase;
> import com.mongodb.client.MongoCollection;
> import org.bson.Document;
> InitialContext cxt = new InitialContext();
> if ( cxt == null ) {
>    throw new Exception("Uh oh -- no context!");
> }
> MongoClient ds = (MongoClient) cxt.lookup( 
> "java:/comp/env/mongodb/MongoClient" );
> if ( ds == null ) {
>    throw new Exception("Data source not found!");
> }
> MongoDatabase database = ds.getDatabase("ssp");
> //MongoCollection<Document> collection = database.getCollection("customer");
> {code}
>  
> The code above runs fine, but If I uncomment the last line 
> *MongoCollection<Document> collection = database.getCollection("customer")* , 
> the BSF throw a exception. See the attached *exception.txt* file.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to