Hi Noah,
you can have a resource as described below and the 'Accept' header in
your request like:
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Then the resource would match as expected but if the Bean Validation
runtime throws an exception then text/html would be chosen as a media
type of the response by our ExceptionMapper.
Maybe we could improve the media type selection for a response in such
cases. I'll take a look at it.
Michal
On 02.08.2013 18:14 , Noah White wrote:
> 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.
>>>