users@jersey.java.net

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

From: cowwoc <cowwoc_at_bbs.darktech.org>
Date: Fri, 08 Nov 2013 11:53:36 -0500

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?

> 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
> <http://jcp.org/en/jsr/detail?id=311#2>, 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.

 1. The definition of "ugly" is subjective.
 2. 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
>>>> o Used to insert a new element into a collection (there is no
>>>> confusion about the kind of child resource being created).
>>>> o 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)
>> <https://jersey.java.net/apidocs/snapshot/jersey/javax/ws/rs/client/Entity.html#entity%28T,%20javax.ws.rs.core.MediaType%29>
>> 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