ContextResourceClientFactory contextResourceClientFactory = module.newObject( ContextResourceClientFactory.class, client );
contextResourceClientFactory.setAcceptedMediaTypes( MediaType.APPLICATION_JSON );
//END SNIPPET: client-create1
//START SNIPPET: client-create2
contextResourceClientFactory.setErrorHandler( new ErrorHandler().onError( ErrorHandler.AUTHENTICATION_REQUIRED, new ResponseHandler()
{
boolean tried = false;
@Override
public HandlerCommand handleResponse( Response response, ContextResourceClient client )
{
if( tried )
{
throw new ResourceException( response.getStatus() );
}
tried = true;
client.getContextResourceClientFactory().getInfo().setUser( new User( "rickard", "secret" ) );
// Try again
return refresh();
}
} ).onError( ErrorHandler.RECOVERABLE_ERROR, new ResponseHandler()
{
@Override
public HandlerCommand handleResponse( Response response, ContextResourceClient client )
{
// Try to restart