unsupported media type

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

unsupported media type

Frank Kolnick
I get this error when issuing a PUT to a Restlet-based server.

Is there a way to tell Restlet to accept 'anything', i.e., all text-based content?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3084952
Reply | Threaded
Open this post in threaded view
|

RE: unsupported media type

Frank Kolnick
I have tried sending (PUT) with a content-type of "text/plain" (verified via Fiddler). On the server side, I have tried:

@Put("text/plain")

@Put("text")

@Put("plain")


I still get the media error in all cases.

What am I doing wrong? Can I tell Restlet to accept *anything*?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085086
Reply | Threaded
Open this post in threaded view
|

RE: unsupported media type

Fabian Mandelbaum

@Put

should be enough to tell Restlet to accept anything

El jul 14, 2014 1:16 PM, "Frank Kolnick" <[hidden email]> escribió:
I have tried sending (PUT) with a content-type of "text/plain" (verified via Fiddler). On the server side, I have tried:

@Put("text/plain")

@Put("text")

@Put("plain")


I still get the media error in all cases.

What am I doing wrong? Can I tell Restlet to accept *anything*?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085086
Reply | Threaded
Open this post in threaded view
|

RE: unsupported media type

Frank Kolnick
Unfortunately, that does not appear to be the case. I.e., that's where I started, and was getting the error. I tried the variations in order to fix the problem, so far without success.

> @Put
>
> should be enough to tell Restlet to accept anything
> El jul 14, 2014 1:16 PM, "Frank Kolnick" <reallyfrank at hotmail dot com> escribió:
>
> > I have tried sending (PUT) with a content-type of "text/plain" (verified
> > via Fiddler). On the server side, I have tried:
> >
> > @Put("text/plain")
> >
> > @Put("text")
> >
> > @Put("plain")
> >
> >
> > I still get the media error in all cases.
> >
> > What am I doing wrong? Can I tell Restlet to accept *anything*?
> >
> > ------------------------------------------------------
> >
> > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085086
> >

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085090
Reply | Threaded
Open this post in threaded view
|

Re: unsupported media type

Fabian Mandelbaum
Euh... I'm sorry but then the problem must be somewhere else.

I use @Put all the time, handling the different media types myself, and I only got HTTP 415 when my own-written code explicitly threw ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE).

can you please try this on your ServerResource (or extending) class:

@Put
public void handlePut(Representation data) {
if (data == null) {
  throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
} else {
   getLogger().info(String.format("Got PUT with media type %s", data.getMediaType()));
}
}

a PUT with no data in the request body should give you HTTP 400
a PUT with some data in the request body should give you a log entry with the request body media type.

If that still does not work try adding the following method to that class:

@Override
protected void initResource() {
  getVariants().add(MediaType.ALL); // I never had to use this, IIRC this is */*
}

Good luck!



On Mon, Jul 14, 2014 at 3:03 PM, Frank Kolnick <[hidden email]> wrote:
Unfortunately, that does not appear to be the case. I.e., that's where I started, and was getting the error. I tried the variations in order to fix the problem, so far without success.

> @Put
>
> should be enough to tell Restlet to accept anything
> El jul 14, 2014 1:16 PM, "Frank Kolnick" <reallyfrank at hotmail dot com> escribió:
>
> > I have tried sending (PUT) with a content-type of "text/plain" (verified
> > via Fiddler). On the server side, I have tried:
> >
> > @Put("text/plain")
> >
> > @Put("text")
> >
> > @Put("plain")
> >
> >
> > I still get the media error in all cases.
> >
> > What am I doing wrong? Can I tell Restlet to accept *anything*?
> >
> > ------------------------------------------------------
> >
> > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085086
> >

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085090



--
Fabián Mandelbaum
IS Engineer
Reply | Threaded
Open this post in threaded view
|

RE: Re: unsupported media type

Frank Kolnick
OK, I get it now: I have to get the content via a 'data' parameter, not by calling getEntity()  :-)

It now *almost* works perfectly.

I.e., my update method is called, I get the right data, I set the return status to 'SUCCESS_OK' and I'm done. But the client gets a 'no content' code.

I'm calling:

Response response = getResponse();
response.setStatus ( Status.SUCCESS_OK, "Test" );

Is this not the proper way to do it?

Thanks Fabian!

