I am somewhat of a J2EE newbie, so this may be a simple task. I have a J2EE servlet that uses an EJB. The EBJ (indirectly) then has to
interact with an external JMS provider. The servlet created the EJB as such ("RequestDispatcherBean" is the name of the bean class):
Context ctx = new InitialContext();
RequestDispatcherHome requestDispatcherHome = (RequestDispatcherHome)ctx.lookup("java:comp/env/ejb/RequestDispatcherBean");
The EJB code has to load the JMS provider library that is going to be called, so we have code like this:
InitialContext iniCtx = new InitialContext(environment);
... remaining JMS connection/queue setup and execution...
The first time the servlet creates the EJBm which in turn, calls the JMS code, everything works. However, the second time the sevlet is
invoked, I get this error: javax.naming.NameNotFoundException: remaining name: env/ejb/RequestDispatcherBean.
This makes sense now, as I am changing the context, and then when the servlet is invoked again, the "original" context is gone.
So, the question I have, is there a way to cache the original context's environment, then restore it in the servlet once the JMS session is completed, such that the next
time the servlet is invoked, the environment is correct?
Do what you did before to get the prior context. Nine of these operations affects any global state in JNDI. The syntax of the operations alone should make that clear. You're just creating a new Context every time with a new environment. I suspect you are barking up the wrong tree completely.