3 Replies Latest reply on Oct 6, 2008 11:31 AM by Mark Egert

    How to build a RestEasy-Sub-Resource as Seam-Component ?

    Mark Egert Newbie


      I'am trying to get the Seam-Injection-Support in a RestEasy-Sub-Resource, but cant get it work.
      I wrote a rest-resource as a seam-component wich provide a Path to the sub-resource TestsResource:

      public class SampleResource {
          private EntityManager entityManager;
          private TestsResource testsResource;
          public TestsResource getTestsResource(){   
              return testsResource;    <---- ????

      It seems as I can't return the injected 'testsResource' because it produce a NullPointerException
      at org.resteasy.ResourceLocator.invokeOnTargetObject(ResourceLocator.java:149)

      The Sub-Resource looks like this:

      public class TestsResource {
          private EntityManager entityManager;
          private TestHome testHome;
          @ProduceMime({"application/xml", "application/json"})
          public TestsConverter get(@Context UriInfo uriInfo) {
              return new TestsConverter(getEntities(), uriInfo.getAbsolutePath());
          @ConsumeMime({"application/xml", "application/json"})
          public Response post(TestConverter data, @Context UriInfo uriInfo) {
              Test entity = data.getEntity();
              return Response.created(uriInfo.getAbsolutePath().resolve(entity.getUsrrid() + "/")).build();

      Of course, if the sub-resource is just a normal resource (not a seam-component), I can instantiate the class with 'new TestsResource(...)' and it works. But I need the seam-component 'TestHome extends EntityHome' in the sub-resource, to persist my entity and I can't use injection in a non-seam-component. So I have to inject 'TestHome' in 'SampleResource' and pass it to the sub-resource:

          public TestsResource getTestsResource(){
              return new TestsResource(entityManager, testHome);

      Anybody knows a better way to handle this?