> Euh... I'm sorry but then the problem must be somewhere else.
>
> I use @Put all the time, handling the different media types myself, and I
> only got HTTP 415 when my own-written code explicitly threw
> ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE).
>
> can you please try this on your ServerResource (or extending) class:
>
> @Put
> public void handlePut(Representation data) {
> if (data == null) {
>   throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
> } else {
>    getLogger().info(String.format("Got PUT with media type %s",
> data.getMediaType()));
> }
> }
>
> a PUT with no data in the request body should give you HTTP 400
> a PUT with some data in the request body should give you a log entry with
> the request body media type.
>
> If that still does not work try adding the following method to that class:
>
> @Override
> protected void initResource() {
>   getVariants().add(MediaType.ALL); // I never had to use this, IIRC this
> is */*
> }
>
> Good luck!
>
>
>
> On Mon, Jul 14, 2014 at 3:03 PM, Frank Kolnick <reallyfrank at hotmail dot com>
> wrote:
>
> > Unfortunately, that does not appear to be the case. I.e., that's where I
> > started, and was getting the error. I tried the variations in order to fix
> > the problem, so far without success.
> >
> > > @Put
> > >
> > > should be enough to tell Restlet to accept anything
> > > El jul 14, 2014 1:16 PM, "Frank Kolnick" <reallyfrank at hotmail dot
> > com> escribió:
> > >
> > > > I have tried sending (PUT) with a content-type of "text/plain"
> > (verified
> > > > via Fiddler). On the server side, I have tried:
> > > >
> > > > @Put("text/plain")
> > > >
> > > > @Put("text")
> > > >
> > > > @Put("plain")
> > > >
> > > >
> > > > I still get the media error in all cases.
> > > >
> > > > What am I doing wrong? Can I tell Restlet to accept *anything*?
> > > >
> > > > ------------------------------------------------------
> > > >
> > > >
> > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085086
> > > >
> >
> > ------------------------------------------------------
> >
> > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085090
> >
>
>
>
> --
> Fabián Mandelbaum
> IS Engineer

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085217
Reply | Threaded
Open this post in threaded view
|

RE: Re: unsupported media type

Frank Kolnick
It's fine if I call setEntity() and return something/anything.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085219
Reply | Threaded
Open this post in threaded view
|

Re: Re: unsupported media type

Fabian Mandelbaum
In reply to this post by Frank Kolnick
Usually you just:

return someRepresentation; // This should automatically set status to HTTP 200 (OK)

or:

setStatus(Status.SUCCESS_CREATED); // Set status to HTTP 201
return someRepresentation;

where "someRepresentation" is the representation for the response you want to return for the PUT request.

Good luck.



On Tue, Jul 15, 2014 at 5:38 PM, Frank Kolnick <[hidden email]> wrote:
OK, I get it now: I have to get the content via a 'data' parameter, not by calling getEntity()  :-)

It now *almost* works perfectly.

I.e., my update method is called, I get the right data, I set the return status to 'SUCCESS_OK' and I'm done. But the client gets a 'no content' code.

I'm calling:

Response response = getResponse();
response.setStatus ( Status.SUCCESS_OK, "Test" );

Is this not the proper way to do it?

Thanks Fabian!

> Euh... I'm sorry but then the problem must be somewhere else.
>
> I use @Put all the time, handling the different media types myself, and I
> only got HTTP 415 when my own-written code explicitly threw
> ResourceException(Status.CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE).
>
> can you please try this on your ServerResource (or extending) class:
>
> @Put
> public void handlePut(Representation data) {
> if (data == null) {
>   throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST);
> } else {
>    getLogger().info(String.format("Got PUT with media type %s",
> data.getMediaType()));
> }
> }
>
> a PUT with no data in the request body should give you HTTP 400
> a PUT with some data in the request body should give you a log entry with
> the request body media type.
>
> If that still does not work try adding the following method to that class:
>
> @Override
> protected void initResource() {
>   getVariants().add(MediaType.ALL); // I never had to use this, IIRC this
> is */*
> }
>
> Good luck!
>
>
>
> On Mon, Jul 14, 2014 at 3:03 PM, Frank Kolnick <reallyfrank at hotmail dot com>
> wrote:
>
> > Unfortunately, that does not appear to be the case. I.e., that's where I
> > started, and was getting the error. I tried the variations in order to fix
> > the problem, so far without success.
> >
> > > @Put
> > >
> > > should be enough to tell Restlet to accept anything
> > > El jul 14, 2014 1:16 PM, "Frank Kolnick" <reallyfrank at hotmail dot
> > com> escribió:
> > >
> > > > I have tried sending (PUT) with a content-type of "text/plain"
> > (verified
> > > > via Fiddler). On the server side, I have tried:
> > > >
> > > > @Put("text/plain")
> > > >
> > > > @Put("text")
> > > >
> > > > @Put("plain")
> > > >
> > > >
> > > > I still get the media error in all cases.
> > > >
> > > > What am I doing wrong? Can I tell Restlet to accept *anything*?
> > > >
> > > > ------------------------------------------------------
> > > >
> > > >
> > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085086
> > > >
> >
> > ------------------------------------------------------
> >
> > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085090
> >
>
>
>
> --
> Fabián Mandelbaum
> IS Engineer

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3085217



--
Fabián Mandelbaum
IS Engineer