• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Accessing ejbs on a client

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, im a newbie to the world of ejbs and i have a slight problem.
Context jndiCntx = new InitialContext();
jndiCntx.lookup(objectName);
I can access and use an ejb using the previous code, but to do so i have to use
"-Dorg.omg.CORBA.ORBInitialHost=HostName" on the command line.
Is there any way if setting this value from within the code ?
Any help, pointers to examples would be most appreciated.
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hope the following modification to code answers your query ...

I am not sure which app server you are using. In weblogic 5.1 I replace the following the above line commented as 'See Note below' as :


With regards to examples that you will *surely* find in any doc directory of the app server's install directory.
HTH
 
Gavin Wilkinson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,cheers for the reply
Im using the J2EE RI application server.
The code
Properties props=new Properties();
props.put("java.naming.provider.url","iiop://HostName:1050");
props.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.enterprise.naming.SerialInitContextFactory");
// does this do anything ?
props.put( "org.omg.CORBA.ORBInitialHost","HostName");
InitialContext jndiCntx = new InitialContext(props);
jndiCntx.lookup(objectName);
works fine if i specify the
"-Dorg.omg.CORBA.ORBInitialHost=HostName" param on the command line.
I get the error below if i dont specify the param.
javax.naming.CommunicationException: Can't find SerialContextProvider
As my class is eventualy going to be part of a bigger project though, i cant use the command line params so i need to be able to set the above value in code.
Cheers. ;-)
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try to change this line of code from ("java.naming.provider.url","iiop://HostName:1050");
to
("java.naming.provider.url","iiop://Dorg.omg.CORBA.ORBInitialHost:1050");
According to what you described, this should work.
 
Bharatesh H Kakamari
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you have to give javax.naming. instead of java.naming as the naming package is in javax package. It is always best to import than to give the fully qualified class. Atleast the compiler will throw an error if it is not able to locate a package in import statement.
Also the Context class is also in javax.naming package
HTH
 
Gavin Wilkinson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, cheers for all the help.
Ive changed lots of code but i am still having the same problem.
im importing javax.naming.*;
Ive changed the properties file i use to initialize my context about a million times. Nothing works.
However, if i specify the
"-Dorg.omg.CORBA.ORBInitialHost=HostPC" to the java command it all works fine. With this param i dont have to set any of the properties in the initialize of the context. All i relay need to be able to do is set whatever the above is from within my code, then every thing should be hunky dory.
Cheers ;-)

 
Bharatesh H Kakamari
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Problem has become interesting. Can you post your code. I am not sure which directory service you are using and if at all it will require any other downloads if you will post your code.
 
Gavin Wilkinson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im afraid i cant post my complete code. I have a few other bods on the problem and will post the solution if anyone ever finds it.
 
Gavin Wilkinson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This doesn' work either.
String objectName="cheese";
System.out.println(System.setProperty("org.omg.CORBA.ORBInitailHost","HostName"));
InitialContext jndiCntx = new InitialContext();
tempObject= jndiCntx.lookup(objectName);
All of the beans and things i have been trying to access have been developed by someone else and there are lots of them deployed and being used on the app server im trying to access.
 
Gavin Wilkinson
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just in case anybody cares.
the following code works
String objectName="cheese";
System.out.println(System.setProperty("org.omg.CORBA.ORBInitialHost","HostName"));
InitialContext jndiCntx = new InitialContext();
tempObject= jndiCntx.lookup(objectName);
It was the spelling mistake of Initial -> Initail that caused it to not work.
Thanks for all the help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic