Accessing JNDI Object

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Accessing JNDI Object

Kamesh Sampath
I am using Apache Aries with Camel, as part of my test with pax-jdbc I have registered the JNDI datasource via Karaf cfg – it all works fine when deployed in Karaf, when doing the testing via CamelBlueprintTest am getting the following error :

Caused by: javax.naming.NoInitialContextException: The calling code's BundleContext could not be determined.
at org.apache.aries.jndi.OSGiInitialContextFactoryBuilder.getInitialContext(OSGiInitialContextFactoryBuilder.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:341)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.apache.ibatis.datasource.jndi.JndiDataSourceFactory.setProperties(JndiDataSourceFactory.java:52)

Where the “ org.apache.ibatis.datasource.jndi.JndiDataSourceFactory.” is a non-OSGi bundle.  After debugging I see the failure happens in  Utils#doGetBundleContext, when it does the “Object bc = env == null?null:env.get("osgi.service.jndi.bundleContext");”, wondering if I am missing any environment property I miss to set. 
    

-Kamesh
Reply | Threaded
Open this post in threaded view
|

Re: Accessing JNDI Object

Jean-Baptiste Onofré
Hi Kamesh,

Did you install the jndi feature in Karaf ?

This feature provide a InitialContextFactory (which is not the case by
default).

Regards
JB

On 05/26/2016 10:10 AM, Kamesh Sampath wrote:

> I am using Apache Aries with Camel, as part of my test with pax-jdbc I
> have registered the JNDI datasource via Karaf cfg – it all works fine
> when deployed in Karaf, when doing the testing via CamelBlueprintTest am
> getting the following error :
>
> “
> Caused by: javax.naming.NoInitialContextException: The calling code's
> BundleContext could not be determined.
> at
> org.apache.aries.jndi.OSGiInitialContextFactoryBuilder.getInitialContext(OSGiInitialContextFactoryBuilder.java:46)
> at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
> at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
> at
> javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:341)
> at javax.naming.InitialContext.lookup(InitialContext.java:417)
> at
> org.apache.ibatis.datasource.jndi.JndiDataSourceFactory.setProperties(JndiDataSourceFactory.java:52)
> “
>
> Where the “ org.apache.ibatis.datasource.jndi.JndiDataSourceFactory.” is
> a non-OSGi bundle.  After debugging I see the failure happens in
>   Utils#doGetBundleContext, when it does the “Object bc = env ==
> null?null:env.get("osgi.service.jndi.bundleContext");”, wondering if I
> am missing any environment property I miss to set.
>
> -Kamesh

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: Accessing JNDI Object

kamesh.sampath

Hi Jean,

It does work when doing in Karaf directly where jndi was installed. When I was doing with Camel tests with blueprint it fails.. may be something to do with FelixConnect. I did run the same tests with pax-exam all went fine.

+Kamesh

Get Outlook for Android




On Mon, Jun 6, 2016 at 1:53 AM -0700, "Jean-Baptiste Onofré" <[hidden email]> wrote:

Hi Kamesh,

Did you install the jndi feature in Karaf ?

This feature provide a InitialContextFactory (which is not the case by
default).

Regards
JB

On 05/26/2016 10:10 AM, Kamesh Sampath wrote:
> I am using Apache Aries with Camel, as part of my test with pax-jdbc I
> have registered the JNDI datasource via Karaf cfg – it all works fine
> when deployed in Karaf, when doing the testing via CamelBlueprintTest am
> getting the following error :
>
> “
> Caused by: javax.naming.NoInitialContextException: The calling code's
> BundleContext could not be determined.
> at
> org.apache.aries.jndi.OSGiInitialContextFactoryBuilder.getInitialContext(OSGiInitialContextFactoryBuilder.java:46)
> at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
> at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
> at
> javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:341)
> at javax.naming.InitialContext.lookup(InitialContext.java:417)
> at
> org.apache.ibatis.datasource.jndi.JndiDataSourceFactory.setProperties(JndiDataSourceFactory.java:52)
> “
>
> Where the “ org.apache.ibatis.datasource.jndi.JndiDataSourceFactory.” is
> a non-OSGi bundle.  After debugging I see the failure happens in
>   Utils#doGetBundleContext, when it does the “Object bc = env ==
> null?null:env.get("osgi.service.jndi.bundleContext");”, wondering if I
> am missing any environment property I miss to set.
>
> -Kamesh

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|

Re: Accessing JNDI Object

Jean-Baptiste Onofré
Hi,

if you don't use Karaf, then you have to create and provide a JNDI
initial context factory yourself.

That's why Karaf is so helpful ;) and it can be run static on docker too
(no need to use FelixConnect ;)).

Regards
JB

On 06/06/2016 11:06 AM, [hidden email] wrote:

> Hi Jean,
>
> It does work when doing in Karaf directly where jndi was installed. When
> I was doing with Camel tests with blueprint it fails.. may be something
> to do with FelixConnect. I did run the same tests with pax-exam all went
> fine.
>
> +Kamesh
>
> Get Outlook for Android <https://aka.ms/ghei36>
>
>
>
>
> On Mon, Jun 6, 2016 at 1:53 AM -0700, "Jean-Baptiste Onofré"
> <[hidden email] <mailto:[hidden email]>> wrote:
>
> Hi Kamesh,
>
> Did you install the jndi feature in Karaf ?
>
> This feature provide a InitialContextFactory (which is not the case by
> default).
>
> Regards
> JB
>
> On 05/26/2016 10:10 AM, Kamesh Sampath wrote:
>  > I am using Apache Aries with Camel, as part of my test with pax-jdbc I
>  > have registered the JNDI datasource via Karaf cfg – it all works fine
>  > when deployed in Karaf, when doing the testing via CamelBlueprintTest am
>  > getting the following error :
>  >
>  > “
>  > Caused by: javax.naming.NoInitialContextException: The calling code's
>  > BundleContext could not be determined.
>  > at
>  >
> org.apache.aries.jndi.OSGiInitialContextFactoryBuilder.getInitialContext(OSGiInitialContextFactoryBuilder.java:46)
>  > at
> javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
>  > at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
>  > at
>  >
> javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:341)
>  > at javax.naming.InitialContext.lookup(InitialContext.java:417)
>  > at
>  >
> org.apache.ibatis.datasource.jndi.JndiDataSourceFactory.setProperties(JndiDataSourceFactory.java:52)
>  > “
>  >
>  > Where the “ org.apache.ibatis.datasource.jndi.JndiDataSourceFactory.” is
>  > a non-OSGi bundle.  After debugging I see the failure happens in
>  >   Utils#doGetBundleContext, when it does the “Object bc = env ==
>  > null?null:env.get("osgi.service.jndi.bundleContext");”, wondering if I
>  > am missing any environment property I miss to set.
>  >
>  > -Kamesh
>
> --
> Jean-Baptiste Onofré
> [hidden email]
> http://blog.nanthrax.net
> Talend - http://www.talend.com

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com