Java Code Examples for org.restlet.Response.setStatus()

The following are Jave code examples for showing how to use setStatus() of the org.restlet.Response 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: prudence   File: PrudenceRouter.java   Source Code and License Vote up 6 votes
@Override
public void handle( Request request, Response response )
{
	// RIAP ignores hide
	if( request.getProtocol() != Protocol.RIAP )
	{
		String remainingPart = request.getResourceRef().getRemainingPart();
		for( Template hiddenUriTemplate : hiddenUriTemplates )
		{
			if( hiddenUriTemplate.match( remainingPart ) != -1 )
			{
				response.setStatus( Status.CLIENT_ERROR_NOT_FOUND );
				return;
			}
		}
	}

	super.handle( request, response );
}
 
Example 2
Project: prudence   File: GeneratedTextDeferredRepresentation.java   Source Code and License Vote up 6 votes
public void run()
{
	if( delay > 0 )
	{
		try
		{
			Thread.sleep( delay );
		}
		catch( InterruptedException e )
		{
			// Restore interrupt status
			Thread.currentThread().interrupt();
			return;
		}
	}

	Response response = resource.getResponse();
	response.setEntity( this );
	response.setStatus( Status.SUCCESS_OK );
	response.commit();
}
 
Example 3
Project: Camel   File: MethodBasedRouter.java   Source Code and License Vote up 5 votes
@Override
public void handle(Request request, Response response) {
    Method method = request.getMethod();
    LOG.debug("MethodRouter ({}) received request method: {}", uriPattern, method);
    
    Restlet target = routes.get(method);
    if (target != null) {
        target.handle(request, response);
    } else {
        LOG.debug("MethodRouter ({}) method not allowed: {}", uriPattern, method);
        response.setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
        // must include list of allowed methods
        response.setAllowedMethods(routes.keySet());
    }
}
 
Example 4
Project: prudence   File: PrudenceApplication.java   Source Code and License Vote up 5 votes
@Override
public void handle( Request request, Response response )
{
	if( isStarted() )
		super.handle( request, response );
	else
		response.setStatus( Status.CLIENT_ERROR_NOT_FOUND );
}
 
Example 5
Project: prudence   File: UnifyMinifyFilter.java   Source Code and License Vote up 5 votes
@Override
protected int beforeHandle( Request request, Response response )
{
	Reference reference = request.getResourceRef();
	String name = reference.getLastSegment( true, false );
	try
	{
		boolean validate = false;
		boolean minify = false;
		if( name.equals( unifiedFilename ) )
			validate = true;
		else if( name.equals( unifiedMinifiedFilename ) )
		{
			validate = true;
			minify = true;
		}

		if( validate )
		{
			long now = System.currentTimeMillis();
			long lastValidityCheck = this.lastValidityCheck.get();
			if( lastValidityCheck == 0 || ( now - lastValidityCheck > minimumTimeBetweenValidityChecks ) )
			{
				if( this.lastValidityCheck.compareAndSet( lastValidityCheck, now ) )
					unify( targetDirectory, minify );
			}
		}
	}
	catch( IOException x )
	{
		response.setStatus( Status.SERVER_ERROR_INTERNAL, x );
		return Filter.STOP;
	}

	return Filter.CONTINUE;
}
 
Example 6
Project: prudence   File: DelegatedStatusService.java   Source Code and License Vote up 4 votes
@Override
public Representation toRepresentation( Status status, Request request, Response response )
{
	if( isEnabled() )
	{
		ConcurrentMap<String, Object> attributes = response.getAttributes();

		Object passthrough = attributes.get( PASSTHROUGH_ATTRIBUTE );
		if( ( passthrough != null ) && (Boolean) passthrough )
			// Pass through
			return response.getEntity();

		Restlet handler = handlers.get( status.getCode() );
		if( handler != null )
		{
			// Reset the response
			response.setStatus( Status.SUCCESS_OK );
			response.setEntity( null );

			// Clean up saved information
			CachingUtil.clearExistingValidDocumentName( request );

			// Delegate
			handler.handle( request, response );

			// Return the status
			response.setStatus( status );

			Representation representation = response.getEntity();
			if( representation != null )
			{
				// Avoid client caching, which would require other
				// interchanges with the client that we can't handle from
				// here
				representation.setExpirationDate( null );
				representation.setModificationDate( null );
				representation.setTag( null );
			}

			attributes.put( PASSTHROUGH_ATTRIBUTE, true );
			return representation;
		}

		if( isFallback )
			// Fallbacks don't override the entity if there are no handlers
			return response.getEntity();

		if( isDebugging() && ( status.getThrowable() != null ) )
		{
			// Use the debug representation for exceptions
			attributes.put( PASSTHROUGH_ATTRIBUTE, true );
			if( debugHeader != null )
				RestletUtil.getResponseHeaders( response ).set( debugHeader, "error" );
			return createDebugRepresentation( status, request, response );
		}
	}

	return super.toRepresentation( status, request, response );
}
 
