You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by Cameron Dalton <Ca...@eim-usa.com> on 2012/03/09 03:57:32 UTC

Wink - MediaType incorrect (text/html) after exceptions

Hello,

After an ExceptionMapper runs, the MediaType seems to incorrectly be considered "text/html" instead of the "application/json" declared in the resource method's @Produces annotation.

The resource method has @Produces(MediaType.APPLICATION_JSON), and the client is successfully getting a JSON response after the "happy path".

However, when the resource method throws an Exception and the ExceptionMapper runs, the subsequent RequestHandler chain sees the MediaType as "text/html" instead of "application/json".  This would be annoying in and of itself since the client would get an unexpected content type, however this is actually causing an IOException because Wink delegates the "text/html" responses to the class com.sun.mail.handlers.text_plain (???) which blows up with any entity type other than String.

Why is this MediaType coming back as "text/html" after an ExceptionMapper runs, when both the client and the resource have agreed on "application/json"?  What can I do to correct or alter this behavior?

Thanks for any insight you can provide!

Cameron


Re: Wink - MediaType incorrect (text/html) after exceptions

Posted by Gino Bustelo <lb...@gmail.com>.
There is actually a way. I was able to accomplish what you need by returning an @asset object from the ExceptionMapper and then having handler methods for each media type in the asset class. Now, if I remember correctly, there seems to be a problem with the JacksonProvider that does not handle Asset classes correctly and rather than letting Wink invoke them, it tries to serialize the asset class. I ended up overriding the JacksonProvider in order to check if the object had the @Asset annotation and skip it.

On Mar 8, 2012, at 9:40 PM, Raymond Feng wrote:

> My understanding is that the exception mapper is responsible to decide what  content type it produces. The exception mapper doesn't even know the resource method where the exception is thrown unless the exception itself carries the desired media type.
> 
> Sent from my iPad
> 
> On Mar 8, 2012, at 6:57 PM, Cameron Dalton <Ca...@eim-usa.com> wrote:
> 
>> Hello,
>>  
>> After an ExceptionMapper runs, the MediaType seems to incorrectly be considered “text/html” instead of the “application/json” declared in the resource method’s @Produces annotation.
>>  
>> The resource method has @Produces(MediaType.APPLICATION_JSON), and the client is successfully getting a JSON response after the “happy path”.
>>  
>> However, when the resource method throws an Exception and the ExceptionMapper runs, the subsequent RequestHandler chain sees the MediaType as “text/html” instead of “application/json”.  This would be annoying in and of itself since the client would get an unexpected content type, however this is actually causing an IOException because Wink delegates the “text/html” responses to the class com.sun.mail.handlers.text_plain (???) which blows up with any entity type other than String.
>>  
>> Why is this MediaType coming back as “text/html” after an ExceptionMapper runs, when both the client and the resource have agreed on “application/json”?  What can I do to correct or alter this behavior?
>>  
>> Thanks for any insight you can provide!
>>  
>> Cameron
>>  


Re: Wink - MediaType incorrect (text/html) after exceptions

Posted by Raymond Feng <en...@gmail.com>.
My understanding is that the exception mapper is responsible to decide what  content type it produces. The exception mapper doesn't even know the resource method where the exception is thrown unless the exception itself carries the desired media type.

Sent from my iPad

On Mar 8, 2012, at 6:57 PM, Cameron Dalton <Ca...@eim-usa.com> wrote:

> Hello,
>  
> After an ExceptionMapper runs, the MediaType seems to incorrectly be considered “text/html” instead of the “application/json” declared in the resource method’s @Produces annotation.
>  
> The resource method has @Produces(MediaType.APPLICATION_JSON), and the client is successfully getting a JSON response after the “happy path”.
>  
> However, when the resource method throws an Exception and the ExceptionMapper runs, the subsequent RequestHandler chain sees the MediaType as “text/html” instead of “application/json”.  This would be annoying in and of itself since the client would get an unexpected content type, however this is actually causing an IOException because Wink delegates the “text/html” responses to the class com.sun.mail.handlers.text_plain (???) which blows up with any entity type other than String.
>  
> Why is this MediaType coming back as “text/html” after an ExceptionMapper runs, when both the client and the resource have agreed on “application/json”?  What can I do to correct or alter this behavior?
>  
> Thanks for any insight you can provide!
>  
> Cameron
>