Thanks guys!
+1On Fri, Dec 21, 2012 at 3:39 PM, Lucas Holmquist <lholmqui@redhat.com> wrote:
+1From a user perspective, i think the route sections looks clean with this approachOn Dec 21, 2012, at 9:34 AM, Daniel Bevenius <daniel.bevenius@gmail.com> wrote:_______________________________________________Hi,I'm working on AEROGEAR-693 and trying to figure out how to implement this in the best way.
At the moment, the default type of ViewResponder is the MvcResponder which forwards to a JSP page. By default, this means that if you do not specify a produces() method on a route, this is what you'll get.
Now, the media types that are passed to the produces() method determine two things: 1. How to match to Route that is the target of a request, matching the HTTP Accept header. 2. Determining the ViewResponder to be used.
The issue here is that for both a HTMLResponder and a JSPResponder the media type would in both cases betext/html.
How do we determine which one the users actually has created a view for (jsp or html page)?Well, we need some way to differantiate between a route that will respond with a html view, but which uses a ceratain technique to render the html.
How about a introduce a type, MediaType that looks something like this:
public class MediaType { public static final String HTML = "text/html"; public static final String ANY = "*/*"; public static final String JSON = "application/json"; private final String mediaType; private final Class<? extends Responder> responderClass; private MediaType(final String mediaType, Class<? extends Responder> responderClass) { this.mediaType = mediaType; this.responderClass = responderClass; } public String getMediaType() { return mediaType; } public Class<? extends Responder> getResponderClass() { return responderClass; } @Override public String toString() { return "MediaType[type=" + mediaType + ", responderClass=" + responderClass + "]"; } public static MediaType html() { return new MediaType(HTML, HtmlViewResponder.class); } public static MediaType jsp() { return new MediaType(HTML, JspViewResponder.class); } public static MediaType json() { return new MediaType(JSON, JsonResponder.class); } }And we could add html(), jsp(), and json() methods to AbstractRoutingModule, so a route that should be handled by a HtmlViewResponder would look like this:
route() .from("/plain") .on(RequestMethod.GET) .produces(html()) .to(Html.class).index();To be backward compatible, if a produces() method was not specified it would be the same as specifying:
.produces(json())
aerogear-dev mailing list
aerogear-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/aerogear-dev
_______________________________________________
aerogear-dev mailing list
aerogear-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/aerogear-dev
_______________________________________________
aerogear-dev mailing list
aerogear-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/aerogear-dev