users@jersey.java.net

[Jersey] Conditional matched resource invocation

From: Behrooz Nobakht <nobeh5_at_gmail.com>
Date: Mon, 9 Nov 2015 07:22:29 +0100

Hi,

Let's consider the following simple example:

class MyResource {

private final LifeCycle lc;

public Response getState() {
  return Response.ok(lc.getState().toString()).build();
}

public Response someCustomOp() {
  // Use a filter for this
  if (!isRunning(lc.getState()) {
    // Abort Response
  }
  // else do the custom op
}

}

I'd like to implement a request filter in which I can access the
matched/built/proxied MyResource *instance*
to be able to check the state of the life cycle object and then decide
about the execution there.
I tried to use ResourceInfo abstraction but this one only gives me access
to the *class* and *method* level information
and I need to access the *instance* of matched MyResource in the filter.
Argument for a filter is that there are a number of resources that inherit
the same operation of LifeCycle and a filter
can help to centrally unify their operations based on certain states.

How can I do this?

Thanks,
Behrooz