Package org.qi4j.library.rest.common

Examples of org.qi4j.library.rest.common.Resource$Mixin


    public boolean writeResponse( final Object result, final Response response )
        throws ResourceException
    {
        if( result instanceof Resource )
        {
            Resource resourceValue = (Resource) result;

            // Allowed methods
            response.getAllowedMethods().add( Method.GET );
            if( Iterables.matchesAny( LinksUtil.withRel( "delete" ), resourceValue.commands().get() ) )
            {
                response.getAllowedMethods().add( Method.DELETE );
            }
            if( Iterables.matchesAny( LinksUtil.withRel( "update" ), resourceValue.commands().get() ) )
            {
                response.getAllowedMethods().add( Method.PUT );
            }

            // Response according to what client accepts
            MediaType type = getVariant( response.getRequest(), ENGLISH, supportedMediaTypes ).getMediaType();
            if( MediaType.APPLICATION_JSON.equals( type ) )
            {
                response.setEntity( new StringRepresentation( resourceValue.toString(), MediaType.APPLICATION_JSON ) );
                return true;
            }
            else if( MediaType.TEXT_HTML.equals( type ) )
            {
                Representation rep = new WriterRepresentation( MediaType.TEXT_HTML )
View Full Code Here

TOP

Related Classes of org.qi4j.library.rest.common.Resource$Mixin

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.