views:

269

answers:

5

I've got a bunch of stateless ejb 3.0 beans calling each other in chain. Consider, BeanA.do(message) -> BeanB.do() -> BeanC.do() -> BeanD.do(). Now i'd like to access message data from BeanD.do(). Obvious solution is to pass message as a parameter to all that do() calls (actually that's how it works now), but i want some nicer solution.

Is there some kind of call context? And can i associate arbitrary data with it?

What i'd like to do, is simply put message in BeanA.do(message) to some local storage associated with bean function call and retrieve it in BeanD.do().

Any ideas?

+1  A: 

i don't believe there is anything in the EJB spec that provides that functionality. If you are on a specific app server, you may be able to use app server specific stuff (i think JBoss allows you to add stuff to a call context). you also may be able to fake something up using JNDI.

personally, this seems (to me) like a poor design. i could see doing this if you had some code in the middle you could not control, but why do it otherwise? you are making your code logic very hard to follow because you have a bunch of "magic" data which just appears in your function.

james
Thanks for your answer. I'll try searching JBoss docs.In other case I'd agree with you, that "magic" data isn't good. But in current situation passing context data explicitly only distracts from real business logic.
begray
A: 

You could have a class with static get/set methods that access a static ThreadLocal field. However I would take james' advice and consider very carefully if you want to couple your EJBs to that other class. Definitely double-check your app server docs as I'm not sure if using ThreadLocals in an EJB environment is supported.

cliff.meyers
A: 

I have exactly the same problem. The ironic part is that this is easy to do with SOAP in jax-ws or jax-rpc, but hard to do with EJB.

I'm debating whether to give up on using the EJB Local or Remote interfaces, and instead passing messages via JMS, which also makes this easy.

There are legitimate cases where this is needed, and doesn't represent a design flaw.

A: 

This is what Seam provides. It is a bit awkward to get running with pure web-services (i.e. no web GUI front end). However, I have managed, and it works beautifully.

A: 

I need to use the Call Context in JAX WS. Brent says "The ironic part is that this is easy to do with SOAP in jax-ws or jax-rpc, but hard to do with EJB."

Can you please let me know how to use the Call context in JAX WS