Hi Rice On Thu, Jun 2, 2011 at 10:55 AM, Rice Yeh <[email protected]> wrote: > I have a feeling that the spec of JAX-RS is kind of weak on exception > handling. It regulates a lot of tags for matching a method to handle a > request based on path, consume, provide, ... But once an exception happen, > all these mechanism are gone. I have to judge what kind of content to return > in the method toResonse(Throwable...) based on very little information > available. >
You can get @HttpHeaders injected and get the properly sorted list of acceptable media types, thus if you have a single method with @Produces having multiple values then you can use the first *known* value in the list of acceptable media types is the one which is expected by the client. Ex, if you know that @Produces has html/xml/json and you get a sorted list starting with json then it's json. If the lists starts from the type not available on @Produces then you need to skip it. Cheers, Sergey > Rice > > On Thu, Jun 2, 2011 at 5:32 PM, Rice Yeh <[email protected]> wrote: > >> Hi, >> I write a ExceptionMapper to handle exception. In the ExceptionMapper, I >> have a need to know the matched response type to return different response. >> For example, if the the matched response type is html, it returns a html >> response and if the matched response is json, it returns json. How do I do >> this? >> >> Regards, >> Rice >> > -- Sergey Beryozkin Application Integration Division of Talend http://sberyozkin.blogspot.com
