You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by "Rupp, Hans" <H....@dzbw.de> on 2011/11/22 08:22:42 UTC

NoInitialContextException

Hallo I have a legacy application which I want to make testable with OpenEJB (JEE5, target platform is JBoss 4.3). Most things work so far. 

However I need to access EJBs from simple classes (Pojos WITHOUT any annotations) like

private void inject() {

      try {

                  Context initialContext = new InitialContext();

                  

                  this.propertyAdapter = (PropertyAdapter) initialContext.lookup("propertyAdapter/local");

            } catch (NamingException e) {

                  log.error(e);

            }

   }

(Yeah I know this is not nice and would have constitently used EJBs, but there are classes with complicated constructors and many parameters which I have so far not refactored to EJBs and the whole architecture is a complete mess ... At the moment I have something like EJBs -> POJOs -> EJBs -> Entities)

When this code runs within OpenEJB

 

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

 

the façade EJBs are accessed by my tests, so I think I have at least the basics right. Is there a way to avoid this Exception without converting all classes to EJBs.

 

Thanks for any hints,

 

Hans 

 



40 Jahre DZBW
Herzlichen Dank unseren Kunden und Partnern. Wir freuen uns auf die gemeinsame Fortsetzung der konstruktiven, vertrauensvollen Zusammenarbeit.
Ihre Datenzentrale Baden-Württemberg
_______________________________________________________________________________

Abonnieren Sie unseren Infobrief und erfahren Sie regelmäßig die neuesten Nachrichten über unsere Lösungen, aktuellen Projekte und Entwicklungen. Melden sie sich an mit diesem Link http://www.datenzentrale.de/Info-Brief
_______________________________________________________________________________

Datenzentrale Baden-Württemberg, Anstalt des öffentlichen Rechts
Krailenshaldenstr. 44, 70469 Stuttgart 
Telefon (0711) 8108-20, Telefax (0711) 8108-21350
E-Mail info@dzbw.de, Internet www.datenzentrale.de
Vorstand: Karl Tramer (Vors.) und Joachim Kischlat, Vorsitzender des Verwaltungsrats: Gunter Czisch
USt-Id-Nr. DE147794223 
_______________________________________________________________________________



AW: NoInitialContextException

Posted by "Rupp, Hans" <H....@dzbw.de>.
Thanks for your reply, you put me on the right track:
I solved it by putting
jndi.properties
with

java.naming.factory.initial=org.apache.openejb.client.LocalInitialContextFactory

in the classpath of my test.

Greetings,

Hans

-----Ursprüngliche Nachricht-----
Von: Romain Manni-Bucau [mailto:rmannibucau@gmail.com] 
Gesendet: Dienstag, 22. November 2011 09:05
An: users@openejb.apache.org
Betreff: Re: NoInitialContextException

i think you can add a conf/system.properties file with this value.

Otherwise add a real system property.

- Romain


2011/11/22 Rupp, Hans <H....@dzbw.de>

