How to filter or intercept Rlet requests

I am trying to filter out RIAP requests to capture some parameters for registration in Restlet 2.2

The filter already works fine for external HTTP requests, but it won't run on RIAP requests.

This is the existing code for Resource

that will send RIAP requests (this is the standard Resource

one that receives batch requests from the outside and in turn generates N internal RIAP requests):

protected Response dispatch(Method method, String url, EntityMap body) {
    ...
    Request req = new Request(method, "riap://component" + url);
    ReqResUtils.copyRequestHeadersAndCookies(getRequest(), req);
    ...
    JsonRepresentation json = new JsonRepresentation(body);
    json.setMediaType(MediaType.APPLICATION_JSON);
    req.setEntity(json);

    Response res = getContext().getClientDispatcher().handle(req);

    getResponse().setStatus(res.getStatus());
    return res;
}

      

Here is what I have tried

protected Response dispatch(Method method, String url, EntityMap body) {
    ...
    Request req = new Request(method, "riap://component" + url);
    ReqResUtils.copyRequestHeadersAndCookies(getRequest(), req);
    ...
    JsonRepresentation json = new JsonRepresentation(body);
    json.setMediaType(MediaType.APPLICATION_JSON);
    req.setEntity(json);

    ClientResource cr = new ClientResource(getContext(), req, new Response(req));
    RQParamsLoggingFilter filter = new RQParamsLoggingFilter(getContext(), new ApiLogService());
    cr.setNext(filter);
    filter.setNext(new Client(getContext(), Protocol.RIAP));
    final Representation representationRes = cr.get();
    Response res = cr.getResponse();
    ...
    getResponse().setStatus(res.getStatus());
    return res;
}

      

This does not work. The RIAP target resource does not start.

On the basis of Restlet Client :: how to add filters? and RETAP protocol for restyling, deployed to the Java application server , since the original getClientDispatcher()

returns a type that does not accept a setNext()

filter to attach, so I am forced to communicate with ClientResources.

Much appreciated.

0


source to share





All Articles