my dog learned polymorphism*
The moose likes EJB and other Java EE Technologies and the fly likes How to identify the current running context? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to identify the current running context?" Watch "How to identify the current running context?" New topic

How to identify the current running context?

Boopathi Ramasamy

Joined: Dec 03, 2004
Posts: 3
Hi, I have a class file that needs to identify the context it is currently running in. Based on its context my logic will differ.
For ex: my class can be instantiated by a servlet or a session bean. How do i find out at runtime, the code is getting called from servlet or ejb?
Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30136

Can you pass this information to your class when you instantiate it?

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Camilo Morales
Ranch Hand

Joined: Jul 14, 2007
Posts: 92

There is a class called: SessionContext, that you can inject with EJB 3.0, or, I guess, lookup in EJB 2.x.

SessionContext extends the javax.ejb.EJBContext class. EJBContext defines several methods that provide useful information to a bean at runtime.

There is a lot of information about this class in the Enterprise JavaBeans, 3.0 By Bill Burke, Richard Monson-Haefel, (O'Reilly).

Hope this helps,

Camilo Morales

Camilo Morales<br />SCJP 5, SCBCD 5
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
It is usually an indication of poor design if you need to know in what context you class exists. It makes your class non portable...
I agree. Here's the link:
subject: How to identify the current running context?
Similar Threads
Identify context path + servlet path+ path info for given URL
New forum for Sun Certified Web Component Developer
Installing Softwares & Updating Ubuntu
calling external servlet from my servlet
Accessing a servlet from a Struts App running in another context.