Search in sources :

Example 11 with ResponseHandler

use of org.qi4j.library.rest.client.spi.ResponseHandler in project qi4j-sdk by Qi4j.

the class ContextResourceClient method onCommand.

public <T> ContextResourceClient onCommand(String relation, final ResultHandler<T> handler) {
    final Class<T> resultType = (Class<T>) Classes.RAW_CLASS.map(((ParameterizedType) handler.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0]);
    commandHandlers.put(relation, new ResponseHandler() {

        @Override
        public HandlerCommand handleResponse(Response response, ContextResourceClient client) {
            T result = contextResourceFactory.readResponse(response, resultType);
            return handler.handleResult(result, client);
        }
    });
    return this;
}
Also used : ChallengeResponse(org.restlet.data.ChallengeResponse) Response(org.restlet.Response) NullResponseHandler(org.qi4j.library.rest.client.spi.NullResponseHandler) ResponseHandler(org.qi4j.library.rest.client.spi.ResponseHandler)

Example 12 with ResponseHandler

use of org.qi4j.library.rest.client.spi.ResponseHandler in project qi4j-sdk by Qi4j.

the class HandlerCommand method onProcessingError.

public <T> HandlerCommand onProcessingError(final ResultHandler<T> resultHandler) {
    final Class<T> resultType = (Class<T>) Classes.RAW_CLASS.map(((ParameterizedType) resultHandler.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0]);
    this.processingErrorHandler = new ResponseHandler() {

        @Override
        public HandlerCommand handleResponse(Response response, ContextResourceClient client) {
            T result = client.getContextResourceClientFactory().readResponse(response, resultType);
            return resultHandler.handleResult(result, client);
        }
    };
    return this;
}
Also used : Response(org.restlet.Response) ResponseHandler(org.qi4j.library.rest.client.spi.ResponseHandler)

Aggregations

ResponseHandler (org.qi4j.library.rest.client.spi.ResponseHandler)12 Response (org.restlet.Response)12 ContextResourceClient (org.qi4j.library.rest.client.api.ContextResourceClient)7 HandlerCommand (org.qi4j.library.rest.client.api.HandlerCommand)7 Test (org.junit.Test)5 AbstractQi4jTest (org.qi4j.test.AbstractQi4jTest)5 ResultHandler (org.qi4j.library.rest.client.spi.ResultHandler)4 Resource (org.qi4j.library.rest.common.Resource)4 Link (org.qi4j.library.rest.common.link.Link)4 Links (org.qi4j.library.rest.common.link.Links)4 ContextResource (org.qi4j.library.rest.server.api.ContextResource)4 ContextResourceClientFactory (org.qi4j.library.rest.client.api.ContextResourceClientFactory)3 ErrorHandler (org.qi4j.library.rest.client.api.ErrorHandler)3 NullResponseHandler (org.qi4j.library.rest.client.spi.NullResponseHandler)3 Client (org.restlet.Client)3 ChallengeResponse (org.restlet.data.ChallengeResponse)3 Reference (org.restlet.data.Reference)3 ResourceException (org.restlet.resource.ResourceException)3 Before (org.junit.Before)2 ContextRestlet (org.qi4j.library.rest.server.api.ContextRestlet)2