[aerogear-dev] [aerogear-controller] Error Route responses

Matthias Wessendorf matzew at apache.org
Thu Jan 3 02:35:53 EST 2013


Nice!

On Thu, Jan 3, 2013 at 8:20 AM, Daniel Bevenius
<daniel.bevenius at gmail.com> wrote:
> JSON Responses for Error Routes
>
> We recently added support for routes to be able to produce responses, other
> than original MVC forwarding to a view. This addition meant that a route
> could specify the media types it produces, and a client could specify the
> desired media types using the HTTP Accept header, and get back a response
> body with that type.
> But this only worked for normal routes and not for error routes which is
> what AEROGEAR-515 has added.
>
> You can now specify that your error routes produce different types:
>
> route()
>       .on(Exception.class)
>       .produces("text/html", "application/json")
>       .to(Error.class).index(param(Exception.class));
>
> route()
>       .from("/throwException")
>       .on(RequestMethod.GET)
>       .produces("text/html", "application/json")
>       .to(Error.class).throwException();
>
> This would enable you to produce a html response by accessing throwException
> in aerogear-controller-demo.
>
> You can also specify that you want the response as application/json and
> calling the same route as above:
>
> curl -i -H "Accept: application/json" -X GET
> "http://localhost:8080/aerogear-controller-demo/throwException"
>
> GET Exception application/json:
> HTTP/1.1 200 OK
> Server: Apache-Coyote/1.1
> Content-Type: application/json;charset=UTF-8
> Content-Length: 28
> Date: Thu, 03 Jan 2013 06:52:56 GMT
>
> "{exception:Demo Exception}"
>
>
> _______________________________________________
> aerogear-dev mailing list
> aerogear-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/aerogear-dev
>



-- 
Matthias Wessendorf

blog: http://matthiaswessendorf.wordpress.com/
sessions: http://www.slideshare.net/mwessendorf
twitter: http://twitter.com/mwessendorf


More information about the aerogear-dev mailing list