use of org.restlet.data.ChallengeResponse in project qi4j-sdk by Qi4j.
the class ContextResourceClient method invokeCommand.
private HandlerCommand invokeCommand(Reference ref, Method method, Object requestObject, ResponseHandler responseHandler, ResponseHandler processingErrorHandler) {
Request request = new Request(method, ref);
if (requestObject == null)
requestObject = new EmptyRepresentation();
contextResourceFactory.writeRequest(request, requestObject);
contextResourceFactory.updateCommandRequest(request);
User user = request.getClientInfo().getUser();
if (user != null)
request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC, user.getName(), user.getSecret()));
Response response = new Response(request);
contextResourceFactory.getClient().handle(request, response);
try {
if (response.getStatus().isSuccess()) {
contextResourceFactory.updateCache(response);
if (responseHandler != null)
return responseHandler.handleResponse(response, this);
} else {
if (response.getStatus().equals(Status.CLIENT_ERROR_UNPROCESSABLE_ENTITY) && processingErrorHandler != null) {
return processingErrorHandler.handleResponse(response, this);
} else {
// TODO This needs to be expanded to allow custom handling of all the various cases
return errorHandler.handleResponse(response, this);
}
}
// No handler found
return null;
} finally {
try {
response.getEntity().exhaust();
} catch (Throwable e) {
// Ignore
}
}
}
Aggregations