Re: What is the correct way to return 415 Unsupported Media Type

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: What is the correct way to return 415 Unsupported Media Type

Thierry Boileau
Hello Gabriel,

this is a very good question which has no answer yet, I think.
I've entered a new RFE => http://restlet.tigris.org/issues/show_bug.cgi?id=637

>
Right now I do the following, is this the way to go?
That's fine for me.

Best regards,
Thierry Boileau
--
Restlet ~ Core developer ~ http://www.restlet.org
Noelios Technologies ~ Co-founder ~ http://www.noelios.com


Hi, there is a standard way to tell the framework which media types is
supported on a GET via getVariants().add(...). Is there a similar way
to tell the framework which media types a resource accepts on
POST/PUT?

Right now I do the following, is this the way to go?

/**
 * Handle POST request
 */
@Override
public void acceptRepresentation(Representation entity) throws
ResourceException {
    if (entity.getMediaType() == null ||
!entity.getMediaType().isCompatible(MediaType.APPLICATION_WWW_FORM)) {
        String msg = String.format("Resource can only be created using
media type: %s, got %s",
                MediaType.APPLICATION_WWW_FORM, entity.getMediaType());
        getResponse().setStatus(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE,
msg);
        return;
    }

    //Do stuff

}

Best Regards
Gabriel Falkenberg