Is it possible to call a Seam bean from JAX-RS/WebEngine ? Is it possible to call a Seam bean from JAX-RS/WebEngine ?

Hello everyone! Here's an interesting question from Youri: Is it possible to call a Seam bean from JAX-RS/WebEngine?
As he says, Restlets have been integrated with Seam. But what about JAX-RS/WebEngine? And what would I add about Content Automation?

For Content Automation, it's actually quite easy. When you write a new operation, you can use Seam's Contexts object to lookup the components you need. Take a look at OperationHelper.getWebActions for instance:

public static WebActions getWebActions() {
return (WebActions) Contexts.getConversationContext().get("webActions");

This is quite simple, as it's a direct lookup to Seam's instantiated components Map, here in the Conversation context. You can also access components in another Context-like application, method, event, page or session. If the component you're looking for hasn't been instantiated, you'll simply get null. To avoid this situation, you should use the following code:

public static DocumentActions getDocumentActions() {
return (DocumentActions) SeamComponentCallHelper.getSeamComponentByName("documentActions");

It's a little different. It will do a lookup on all contexts, and if it does not find any instance, will go through the Seam Factory to create and return a new instance of the component. So it's a safer method than the direct lookup in the Seam Contexts object.

Now, what if you already have a conversation and want to reuse it? Again it's easy with Content Automation, as we already have operations for that.
Take Seam.RunOperation for instance. You can use the conversationId parameter to specify the conversation you want to use. You can also use Seam.InitContext to create or reuse a conversation in your operation chain. If you're interested in how the conversations are handled, take a look at the SeamOperationFilter.

So about WebEngine, you can use the same code. Actually, Content Automation is based on JAX-RS, too, so it should make no difference.

Drop me a line in the comment space if you need more clarifications on this topic.

See you next week!