How to filter or intercept Restlet RIAP requests

17 views
Skip to first unread message

Daniel R

unread,
Sep 15, 2017, 4:11:10 AM9/15/17
to Restlet Framework (Discuss)

Hello there,
I'm trying to filter RIAP requests to capture some parameters for logging in Restlet 2.2

The filter already works just fine for external HTTP requests but it doesn't get invoked on RIAP requests.

This is the existing code on the `Resource` that will send the RIAP requests (it's a standard `Resource` that receives batched 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;
   
}



This is what I've 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;
   
}



It doesn't work. The target RIAP resource never gets invoked.

Based on https://stackoverflow.com/questions/26391048/restlet-client-how-to-add-filters
and https://stackoverflow.com/questions/6810128/restlet-riap-protocol-deployed-in-java-app-server
since the original `getClientDispatcher()` returns a type that doesn't accept a `setNext()` to attach the filter so I'm forced to mess around with ClientResources.

Very much appreciated.
Reply all
Reply to author
Forward
0 new messages