Java Code Examples for org.restlet.Request.setChallengeResponse()

The following are Jave code examples for showing how to use setChallengeResponse() of the org.restlet.Request class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: polygene-java   File: ContextResourceClient.java   Source Code and License Vote up 5 votes
private HandlerCommand invokeQuery( Reference ref, Object queryRequest, ResponseHandler resourceHandler, ResponseHandler processingErrorHandler )
{
    Request request = new Request( Method.GET, ref );

    if( queryRequest != null )
    {
        contextResourceFactory.writeRequest( request, queryRequest );
    }

    contextResourceFactory.updateQueryRequest( 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 );

    if( response.getStatus().isSuccess() )
    {
        contextResourceFactory.updateCache( response );

        return resourceHandler.handleResponse( response, this );
    } else if (response.getStatus().isRedirection())
    {
        Reference redirectedTo = response.getLocationRef();
        return invokeQuery( redirectedTo, queryRequest, resourceHandler, processingErrorHandler );
    } 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 );
        }
    }
}
 
Example 2
Project: MCRest   File: AuthResourceTest.java   Source Code and License Vote up 5 votes
private Response getRequestResultWithAuth(String path,String user,String password){
    Request request = new Request(Method.GET, serverUrl+path);
    Client client = new Client(Protocol.HTTP);

    ChallengeResponse authentication = new ChallengeResponse(
            ChallengeScheme.HTTP_BASIC, user, password);
    request.setChallengeResponse(authentication);

    Response response = client.handle(request);
    return response;
}