> Hallo Romain
> Thanks for your answer.
>
> Like this?
> Properties p = new Properties();
> p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>                 
> "org.apache.openejb.client.LocalInitialContextFactory");
> Context initialContext = new InitialContext(p);
>
> this.propertyAdapter = (PropertyAdapter) 
> initialContext.lookup("PropertyAdapterBean/local");
>
> Yes that works. But it does not really solve my problem. I would have 
> to modify my code so that it works with OpenEJB in a way which is 
> incompatible with the target platform (this won't work on JBoss).
>
> Greetings,
>
> Hans
>
> -----Ursprüngliche Nachricht-----
> Von: Romain Manni-Bucau [mailto:rmannibucau@gmail.com]
> Gesendet: Dienstag, 22. November 2011 08:25
> An: users@openejb.apache.org
> Betreff: Re: NoInitialContextException
>
> Hi,
>
> try to pass this properties as your initial context parameter:
>
>  p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>
> - Romain
>
>
> 2011/11/22 Rupp, Hans <H....@dzbw.de>
>
> > Hallo I have a legacy application which I want to make testable with 
> > OpenEJB (JEE5, target platform is JBoss 4.3). Most things work so far.
> >
> > However I need to access EJBs from simple classes (Pojos WITHOUT any
> > annotations) like
> >
> > private void inject() {
> >
> >      try {
> >
> >                  Context initialContext = new InitialContext();
> >
> >
> >
> >                  this.propertyAdapter = (PropertyAdapter) 
> > initialContext.lookup("propertyAdapter/local");
> >
> >            } catch (NamingException e) {
> >
> >                  log.error(e);
> >
> >            }
> >
> >   }
> >
> > (Yeah I know this is not nice and would have constitently used EJBs, 
> > but there are classes with complicated constructors and many 
> > parameters which I have so far not refactored to EJBs and the whole 
> > architecture is a complete mess ... At the moment I have something 
> > like EJBs -> POJOs -> EJBs ->
> > Entities)
> >
> > When this code runs within OpenEJB
> >
> >
> >
> > 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
> >
> >
> >
> > the façade EJBs are accessed by my tests, so I think I have at least 
> > the basics right. Is there a way to avoid this Exception without 
> > converting all classes to EJBs.
> >
> >
> >
> > Thanks for any hints,
> >
> >
> >
> > Hans
> >
> >
> >
> >
> >
> > 40 Jahre DZBW
> > Herzlichen Dank unseren Kunden und Partnern. Wir freuen uns auf die 
> > gemeinsame Fortsetzung der konstruktiven, vertrauensvollen
> Zusammenarbeit.
> > Ihre Datenzentrale Baden-Württemberg
> >
> > ____________________________________________________________________
> > __
> > _________
> >
> > Abonnieren Sie unseren Infobrief und erfahren Sie regelmäßig die 
> > neuesten Nachrichten über unsere Lösungen, aktuellen Projekte und
> Entwicklungen.
> > Melden sie sich an mit diesem Link
> > http://www.datenzentrale.de/Info-Brief
> >
> > ____________________________________________________________________
> > __
> > _________
> >
> > Datenzentrale Baden-Württemberg, Anstalt des öffentlichen Rechts 
> > Krailenshaldenstr. 44, 70469 Stuttgart Telefon (0711) 8108-20, 
> > Telefax
> > (0711) 8108-21350 E-Mail info@dzbw.de, Internet www.datenzentrale.de
> > Vorstand: Karl Tramer (Vors.) und Joachim Kischlat, Vorsitzender des
> > Verwaltungsrats: Gunter Czisch
> > USt-Id-Nr. DE147794223
> >
> > ____________________________________________________________________
> > __
> > _________
> >
> >
> >
>

Re: NoInitialContextException

Posted by Romain Manni-Bucau <rm...@gmail.com>.
i think you can add a conf/system.properties file with this value.

Otherwise add a real system property.

- Romain


2011/11/22 Rupp, Hans <H....@dzbw.de>

> Hallo Romain
> Thanks for your answer.
>
> Like this?
> Properties p = new Properties();
> p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
>                 "org.apache.openejb.client.LocalInitialContextFactory");
> Context initialContext = new InitialContext(p);
>
> this.propertyAdapter = (PropertyAdapter)
> initialContext.lookup("PropertyAdapterBean/local");
>
> Yes that works. But it does not really solve my problem. I would have to
> modify my code so that it works with OpenEJB in a way which is incompatible
> with the target platform (this won't work on JBoss).
>
> Greetings,
>
> Hans
>
> -----Ursprüngliche Nachricht-----
> Von: Romain Manni-Bucau [mailto:rmannibucau@gmail.com]
> Gesendet: Dienstag, 22. November 2011 08:25
> An: users@openejb.apache.org
> Betreff: Re: NoInitialContextException
>
> Hi,
>
> try to pass this properties as your initial context parameter:
>
>  p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
> "org.apache.openejb.client.LocalInitialContextFactory");
>
> - Romain
>
>
> 2011/11/22 Rupp, Hans <H....@dzbw.de>
>
> > Hallo I have a legacy application which I want to make testable with
> > OpenEJB (JEE5, target platform is JBoss 4.3). Most things work so far.
> >
> > However I need to access EJBs from simple classes (Pojos WITHOUT any
> > annotations) like
> >
> > private void inject() {
> >
> >      try {
> >
> >                  Context initialContext = new InitialContext();
> >
> >
> >
> >                  this.propertyAdapter = (PropertyAdapter)
> > initialContext.lookup("propertyAdapter/local");
> >
> >            } catch (NamingException e) {
> >
> >                  log.error(e);
> >
> >            }
> >
> >   }
> >
> > (Yeah I know this is not nice and would have constitently used EJBs,
> > but there are classes with complicated constructors and many
> > parameters which I have so far not refactored to EJBs and the whole
> > architecture is a complete mess ... At the moment I have something
> > like EJBs -> POJOs -> EJBs ->
> > Entities)
> >
> > When this code runs within OpenEJB
> >
> >
> >
> > 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
> >
> >
> >
> > the façade EJBs are accessed by my tests, so I think I have at least
> > the basics right. Is there a way to avoid this Exception without
> > converting all classes to EJBs.
> >
> >
> >
> > Thanks for any hints,
> >
> >
> >
> > Hans
> >
> >
> >
> >
> >
> > 40 Jahre DZBW
> > Herzlichen Dank unseren Kunden und Partnern. Wir freuen uns auf die
> > gemeinsame Fortsetzung der konstruktiven, vertrauensvollen
> Zusammenarbeit.
> > Ihre Datenzentrale Baden-Württemberg
> >
> > ______________________________________________________________________
> > _________
> >
> > Abonnieren Sie unseren Infobrief und erfahren Sie regelmäßig die
> > neuesten Nachrichten über unsere Lösungen, aktuellen Projekte und
> Entwicklungen.
> > Melden sie sich an mit diesem Link
> > http://www.datenzentrale.de/Info-Brief
> >
> > ______________________________________________________________________
> > _________
> >
> > Datenzentrale Baden-Württemberg, Anstalt des öffentlichen Rechts
> > Krailenshaldenstr. 44, 70469 Stuttgart Telefon (0711) 8108-20, Telefax
> > (0711) 8108-21350 E-Mail info@dzbw.de, Internet www.datenzentrale.de
> > Vorstand: Karl Tramer (Vors.) und Joachim Kischlat, Vorsitzender des
> > Verwaltungsrats: Gunter Czisch
> > USt-Id-Nr. DE147794223
> >
> > ______________________________________________________________________
> > _________
> >
> >
> >
>

