Quantcast

problem with Karaf jndi feature

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

problem with Karaf jndi feature

rolando
Hello all,

I am using apache karaf 3.0.3.

I just followed the guide of Karaf regarding JNDI,
installed the feature

feature:install jndi

The guide states that

You have two parts in the Apache Karaf JNDI support:

a fully compliant implementation of the OSGi Alliance JNDI Service specification.
a more "regular" JNDI context, containing different names that you can administrate.

When i execute

jndi:names

I got

JNDI Name         | Class Name                                    
------------------------------------------------------------------
osgi:service/jndi | org.apache.karaf.jndi.internal.JndiServiceImpl

instead of

JNDI Name         | Class Name
------------------------------------------------------------------
osgi:service/jndi | org.apache.karaf.jndi.internal.JndiServiceImpl
jndi/service      | org.apache.karaf.jndi.internal.JndiServiceImpl

as the guide says

Also when i try to do the following to test the jndi from outside OSGI

package com.company;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class Main {

    public static void main(String[] args) {
        // write your code here
        try {
            Context ctx = new InitialContext();
            Object service = (Object)ctx.lookup("osgi:service/jndi");
            if(service != null){
                System.out.println(service.getClass().getName());
            }else{
                System.out.println("No service instance received");
            }
        } catch (NamingException e) {
            e.printStackTrace();
        }

    }
}

i receive the following error stack trace

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
        at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
        at javax.naming.InitialContext.lookup(InitialContext.java:411)
        at Test.main(Test.java:10)

Also if i use Karaf 4.0.0 M2 when i install the jndi feature the jndi:names command shows nothing

Anyone know how to resolve this issue, i need to access the osgi jndi from outside osgi.

Thank you in advance,

Rolando

Loading...