You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Andreas Karalus <an...@googlemail.com> on 2008/09/09 18:21:06 UTC

"Local server is not initialized"

first of all, I would like to thank all the people in forum for the quick
responses. openejb looks like solid piece of software.

however, i'm still running into problems while trying to migrate our jboss
embedded tests to openejb. 

booting of openejb works fine, however, we have some places in our code
where we do a new InitialContext(). whenever this code is reached while
openejb is running, I get a javax.naming.NamingException

INFO - Deployed
Application(path=D:\projekte\HEAD\ed02\env\testframework\target\classes)
javax.naming.NamingException: Local server is not initialized
	at
org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
	at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
	at javax.naming.InitialContext.init(InitialContext.java:223)
	at javax.naming.InitialContext.<init>(InitialContext.java:175)
...	

any ideas welcome,
regards,
andreas

-- 
View this message in context: http://www.nabble.com/%22Local-server-is-not-initialized%22-tp19396008p19396008.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: "Local server is not initialized"

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Andreas,

As far as I know, the InitialContext (from your JDK) has a kind of failback
mechanism.
If no properties are used (new InitialContext() or new
InitialContext(null)), a set of properties will be built using env params,
applet params, system params and then jndi.properties params.

So from my point of view, you can create a jndi.properties and put it in
your classpath. The jndi.properties file must contain a line
java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory

But, I think there is a problem within Tomcat cause Tomcat puts its own
InitialContext Factory implementation first, so you will never be able to
use your InitialContext Factory using standard mechanisms.
See http://wiki.apache.org/tomcat/FAQ/Miscellaneous#Q22

Regards,
Jean-Louis



