Hi, <div><br></div><div><p style="margin-right:0px;margin-bottom:15px;margin-left:0px;color:rgb(0,0,0);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:22px;margin-top:0px!important">I&#39;m working on <a href="https://issues.jboss.org/browse/AEROGEAR-693" style="color:rgb(65,131,196);text-decoration:initial">AEROGEAR-693</a> and trying to figure out how to implement this in the best way.</p>
<p style="margin:15px 0px;color:rgb(0,0,0);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:22px">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 <em>produces()</em> method on a route, this is what you&#39;ll get.</p>
<p style="margin:15px 0px;color:rgb(0,0,0);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:22px">Now, the media types that are passed to the <em>produces()</em> method determine two things: 1. How to match to Route that is the target of a request, matching the HTTP <em>Accept</em> header. 2. Determining the ViewResponder to be used.</p>
<p style="margin:15px 0px;color:rgb(0,0,0);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:22px">The issue here is that for both a HTMLResponder and a JSPResponder the media type would in both cases be<em>text/html</em>.<br>
How do we determine which one the users actually has created a view for (jsp or html page)?</p><p style="margin:15px 0px;color:rgb(0,0,0);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:22px">
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.</p><p style="margin:15px 0px;color:rgb(0,0,0);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:22px">
How about a introduce a type, MediaType that looks something like this:</p><div class="" style="border:none;padding:0px;color:rgb(0,0,0);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:22px">
<pre style="font-size:13px;line-height:19px;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;word-wrap:break-word;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(204,204,204);overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">
<span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">class</span> <span class="" style="color:rgb(68,85,136);font-weight:bold">MediaType</span> <span class="" style="font-weight:bold">{</span>

    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="" style="font-weight:bold">final</span> <span class="">String</span> <span class="">HTML</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(221,17,68)">&quot;text/html&quot;</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="" style="font-weight:bold">final</span> <span class="">String</span> <span class="">ANY</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(221,17,68)">&quot;*/*&quot;</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="" style="font-weight:bold">final</span> <span class="">String</span> <span class="">JSON</span> <span class="" style="font-weight:bold">=</span> <span class="" style="color:rgb(221,17,68)">&quot;application/json&quot;</span><span class="" style="font-weight:bold">;</span>

    <span class="" style="font-weight:bold">private</span> <span class="" style="font-weight:bold">final</span> <span class="">String</span> <span class="">mediaType</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">private</span> <span class="" style="font-weight:bold">final</span> <span class="">Class</span><span class="" style="font-weight:bold">&lt;?</span> <span class="" style="font-weight:bold">extends</span> <span class="">Responder</span><span class="" style="font-weight:bold">&gt;</span> <span class="">responderClass</span><span class="" style="font-weight:bold">;</span>

    <span class="" style="font-weight:bold">private</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">MediaType</span><span class="" style="font-weight:bold">(</span><span class="" style="font-weight:bold">final</span> <span class="">String</span> <span class="">mediaType</span><span class="" style="font-weight:bold">,</span> <span class="">Class</span><span class="" style="font-weight:bold">&lt;?</span> <span class="" style="font-weight:bold">extends</span> <span class="">Responder</span><span class="" style="font-weight:bold">&gt;</span> <span class="">responderClass</span><span class="" style="font-weight:bold">)</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">this</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">mediaType</span> <span class="" style="font-weight:bold">=</span> <span class="">mediaType</span><span class="" style="font-weight:bold">;</span>
        <span class="" style="font-weight:bold">this</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">responderClass</span> <span class="" style="font-weight:bold">=</span> <span class="">responderClass</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="" style="font-weight:bold">public</span> <span class="">String</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">getMediaType</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="">mediaType</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="" style="font-weight:bold">public</span> <span class="">Class</span><span class="" style="font-weight:bold">&lt;?</span> <span class="" style="font-weight:bold">extends</span> <span class="">Responder</span><span class="" style="font-weight:bold">&gt;</span> <span class="">getResponderClass</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="">responderClass</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="">@Override</span>
    <span class="" style="font-weight:bold">public</span> <span class="">String</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">toString</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="" style="color:rgb(221,17,68)">&quot;MediaType[type=&quot;</span> <span class="" style="font-weight:bold">+</span> <span class="">mediaType</span> <span class="" style="font-weight:bold">+</span> <span class="" style="color:rgb(221,17,68)">&quot;, responderClass=&quot;</span> <span class="" style="font-weight:bold">+</span> <span class="">responderClass</span> <span class="" style="font-weight:bold">+</span> <span class="" style="color:rgb(221,17,68)">&quot;]&quot;</span><span class="" style="font-weight:bold">;</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="">MediaType</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">html</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="" style="font-weight:bold">new</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">MediaType</span><span class="" style="font-weight:bold">(</span><span class="">HTML</span><span class="" style="font-weight:bold">,</span> <span class="">HtmlViewResponder</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">class</span><span class="" style="font-weight:bold">);</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="">MediaType</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">jsp</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="" style="font-weight:bold">new</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">MediaType</span><span class="" style="font-weight:bold">(</span><span class="">HTML</span><span class="" style="font-weight:bold">,</span> <span class="">JspViewResponder</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">class</span><span class="" style="font-weight:bold">);</span>
    <span class="" style="font-weight:bold">}</span>

    <span class="" style="font-weight:bold">public</span> <span class="" style="font-weight:bold">static</span> <span class="">MediaType</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">json</span><span class="" style="font-weight:bold">()</span> <span class="" style="font-weight:bold">{</span>
        <span class="" style="font-weight:bold">return</span> <span class="" style="font-weight:bold">new</span> <span class="" style="color:rgb(153,0,0);font-weight:bold">MediaType</span><span class="" style="font-weight:bold">(</span><span class="">JSON</span><span class="" style="font-weight:bold">,</span> <span class="">JsonResponder</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">class</span><span class="" style="font-weight:bold">);</span>
    <span class="" style="font-weight:bold">}</span>

<span class="" style="font-weight:bold">}</span>
</pre></div><p style="margin:15px 0px;color:rgb(0,0,0);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:22px">And we could add <em>html()</em>, <em>jsp()</em>, and <em>json()</em> methods to AbstractRoutingModule, so a route that should be handled by a HtmlViewResponder would look like this:</p>
<div class="" style="border:none;padding:0px;color:rgb(0,0,0);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:22px"><pre style="font-size:13px;line-height:19px;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;word-wrap:break-word;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(204,204,204);overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">
<span class="">route</span><span class="" style="font-weight:bold">()</span>
      <span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">from</span><span class="" style="font-weight:bold">(</span><span class="" style="color:rgb(221,17,68)">&quot;/plain&quot;</span><span class="" style="font-weight:bold">)</span>
      <span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">on</span><span class="" style="font-weight:bold">(</span><span class="">RequestMethod</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">GET</span><span class="" style="font-weight:bold">)</span>
      <span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">produces</span><span class="" style="font-weight:bold">(</span><span class="">html</span><span class="" style="font-weight:bold">())</span>
      <span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">to</span><span class="" style="font-weight:bold">(</span><span class="">Html</span><span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">class</span><span class="" style="font-weight:bold">).</span><span class="" style="color:rgb(0,128,128)">index</span><span class="" style="font-weight:bold">();</span>
</pre></div><p style="margin:15px 0px;color:rgb(0,0,0);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:22px">To be backward compatible, if a <em>produces()</em> method was not specified it would be the same as specifying:</p>
<div class="" style="border:none;padding:0px;color:rgb(0,0,0);font-family:Helvetica,arial,freesans,clean,sans-serif;font-size:14px;line-height:22px;margin-bottom:0px!important"><pre style="font-size:13px;line-height:19px;font-family:Consolas,&#39;Liberation Mono&#39;,Courier,monospace;word-wrap:break-word;margin-top:15px;margin-bottom:15px;background-color:rgb(248,248,248);border:1px solid rgb(204,204,204);overflow:auto;padding:6px 10px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px">
      <span class="" style="font-weight:bold">.</span><span class="" style="color:rgb(0,128,128)">produces</span><span class="" style="font-weight:bold">(</span><span class="">json</span><span class="" style="font-weight:bold">())</span></pre>
</div></div>