users@jersey.java.net

[Jersey] Re: Jersey2: Impossible to POST with empty entity?

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Tue, 12 Nov 2013 13:53:57 +0100

On 08 Nov 2013, at 17:53, cowwoc <cowwoc_at_bbs.darktech.org> wrote:

> On 08/11/2013 7:15 AM, Marek Potociar wrote:
>> Resource should represent a concept, not a particular representation of a concept. Resource should be identified by URI (or new content), not by content-type.
>
> You've convinced me. I've made the modification you suggested (@POST on the collection), but I'd still like to be able to specify a Content-Type with an empty request body (unless we figure out how to get @Consumes to match the lack of Content-Type). Can I open a feature request for this?

I'm waiting for a confirmation from RedHat that they agree with the proposed change.

Marek

>
>> We do not eliminate. Our mission, though, is to provide hight-level API that helps you design and implement your services according to the principles of REST (See JSR-311, section 2.1). As such, we are not going to make it simpler for anyone to do ugly stuff. One can use directly lower-level Servlet API if wants to do something non-RESTful with HTTP.
>
> The definition of "ugly" is subjective.
> How are we supposed to use the lower-level Servlet API? Are you expecting us to use a Servlet Filter to mutate the response after Jersey sets it? Isn't it already too late at that point (the stream is already flushed)? This also sounds like maintenance hell for unit tests! If you'd really like to punt to the lower-level Servlet API, there should be an (easy!) way for me to translate a Jersey request/response to a Servlet request/response within the same method (as opposed to using filters which require me to spread the logic across multiple classes). The resulting code has to be easy to maintain.
>
>>>>> POST without either a Content-Type or body
>>>>> Used to insert a new element into a collection (there is no confusion about the kind of child resource being created).
>>>>> Example: Create a new "transaction" by invoking POST /transactions: http://stackoverflow.com/a/147299/14731
>>>> This is doable, right?
>>>
>>> I'm not sure. Are you expecting me to pass null into entity or MediaType in this method? https://jersey.java.net/apidocs/snapshot/jersey/javax/ws/rs/client/Entity.html#entity(T, javax.ws.rs.core.MediaType) If so, the Javadoc should really mention that passing null is an acceptable way to omit the field.
>>
>> Passing null should work.
>>
>
> Okay, thanks. I'll try this out once I get the rest of my project onto Jersey 2.0.
>
> Thanks,
> Gili