How to filter or intercept Restlet RIAP requests

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to filter or intercept Restlet RIAP requests

Daniel R

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.

--
You received this message because you are subscribed to the Google Groups "Restlet Framework (Discuss)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].