This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

getEnvironment()  RSS feed

 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was using
EntityContext ec = null;
String initialContext = ec.getEnvironment.getProperty("INITIAL_CONTEXT_FACTORY");
Now the EJB 2.0 spec says that getEnvironment is deprecated and java.naming.InitialContext should be used. So i changed my code to
InitialContext ic = null
String initialContext = (String)ic.getEnvironment().get("INITIAL_CONTEXT_FACTORY");
My question is how do i use the EntityContext to get the environment variables. Is what ever I am doing correct.
Thanks
Praveen
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Praveen,
Thanks for joining JavaRanch, but could you take a quick look at the naming policy and edit your profile accordingly.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as your question is concerned... here is a simple code snippet for retrieving an ejb environment property from within an ejb.
 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my real name.
As far as the reply goes. I want to get the environment variable from the Entity context.
Thanks for your reply
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Praveen:
This is my real name.

No problem, however the name policy requires both a first and last name. Check the aforementioned link for a complete description.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Praveen:
As far as the reply goes. I want to get the environment variable from the Entity context.

Using the EJBContext to access environment variables was deprecated in EJB 2.0.
EJBContext.getEnvironment() Javadocs:
Use the JNDI naming context java:comp/env to access enterprise bean's environment.
 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok.May be i am missing something here. EJB 2.0 recommends using javax.naming.InitialContext. And also EJB 2.0 needs us to specify setEntityContext(EntityContext). So i am trying to get the variables out of the entity context. What is the best way to do that.
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All ejbs have some type of EJBContext that is provided by the EJB Container at runtime. This context provides many services (transactional, security-related, etc.), however accessing the ejb's environment properties are no longer one of provided services. Hence, the EJBContext.getEnvironment() method is deprecated.
The correct way to access enviroment properties from an ejb is using code similar to the code that I provided earlier.
 
Praveen Dharmavaram
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Chris. That explains a lot. I did code it that way.But wasnt sure if its going to work.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!