Andreas Karalus wrote:
> 
> Jean Louis,
> 
> thank you for your quick reply. 
> I start openejb in the way you described, and the startup is fine. 
> I am also able to test some ejbs.
> However, if somewhere in our code, a new InitialContext is initialized, I
> get the exception.
> 
> so basically I have following configuration:
> 
> class Beanfactory{
>  
>  static void initContainer() {
>    Properties properties = new Properties();
>     
>    properties.put(Context.INITIAL_CONTEXT_FACTORY, 
>         "org.openejb.client.LocalInitialContextFactory");
>     
>    // THIS WORKS FINE
>    InitialContext ctx = new InitialContext(properties);
> }
> 
> I want to test code that performs itself a "InitialContext ctx = new
> InitialContext()". This works well with jboss.embedded, but fails with
> openejb. 
> For jboss.embedded we use a jndi.properties as configuration. so if the
> file is present in classpath, new IntialContext() works fine. I wonder if
> there is a similar configuration in openejb? 
> 
> thx,
> andreas
> 
> p.s. here is the data in jndi.properties
> 
> java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
> java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
> 
> 
> 
> Jean-Louis MONTEIRO wrote:
>> 
>> Andreas,
>> 
>> Seems like you are still using JBoss InitialContext implementation. 
>> Did you set your system properties to use OpenEJB InitialContextFactory ?
>> 
>> Properties properties = new Properties();
>>     
>> properties.put(Context.INITIAL_CONTEXT_FACTORY, 
>>         "org.openejb.client.LocalInitialContextFactory");
>>     
>> InitialContext ctx = new InitialContext(properties);
>> 
>> Regards,
>> Jean-Louis
>> 
>> 
>> Andreas Karalus wrote:
>>> 
>>> first of all, I would like to thank all the people in forum for the
>>> quick responses. openejb looks like solid piece of software.
>>> 
>>> however, i'm still running into problems while trying to migrate our
>>> jboss embedded tests to openejb. 
>>> 
>>> booting of openejb works fine, however, we have some places in our code
>>> where we do a new InitialContext(). whenever this code is reached while
>>> openejb is running, I get a javax.naming.NamingException
>>> 
>>> INFO - Deployed
>>> Application(path=D:\projekte\HEAD\ed02\env\testframework\target\classes)
>>> javax.naming.NamingException: Local server is not initialized
>>> 	at
>>> org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
>>> 	at
>>> javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
>>> 	at
>>> javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
>>> 	at javax.naming.InitialContext.init(InitialContext.java:223)
>>> 	at javax.naming.InitialContext.<init>(InitialContext.java:175)
>>> ...	
>>> 
>>> any ideas welcome,
>>> regards,
>>> andreas
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/%22Local-server-is-not-initialized%22-tp19396008p19409584.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: "Local server is not initialized"

Posted by Andreas Karalus <an...@googlemail.com>.
david, 

thank you very much!
I followed your hint and changed the jndi.properties for tests like you
suggested and everything works fine.
you are doing a great job here, thank you!

andreas



David Blevins wrote:
> 
> 
> On Sep 10, 2008, at 1:38 AM, Andreas Karalus wrote:
> 
>> I want to test code that performs itself a "InitialContext ctx = new
>> InitialContext()". This works well with jboss.embedded, but fails with
>> openejb.
>> For jboss.embedded we use a jndi.properties as configuration. so if  
>> the file
>> is present in classpath, new IntialContext() works fine. I wonder if  
>> there
>> is a similar configuration in openejb?
> [...]
>>
>> p.s. here is the data in jndi.properties
>>
>> java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
>> java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
> 
> Right, it's the java.naming.factory.url.pkgs line that's causing the  
> problem.  A snippet from the InitialContext javadoc:
> 
>     JNDI determines each property's value by merging the values from
>     the following two sources, in order:
> 
>     1. The first occurrence of the property from the constructor's
>        environment parameter and (for appropriate properties) the
>        applet parameters and system properties.
> 
>     2. The application resource files (jndi.properties).
> 
> 
> The vm is picking JBoss's org.jboss.naming and org.jnp.interfaces  
> packages for all "java:" lookups instead of ours because the values of  
> the jndi.properties file are getting merged with your InitialContext  
> properties.
> 
> You could either delete your jndi.properties file completely or you  
> could update it as follows:
> 
>     
> java 
> .naming 
> .factory.initial=org.apache.openejb.client.LocalInitialContextFactory
>    java.naming.factory.url.pkgs=org.apache.openejb.core.ivm.naming
> 
> 
> Just make sure that you don't use these settings in an actual remote  
> client running in a different VM than the server.  There you'd use  
> these settings:
> 
>     
> java 
> .naming 
> .factory.initial=org.apache.openejb.client.RemoteInitialContextFactory
>    java.naming.factory.url.pkgs=org.apache.openejb.client
> 
> 
> -David
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/%22Local-server-is-not-initialized%22-tp19396008p19414605.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: "Local server is not initialized"

Posted by David Blevins <da...@visi.com>.
On Sep 10, 2008, at 1:38 AM, Andreas Karalus wrote:

> I want to test code that performs itself a "InitialContext ctx = new
> InitialContext()". This works well with jboss.embedded, but fails with
> openejb.
> For jboss.embedded we use a jndi.properties as configuration. so if  
> the file
> is present in classpath, new IntialContext() works fine. I wonder if  
> there
> is a similar configuration in openejb?
[...]
>
> p.s. here is the data in jndi.properties
>
> java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
> java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

Right, it's the java.naming.factory.url.pkgs line that's causing the  
problem.  A snippet from the InitialContext javadoc:

    JNDI determines each property's value by merging the values from
    the following two sources, in order:

    1. The first occurrence of the property from the constructor's
       environment parameter and (for appropriate properties) the
       applet parameters and system properties.

    2. The application resource files (jndi.properties).


The vm is picking JBoss's org.jboss.naming and org.jnp.interfaces  
packages for all "java:" lookups instead of ours because the values of  
the jndi.properties file are getting merged with your InitialContext  
properties.

You could either delete your jndi.properties file completely or you  
could update it as follows:

    
java 
.naming 
.factory.initial=org.apache.openejb.client.LocalInitialContextFactory
   java.naming.factory.url.pkgs=org.apache.openejb.core.ivm.naming


Just make sure that you don't use these settings in an actual remote  
client running in a different VM than the server.  There you'd use  
these settings:

    
java 
.naming 
.factory.initial=org.apache.openejb.client.RemoteInitialContextFactory
   java.naming.factory.url.pkgs=org.apache.openejb.client


-David




Re: "Local server is not initialized"

Posted by Andreas Karalus <an...@googlemail.com>.
Jean Louis,

thank you for your quick reply. 
I start openejb in the way you described, and the startup is fine. 
I am also able to test some ejbs.
However, if somewhere in our code, a new InitialContext is initialized, I
get the exception.

so basically I have following configuration:

class Beanfactory{
 
 static void initContainer() {
   Properties properties = new Properties();
    
   properties.put(Context.INITIAL_CONTEXT_FACTORY, 
        "org.openejb.client.LocalInitialContextFactory");
    
   // THIS WORKS FINE
   InitialContext ctx = new InitialContext(properties);
}

I want to test code that performs itself a "InitialContext ctx = new
InitialContext()". This works well with jboss.embedded, but fails with
openejb. 
For jboss.embedded we use a jndi.properties as configuration. so if the file
is present in classpath, new IntialContext() works fine. I wonder if there
is a similar configuration in openejb? 

thx,
andreas

p.s. here is the data in jndi.properties

java.naming.factory.initial=org.jnp.interfaces.LocalOnlyContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces



Jean-Louis MONTEIRO wrote:
> 
> Andreas,
> 
> Seems like you are still using JBoss InitialContext implementation. 
> Did you set your system properties to use OpenEJB InitialContextFactory ?
> 
> Properties properties = new Properties();
>     
> properties.put(Context.INITIAL_CONTEXT_FACTORY, 
>         "org.openejb.client.LocalInitialContextFactory");
>     
> InitialContext ctx = new InitialContext(properties);
> 
> Regards,
> Jean-Louis
> 
> 
> Andreas Karalus wrote:
>> 
>> first of all, I would like to thank all the people in forum for the quick
>> responses. openejb looks like solid piece of software.
>> 
>> however, i'm still running into problems while trying to migrate our
>> jboss embedded tests to openejb. 
>> 
>> booting of openejb works fine, however, we have some places in our code
>> where we do a new InitialContext(). whenever this code is reached while
>> openejb is running, I get a javax.naming.NamingException
>> 
>> INFO - Deployed
>> Application(path=D:\projekte\HEAD\ed02\env\testframework\target\classes)
>> javax.naming.NamingException: Local server is not initialized
>> 	at
>> org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
>> 	at
>> javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
>> 	at
>> javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
>> 	at javax.naming.InitialContext.init(InitialContext.java:223)
>> 	at javax.naming.InitialContext.<init>(InitialContext.java:175)
>> ...	
>> 
>> any ideas welcome,
>> regards,
>> andreas
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/%22Local-server-is-not-initialized%22-tp19396008p19409100.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: "Local server is not initialized"

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Andreas,

Seems like you are still using JBoss InitialContext implementation. 
Did you set your system properties to use OpenEJB InitialContextFactory ?

Properties properties = new Properties();
    
properties.put(Context.INITIAL_CONTEXT_FACTORY, 
        "org.openejb.client.LocalInitialContextFactory");
    
InitialContext ctx = new InitialContext(properties);

Regards,
Jean-Louis


Andreas Karalus wrote:
> 
> first of all, I would like to thank all the people in forum for the quick
> responses. openejb looks like solid piece of software.
> 
> however, i'm still running into problems while trying to migrate our jboss
> embedded tests to openejb. 
> 
> booting of openejb works fine, however, we have some places in our code
> where we do a new InitialContext(). whenever this code is reached while
> openejb is running, I get a javax.naming.NamingException
> 
> INFO - Deployed
> Application(path=D:\projekte\HEAD\ed02\env\testframework\target\classes)
> javax.naming.NamingException: Local server is not initialized
> 	at
> org.jnp.interfaces.LocalOnlyContextFactory.getInitialContext(LocalOnlyContextFactory.java:45)
> 	at
> javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
> 	at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
> 	at javax.naming.InitialContext.init(InitialContext.java:223)
> 	at javax.naming.InitialContext.<init>(InitialContext.java:175)
> ...	
> 
> any ideas welcome,
> regards,
> andreas
> 
> 

-- 
View this message in context: http://www.nabble.com/%22Local-server-is-not-initialized%22-tp19396008p19407453.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: "Local server is not initialized"

Posted by Jean-Louis MONTEIRO <je...@atosorigin.com>.
Andreas,

May be you can define properties statically.
And then, use always new InitialContext(props) or use a jndi.properties file
if you are running JUnit test cases.

Jean-Louis




Andreas Karalus wrote:
> 
> Here is a simple example to show that the lookup is failing. 
> The class is the testclass from openejb jpa-hibernate example. I added a
> new test2 method to simulate behaviour. 
> 
> 
> package org.superbiz.injection.h3jpa;
> 
> import junit.framework.TestCase;
> 
> import javax.naming.Context;
> import javax.naming.InitialContext;
> import java.util.Properties;
> import java.util.List;
> 
> import org.superbiz.injection.h3jpa.Movie;
> import org.superbiz.injection.h3jpa.Movies;
> 
> /**
>  * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27
> Dec 2007) $
>  */
> public class MoviesTest extends TestCase {
> 
>     public void test() throws Exception {
>         Properties p = new Properties();
>         p.put(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>         p.put("movieDatabase", "new://Resource?type=DataSource");
>         p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
>         p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
> 
>         p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource");
>         p.put("movieDatabaseUnmanaged.JdbcDriver",
> "org.hsqldb.jdbcDriver");
>         p.put("movieDatabaseUnmanaged.JdbcUrl",
> "jdbc:hsqldb:mem:moviedb");
>         p.put("movieDatabaseUnmanaged.JtaManaged", "false");
> 
>         Context context = new InitialContext(p);
> 
>         Movies movies = (Movies) context.lookup("MoviesLocal");
> 
>         movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs",
> 1992));
>         movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
>         movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));
> 
>         List<Movie> list = movies.getMovies();
>         assertEquals("List.size()", 3, list.size());
> 
>         for (Movie movie : list) {
>             movies.deleteMovie(movie);
>         }
> 
>         assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
>     }
>     
>     /**
>      * this method simulates a call in production code, 
>      * with a bean lookup from a normal "POJO" class 
>      *
>      * @throws Exception
>      */
>     public void test2() throws Exception{
>     	// this call unfortunately fails.
>     	// question is how can we instantiate another initalContext while
> openejb is running, whithout touching production code? 
>     	InitialContext context = new InitialContext();
>     	Movies movies = (Movies) context.lookup("MoviesLocal");
>     	assertNotNull(movies);
>     }
> }
>  
> 

