users@jersey.java.net

[Jersey] Re: JAXRS 2.0 Bean Validation error, how to return XML and not HTML

From: Noah White <emailnbw_at_gmail.com>
Date: Fri, 2 Aug 2013 12:14:39 -0400

If your request has an accept header which does not match a @Produces why would the resource ever match in the first place?

-Noah

On Aug 2, 2013, at 11:24 AM, Michal Gajdos <michal.gajdos_at_oracle.com> wrote:

> Hi Richard,
>
> do you use the 'Accept' header in your requests? The media type selection of response entity is driven by the 'Accept' header and not by the media type you annotate your resource method with (via @Produces annotation).
>
> Is HTML returned even if you explicitly say that you accept only "application/xml" media type? i.e.
>
> curl -v -H "Accept: application/xml" http://<host>/<app>/rest/order?amountCents=1
>
> Michal
>
> On 29.07.2013 14:17 , Richard Kolb wrote:
>> Hello
>>
>> I have a simple Restful webservice :
>> @GET
>> @Path("/order")
>> @Produces(MediaType.APPLICATION_XML)
>> public MyResult placeOrder(@Min(message="Min order is 10 cents", value=10) @QueryParam("amountCents") Integer amountCents) {}
>>
>> When I pass in less than 10 to amountCents, jersey gives back a error in HTML, but I would like it in XML.
>>
>> I also have an application that looks like :
>> @ApplicationPath("rest/*")
>> public class SnailApplication extends Application {
>> @Override
>> public Map<String, Object> getProperties() {
>> Map<String,Object> props = new HashMap<>();
>> props.put(ServerProperties.BV_SEND_ERROR_IN_RESPONSE, true);
>> return props;
>> }
>> }
>>
>> I have had a look here : https://jersey.java.net/documentation/latest/user-guide.html#bv.ValidationError
>> But I think I am missing something.
>>
>> Help please.
>>
>> thanks
>> Richard.
>>
>