views:

713

answers:

1

Consider the following simple RESTEasy (JAX-RS) service:

@Path("/example-service")
public interface ExampleService {

    @Path("/ping")
    @GET
    public String ping(String message);

}

I want to define JAXRS specifics on the interface rather than the class so I can use the nice client framework, ie:

ExampleService client = ProxyFactory.create(ExampleService.class, "http://localhost:8080");

Everything works well, except for when I want to introduce some of RESTEasy's context injections, ie: @Context. Naively, consider the following:

@Path("/example-service")
public interface ExampleService {

    @Path("/ping")
    @GET
    public String ping(@Context HttpServletRequest request, String message);

}

This obviously doesn't make sense because this @Context injection is orthogonal and doesn't belong on the interface (furthermore, even if I can get past the ugliness of this interface from the client perspective and pass null, there is currently a bug preventing this from working: RESTEASY-311)

How can I use interface JAXRS markup (and therefore leverage the nice RESTEasy client framework) and access orthogonal @Context injections at the same time?

A: 

As this question is phrased, this can be easily solved with a @Context field injection in the implementation. What complicated this particular situation was the use of RESTEasy's "ejb-integration" which retrieves the implementation from JNDI. This solution does not (yet) perform additional REST injections on the implementation retrieved from the EJB container. This will all be easier with the upcoming JEE6/JAXRS integration.

jnorris