-- 
View this message in context: http://www.nabble.com/%22Local-server-is-not-initialized%22-tp19396008p19409679.html
Sent from the OpenEJB User mailing list archive at Nabble.com.


Re: "Local server is not initialized"

Posted by Andreas Karalus <an...@googlemail.com>.
Here is a simple example to show that the lookup is failing. 
The class is the testclass from openejb jpa-hibernate example. I added a new
test2 method to simulate behaviour. 


package org.superbiz.injection.h3jpa;

import junit.framework.TestCase;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;
import java.util.List;

import org.superbiz.injection.h3jpa.Movie;
import org.superbiz.injection.h3jpa.Movies;

/**
 * @version $Revision: 607077 $ $Date: 2007-12-27 06:55:23 -0800 (Thu, 27
Dec 2007) $
 */
public class MoviesTest extends TestCase {

    public void test() throws Exception {
        Properties p = new Properties();
        p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");
        p.put("movieDatabase", "new://Resource?type=DataSource");
        p.put("movieDatabase.JdbcDriver", "org.hsqldb.jdbcDriver");
        p.put("movieDatabase.JdbcUrl", "jdbc:hsqldb:mem:moviedb");

        p.put("movieDatabaseUnmanaged", "new://Resource?type=DataSource");
        p.put("movieDatabaseUnmanaged.JdbcDriver", "org.hsqldb.jdbcDriver");
        p.put("movieDatabaseUnmanaged.JdbcUrl", "jdbc:hsqldb:mem:moviedb");
        p.put("movieDatabaseUnmanaged.JtaManaged", "false");

        Context context = new InitialContext(p);

        Movies movies = (Movies) context.lookup("MoviesLocal");

        movies.addMovie(new Movie("Quentin Tarantino", "Reservoir Dogs",
1992));
        movies.addMovie(new Movie("Joel Coen", "Fargo", 1996));
        movies.addMovie(new Movie("Joel Coen", "The Big Lebowski", 1998));

        List<Movie> list = movies.getMovies();
        assertEquals("List.size()", 3, list.size());

        for (Movie movie : list) {
            movies.deleteMovie(movie);
        }

        assertEquals("Movies.getMovies()", 0, movies.getMovies().size());
    }
    
    /**
     * this method simulates a call in production code, 
     * with a bean lookup from a normal "POJO" class 
     *
     * @throws Exception
     */
    public void test2() throws Exception{
    	// this call unfortunately fails.
    	// question is how can we instantiate another initalContext while
openejb is running, whithout touching production code? 
    	InitialContext context = new InitialContext();
    	Movies movies = (Movies) context.lookup("MoviesLocal");
    	assertNotNull(movies);
    }
}
 
-- 
View this message in context: http://www.nabble.com/%22Local-server-is-not-initialized%22-tp19396008p19409396.html
Sent from the OpenEJB User mailing list archive at Nabble.com.