Example 7
Project: prudence   File: ZussFilter.java   Source Code and License Vote up 4 votes
@Override
protected int beforeHandle( Request request, Response response )
{
	Reference reference = request.getResourceRef();
	String path = reference.getRemainingPart( true, false );
	try
	{
		// String name = reference.getLastSegment( true, false );
		String zussPath = null;
		boolean minify = false;
		if( path.endsWith( CSS_MIN_EXTENSION ) )
		{
			zussPath = path.substring( 0, path.length() - CSS_MIN_EXTENSION_LENGTH ) + ZUSS_EXTENSION;
			minify = true;
		}
		else if( path.endsWith( CSS_EXTENSION ) )
			zussPath = path.substring( 0, path.length() - CSS_EXTENSION_LENGTH ) + ZUSS_EXTENSION;

		if( zussPath != null )
		{
			long now = System.currentTimeMillis();
			AtomicLong lastValidityCheckAtomic = getLastValidityCheck( path );
			long lastValidityCheck = lastValidityCheckAtomic.get();
			if( lastValidityCheck == 0 || ( now - lastValidityCheck > minimumTimeBetweenValidityChecks ) )
			{
				if( lastValidityCheckAtomic.compareAndSet( lastValidityCheck, now ) )
				{
					for( File sourceDirectory : sourceDirectories )
					{
						File zussFile = new File( sourceDirectory, zussPath );
						if( zussFile.exists() )
						{
							File cssFile = new File( targetDirectory, path );
							translate( zussFile, cssFile, minify );
							break;
						}
					}

					// ZUSS file was not found, so don't keep the entry for
					// it
					this.lastValidityChecks.remove( path );
				}
			}
		}
	}
	catch( IOException x )
	{
		response.setStatus( Status.SERVER_ERROR_INTERNAL, x );
		return Filter.STOP;
	}

	return Filter.CONTINUE;
}
 
Example 8
Project: prudence   File: LessFilter.java   Source Code and License Vote up 4 votes
@Override
protected int beforeHandle( Request request, Response response )
{
	Reference reference = request.getResourceRef();
	String path = reference.getRemainingPart( true, false );
	try
	{
		// String name = reference.getLastSegment( true, false );
		String lessPath = null;
		boolean minify = false;
		if( path.endsWith( CSS_MIN_EXTENSION ) )
		{
			lessPath = path.substring( 0, path.length() - CSS_MIN_EXTENSION_LENGTH ) + LESS_EXTENSION;
			minify = true;
		}
		else if( path.endsWith( CSS_EXTENSION ) )
			lessPath = path.substring( 0, path.length() - CSS_EXTENSION_LENGTH ) + LESS_EXTENSION;

		if( lessPath != null )
		{
			long now = System.currentTimeMillis();
			AtomicLong lastValidityCheckAtomic = getLastValidityCheck( path );
			long lastValidityCheck = lastValidityCheckAtomic.get();
			if( lastValidityCheck == 0 || ( now - lastValidityCheck > minimumTimeBetweenValidityChecks ) )
			{
				if( lastValidityCheckAtomic.compareAndSet( lastValidityCheck, now ) )
				{
					for( File sourceDirectory : sourceDirectories )
					{
						File lessFile = new File( sourceDirectory, lessPath );
						if( lessFile.exists() )
						{
							File cssFile = new File( targetDirectory, path );
							translate( lessFile, cssFile, minify );
							break;
						}
					}

					// LESS file was not found, so don't keep the entry for
					// it
					this.lastValidityChecks.remove( path );
				}
			}
		}
	}
	catch( IOException x )
	{
		response.setStatus( Status.SERVER_ERROR_INTERNAL, x );
		return Filter.STOP;
	}

	return Filter.CONTINUE;
}
 
Example 9
Project: prudence   File: StatusRestlet.java   Source Code and License Vote up 4 votes
@Override
public void handle( Request request, Response response )
{
	response.setStatus( status );
}