Search code examples
restjakarta-eejbossresteasyseam

No event context active - RESTeasy, Seam


I'm trying to add a RESTful web service with RESTeasy to our application running on JBoss 7.x, using Seam2.

I wanted to use as little Seam as possible, but I need it for Dependancy Injection.

My REST endpoints are as follows:

@Name("myEndpoint")
@Stateless
@Path("/path")
@Produces(MediaType.APPLICATION_JSON+"; charset=UTF-8")
public class MyEndpoint {
  @In private FooService fooService;

  @GET
  @Path("/foo/{bar}")
  public Response foobar(@CookieParam("sessionId") String sessionId, 
                             @PathParam("bar") String bar)
  { ... }
}

I'm using a class extending Application. There is no XML config. I can use the web service methods and they work, but I always get an IllegalStateException:

Exception processing transaction Synchronization after completion: java.lang.IllegalStateException: No event context active

Complete StackTrace

I did try everything in the documentation, but I can't get it away. If I leave out the @Stateless annotation, I don't get any Injection done. Adding @Scope doesn't do jack. Accessing the service via seam/resource/ doesn't even work (even without the Application class with @ApplicationPath).

It goes away if I don't use Dep. Injection, but instead add to each and every method

fooService = Component.getInstance("fooService");
Lifecycle.beginCall();
...
Lifecycle.endCall();

which isn't really a good solution. Nah, doesn't work either...


Solution

  • I have resolved the issue. For some reason (still not sure why, maybe because I tried to use Annotations and code exclusivly and no XML config), my REST service was availiable under a "non-standard" URL.

    Usually it'd be something like "/seam/resources/rest".

    Anyway, if you have a "custom" path, Seam doesn't know it should inject a context. You need to add <web:context-filter url-pattern="something" /> to your component.xml.

    Specifically we already had this tag, but with the attribute regex-url-pattern and I extended it to match the REST URL.