AW: NoInitialContextException

Posted by "Rupp, Hans" <H....@dzbw.de>.
Hallo Romain
Thanks for your answer.

Like this?
Properties p = new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
    		 "org.apache.openejb.client.LocalInitialContextFactory");
Context initialContext = new InitialContext(p);
			
this.propertyAdapter = (PropertyAdapter) initialContext.lookup("PropertyAdapterBean/local");

Yes that works. But it does not really solve my problem. I would have to modify my code so that it works with OpenEJB in a way which is incompatible with the target platform (this won't work on JBoss).

Greetings,

Hans

-----Ursprüngliche Nachricht-----
Von: Romain Manni-Bucau [mailto:rmannibucau@gmail.com] 
Gesendet: Dienstag, 22. November 2011 08:25
An: users@openejb.apache.org
Betreff: Re: NoInitialContextException

Hi,

try to pass this properties as your initial context parameter:

 p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");

- Romain


2011/11/22 Rupp, Hans <H....@dzbw.de>

> Hallo I have a legacy application which I want to make testable with 
> OpenEJB (JEE5, target platform is JBoss 4.3). Most things work so far.
>
> However I need to access EJBs from simple classes (Pojos WITHOUT any
> annotations) like
>
> private void inject() {
>
>      try {
>
>                  Context initialContext = new InitialContext();
>
>
>
>                  this.propertyAdapter = (PropertyAdapter) 
> initialContext.lookup("propertyAdapter/local");
>
>            } catch (NamingException e) {
>
>                  log.error(e);
>
>            }
>
>   }
>
> (Yeah I know this is not nice and would have constitently used EJBs, 
> but there are classes with complicated constructors and many 
> parameters which I have so far not refactored to EJBs and the whole 
> architecture is a complete mess ... At the moment I have something 
> like EJBs -> POJOs -> EJBs ->
> Entities)
>
> When this code runs within OpenEJB
>
>
>
> 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
>
>
>
> the façade EJBs are accessed by my tests, so I think I have at least 
> the basics right. Is there a way to avoid this Exception without 
> converting all classes to EJBs.
>
>
>
> Thanks for any hints,
>
>
>
> Hans
>
>
>
>
>
> 40 Jahre DZBW
> Herzlichen Dank unseren Kunden und Partnern. Wir freuen uns auf die 
> gemeinsame Fortsetzung der konstruktiven, vertrauensvollen Zusammenarbeit.
> Ihre Datenzentrale Baden-Württemberg
>
> ______________________________________________________________________
> _________
>
> Abonnieren Sie unseren Infobrief und erfahren Sie regelmäßig die 
> neuesten Nachrichten über unsere Lösungen, aktuellen Projekte und Entwicklungen.
> Melden sie sich an mit diesem Link 
> http://www.datenzentrale.de/Info-Brief
>
> ______________________________________________________________________
> _________
>
> Datenzentrale Baden-Württemberg, Anstalt des öffentlichen Rechts 
> Krailenshaldenstr. 44, 70469 Stuttgart Telefon (0711) 8108-20, Telefax 
> (0711) 8108-21350 E-Mail info@dzbw.de, Internet www.datenzentrale.de
> Vorstand: Karl Tramer (Vors.) und Joachim Kischlat, Vorsitzender des
> Verwaltungsrats: Gunter Czisch
> USt-Id-Nr. DE147794223
>
> ______________________________________________________________________
> _________
>
>
>

Re: NoInitialContextException

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi,

try to pass this properties as your initial context parameter:

 p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory");

- Romain


2011/11/22 Rupp, Hans <H....@dzbw.de>

> Hallo I have a legacy application which I want to make testable with
> OpenEJB (JEE5, target platform is JBoss 4.3). Most things work so far.
>
> However I need to access EJBs from simple classes (Pojos WITHOUT any
> annotations) like
>
> private void inject() {
>
>      try {
>
>                  Context initialContext = new InitialContext();
>
>
>
>                  this.propertyAdapter = (PropertyAdapter)
> initialContext.lookup("propertyAdapter/local");
>
>            } catch (NamingException e) {
>
>                  log.error(e);
>
>            }
>
>   }
>
> (Yeah I know this is not nice and would have constitently used EJBs, but
> there are classes with complicated constructors and many parameters which I
> have so far not refactored to EJBs and the whole architecture is a complete
> mess ... At the moment I have something like EJBs -> POJOs -> EJBs ->
> Entities)
>
> When this code runs within OpenEJB
>
>
>
> 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
>
>
>
> the façade EJBs are accessed by my tests, so I think I have at least the
> basics right. Is there a way to avoid this Exception without converting all
> classes to EJBs.
>
>
>
> Thanks for any hints,
>
>
>
> Hans
>
>
>
>
>
> 40 Jahre DZBW
> Herzlichen Dank unseren Kunden und Partnern. Wir freuen uns auf die
> gemeinsame Fortsetzung der konstruktiven, vertrauensvollen Zusammenarbeit.
> Ihre Datenzentrale Baden-Württemberg
>
> _______________________________________________________________________________
>
> Abonnieren Sie unseren Infobrief und erfahren Sie regelmäßig die neuesten
> Nachrichten über unsere Lösungen, aktuellen Projekte und Entwicklungen.
> Melden sie sich an mit diesem Link http://www.datenzentrale.de/Info-Brief
>
> _______________________________________________________________________________
>
> Datenzentrale Baden-Württemberg, Anstalt des öffentlichen Rechts
> Krailenshaldenstr. 44, 70469 Stuttgart
> Telefon (0711) 8108-20, Telefax (0711) 8108-21350
> E-Mail info@dzbw.de, Internet www.datenzentrale.de
> Vorstand: Karl Tramer (Vors.) und Joachim Kischlat, Vorsitzender des
> Verwaltungsrats: Gunter Czisch
> USt-Id-Nr. DE147794223
>
> _______________________________________________________________________________
>
>
>