1

I'm running a CDI based application on JBoss AS 7.1.1 which uses Conversation Scoped Beans. I need to invoke one of these beans from a RESTeasy Service. Unfortunately when I invoke the Conversation Scoped Bean

@Inject
private ConversationBean service; 


@GET
@Produces("text/html")
@Path("/book")
public void bookTicket(Long l) {

    service.book(l);
    . . . .
} 

the following error is returned:

Caused by: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.ConversationScoped

Is there any workaround for this issue ?
Thanks!

Max Korn
  • 275
  • 7
  • 18

1 Answers1

4

I know I've answered this question before (or maybe it was @SessionScoped, same thing really). The Conversation is tied to a Session in CDI. As there are no Sessions in JAX-RS there are no conversations. In the spec section 6.7.4 it states that the Conversation scope is only active during JSF requests.

If you would like to create your own Scope and Context that acts like the conversation one and make it available to JAX-RS requests, that's certainly doable, but you'd have to have some location to store the scope and also associate it with a request.

LightGuard
  • 5,298
  • 19
  • 19
  • Can you explain why the `javax.enterprise.context.SessionScoped` does seem work in RESTeasy? Or is this due to the fact that I use RESTeasy in combination with a AngularJS webpage serviced from the same JBoss (7.1.1-Final)? – gkephorus Nov 18 '13 at 12:10
  • My bet is if you looked at things, it's creating a new session scoped bean proxy every time it's accessed, or do you actually see state being properly preserved between requests? – LightGuard Nov 18 '13 at 22:29
  • 1
    Yes, a cookie is send to the client and when this is then send back, the session is preserved in the server. (note: we do use a full browser as the REST-client, I can imagine that when you use a state-less client, the cookie will not be send back and hence you lose the session) – gkephorus Nov 19 '13 at 09:31
  • 1
    If anybody else has the same problem, this blog posts explains how you can use ConversationScoped with JAX-RS http://www.knitelius.com/2015/07/22/cdi-conversations-for-jax-rs-with-jee-6/ – dngfng Aug 26 '15 at 07:11