Reputation: 21319
I am writing a custom Jersey 2.0 server logging filter.
A reference to ResourceInfo
is injected as:
@Context
private ResourceInfo resourceInfo;
Interface ResourceInfo
has two methods:
Class<?> getResourceClass()
Method getResourceMethod()
Is there ever a case where ResourceInfo.getResourceClass() != ResourceInfo.getResourceMethod().getDeclaringClass()
?
Bonus question: Both methods may return null
. Is it possible that only one would be null
?
Upvotes: 2
Views: 2819
Reputation: 14731
Can't say much about null values, but there is a case when getResourceClass() != getResourceMethod().getDeclaringClass()
if you have some class hierarchy like superclass resource. It is easier to show in code, so consider this:
public class SuperResource {
@GET
@Produces({ MediaType.APPLICATION_JSON })
public Response getInfo() {
return Response.ok("{\"info\":1}").build();
}
}
@Path("test")
public class MyResource extends SuperResource{
// ... other endpoints
}
Now lets call
GET http://localhost:9998/test/
getResourceClass() : class ru.varren.MyResource
getResourceMethod(): javax.ws.rs.core.Response ru.varren.SuperResource.getInfo()
Upvotes: 4