quarks
quarks

Reputation: 35276

The right way to do Filtering with Restlet

Here is my Filter code that I need to fix. The idea behind the filter is that if some query string is found. Process it, no need to return or process the chain or something like that. However when no query string is found, the original request should be serviced, e.g. get/put/update/delete request.

    @Override
    protected int doHandle(Request request, Response response) {
        HttpServletRequest servletRequest = ServletUtils.getRequest(request);
        HttpServletResponse servletResponse = ServletUtils.getResponse(response);
        String query = servletRequest.getQueryString();
        LOG.info("Query=" + query);
        if(query != null && query.contains(ESCAPED_FRAGMENT_FORMAT1)){
            // TODO: return a HTML String, no need to go down the chain.
            return STOP;
        } else {
            // TODO: need to execute the original request
            return SKIP;
        }
        return CONTINUE;
    }

The problem here is that I am not totally sure where to return STOP, SKIP and CONTINUE in this code to achive what I need.

Upvotes: 0

Views: 647

Answers (1)

Thierry Boileau
Thierry Boileau

Reputation: 866

  • CONTINUE: indicates that the request processing should continue normally.
  • STOP: indicates that the request processing should stop and return the current response from the filter.
  • SKIP: indicates that after the beforeHandle(Request, Response) method, the request processing should skip the doHandle(Request, Response) method to continue with the afterHandle(Request, Response) method. The doHandle method Handles the call by distributing it to the next Restlet.

You can find the needed explanations in the javadocs: http://restlet.com/technical-resources/restlet-framework/javadocs/2.3/jse/api/org/restlet/routing/Filter.html

I hope this will help you.

Upvotes: 1

Related Questions