jsr339-experts@jax-rs-spec.java.net

[jsr339-experts] Re: [jax-rs-spec users] Re: Re: forward()

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Tue, 5 Nov 2013 20:20:59 +0100

On 31 Oct 2013, at 18:00, Sergey Beryozkin <sberyozkin_at_talend.com> wrote:

> On 30/10/13 16:23, Marek Potociar wrote:
>> On 30 Oct 2013, at 15:30, Sergey Beryozkin <sberyozkin_at_talend.com
>> <mailto:sberyozkin_at_talend.com>> wrote:
>>
>>> Sure, you have some good support there, but it kind of forces the
>>> users to choose between an explicit MVC style vs JAX-RS style,
>>> example, you can't have a Book returned with Produces set to text/xml
>>> & text/html.
>>
>> You just need to provide 2 separate methods right now. Not a big deal
>> IMO really
>> <https://github.com/jersey/jersey/blob/master/examples/flight-mgmt-webapp/src/main/java/org/glassfish/jersey/examples/flight/resources/FlightsResource.java>.
>> We can of course try to think more about this and see if we can come up
>> with a solution that would not require the extra resource methods.
>> (Still, not a big deal IMO.)
>
> Yes, agreed
>
>>
>>> May be I'm wrong though. But I'd prefer for users to have an option to
>>> have the data to HTML binding done under the hood - I guess though we
>>> may not need to do anything at all for the latter, it works right now
>>> for us via a basic MBW
>>
>> Our approach also works via MBW (good thing as it does not bypasses the
>> response filters an exception mappers), but is much, much more
>> convenient. You can also choose whether you want something more dynamic
>> and use programmatic Viewable approach, or if you are ok with a static,
>> declarative approach of @Template annotation.
>>
> So, given that Jersey also relies on MBW in to finish off processing a response, would it be fair to say that what Viewable & Template add is basically an ability to configure the view target in the application code, right ?

Yes.

> This is of course possible to do in MBW itself, but I can see where one may want to rely on some conventions and do the application code level control...

Jersey does support conventions based on resource package/class name etc. We also support implicit templates where the whole resource instance serves as a model:
https://jersey.java.net/documentation/latest/mvc.html#d0e11473
Note that in the example the resource does not have ANY explicitly defined resource methods.

Marek

>
> Sergey
>
>> Marek
>>
>>>
>>> Sergey
>>>
>>> On 30/10/13 14:12, Sergey Beryozkin wrote:
>>>> On 30/10/13 14:03, Marek Potociar wrote:
>>>>> FYI, in Jersey we have this:
>>>>> https://jersey.java.net/documentation/latest/mvc.html
>>>>>
>>>>> This is a more generic approach IMO than a forward() method, which is
>>>>> IMO too Servlet-specific.
>>>>
>>>> No, this is a very intrusive approach, not JAX-RS.
>>>> I've never liked asking users to do something like:
>>>>
>>>> return new Viewable("/index", "FOO");
>>>>
>>>> etc
>>>>
>>>> Sergey
>>>>
>>>>>
>>>>> Marek
>>>>>
>>>>> On 11 Sep 2013, at 20:03, Bill Burke <bburke_at_redhat.com
>>>>> <mailto:bburke_at_redhat.com>
>>>>> <mailto:bburke_at_redhat.com>> wrote:
>>>>>
>>>>>>
>>>>>>
>>>>>> On 9/11/2013 11:19 AM, Sergey Beryozkin wrote:
>>>>>>> On 11/09/13 14:04, Bill Burke wrote:
>>>>>>>> Hey,
>>>>>>>>
>>>>>>>> I'm working on my first Angular JS web UI application. Angular JS is
>>>>>>>> REST based, so it works great with a JAX-RS backend. The only thing
>>>>>>>> that is really missing in JAX-RS at the moment, is a servlet
>>>>>>>> forward().
>>>>>>>> I often need to forward the request to .html, .jsp, or JSF pages
>>>>>>>> within the WAR.
>>>>>>>>
>>>>>>>> A could inject HttpServletRequest and do the forward, but the JAX-RS
>>>>>>>> implementation is going to have to be aware that you're doing a
>>>>>>>> forward,
>>>>>>>> otherwise, it will try to send back a response.
>>>>>>>>
>>>>>>>> Do we need a forward() method somewhere? LIke on ResourceContext or
>>>>>>>> something? Or do we need explicit language in the spec that JAX-RS
>>>>>>>> implementations need to handle servlet forwards gracefully.
>>>>>>>>
>>>>>>> We do it at MBW level and ensure the runtime does not try to
>>>>>>> handle the
>>>>>>> response after the forward, basic and non-intrusive solution,
>>>>>>
>>>>>> We have an API for forward(). Which bypasses response processing if
>>>>>> you call it on a JAX-RS method return. Which means no exception
>>>>>> handling, filters, or interceptors or MBW.
>>>>>>
>>>>>> --
>>>>>> Bill Burke
>>>>>> JBoss, a division of Red Hat
>>>>>> http://bill.burkecentral.com
>>>>>
>>>>
>>>
>>>
>>> --
>>> Sergey Beryozkin
>>>
>>> Talend Community Coders
>>> http://coders.talend.com/
>>>
>>> Blog: http://sberyozkin.blogspot.com
>>
>