You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by wkbutler <ke...@gmail.com> on 2009/03/10 21:52:38 UTC

Mapping FreeMarker results in struts-rest-plugin

Hi - 
Has anyone  had luck using .ftl templates with the struts2-rest-plugin?  I
see that .ftl is mapped by the struts-default.xml in struts-core, and
somehow Convention enables this mapping itself, although I don't quite get
how that happens.

The REST plugin resolves .jsp  (or is Convention doing that..?)  but I'm not
sure how, there is no explicit mapping for it in plugin-struts.xml, as there
are for its other supported extensions like xml and json.  I'd imagine that
a .ftl result should resolve in a similar way to a .jsp - some kind of
pass-through to struts-core - for me though, requests to *.ftl result in a
404 when using the rest plugin.

Anybody get this to work? 
Thanks - 
Kent
-- 
View this message in context: http://www.nabble.com/Mapping-FreeMarker-results-in-struts-rest-plugin-tp22443339p22443339.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Mapping FreeMarker results in struts-rest-plugin

Posted by wkbutler <ke...@gmail.com>.
Update - as it turns out, URL
   http://localhost:8080/lotmap/subdivision/id1

resolves to template 
   WEB-INF/content/subdivision-show.ftl

*if* and only if the correlating JSP template 
   WEB-INF/content/subdivision-show.jsp

does *not* exist.  

While that is not terribly surprising, this is:  when the project is checked
out of CVS and run on another server using the same JVM, we have a different
order of template preference; i.e. on my box, when

   WEB-INF/content/subdivision-show.ftl
   WEB-INF/content/subdivision-show.jsp

both exist, then the no-extension URL resolves to the JSP template.  On the
other server, the same no-extension URL resolves to the FTL template when
both exist.  



wkbutler wrote:
> 
> Thanks Bill -  my action class is actually called SubdivisionController. 
> Interesting you're getting responses for ftl requests. 
> 
> These URI's resolve for me:
>    http://localhost:8080/lotmap/subdivision/id1
>    http://localhost:8080/lotmap/subdivision/id1.xml
> 
> and these fail with a 404
>    http://localhost:8080/lotmap/subdivision/id1.jsp   (can't find local
> file - see below)
>    http://localhost:8080/lotmap/subdivision/id1.ftl    (nothing logged at
> all)
> 
> and these are what I think should be the relevant templates 
>    WEB-INF/content/subdivision-show.jsp
>    WEB-INF/content/subdivision-show.ftl
> 
> The URI with no extension is resolved via a forward from
> ServletDispatcherResult. It is the only one of this group that is handled
> this way though.  Of note, for the cases that succeed, the action method
> appears to be unknown in the ActionInvocation:
> 
> DEBUG [btpool0-2] RestWorkflowInterceptor.debug(57) | Skipping
> Interceptor... Method [show] found in exclude list.
> DEBUG [btpool0-2] RestActionInvocation.debug(57) | Executing action method
> = null
> 
> which I think means that a registered UnknownHandler should process this
> Result, based on the RestActionInvocation class's invokeAction() method.
> And the only UnknownHandler candidate I see is Convention's, and it seems
> to give up on unknown methods. So I don't think I found the right handler. 
> 
> It's a bit confusing that with no extension the result is processed, and
> with a .jsp extension, this error is logged:
> 
> 2009-03-11 07:11:51.703::WARN:  PWC6117: File
> "D:\projects\lotmap-restful-ep\src\main\webapp\subdivision\F11.jsp" not
> found
> 
> And for the .ftl extension there is nothing logged at all.
> 
> Musachy - thanks for the reminder, in haste I had blurred the distinction. 
> It appears that the Rest plugin's strategy for result handling defers to
> Convention or struts core definitions, but this appears to be working only
> for the rest-plugin's default extension "" (or "xhtml" to be more
> correct). 
> 
> The rest plugin does properly handle different ContentTypes based on
> extension via its Interceptor, which is much different than the Action
> mechanism's use of extension to map result type.  
> 
> I think my URL's above and their content templates are accurate. I have
> also tried some nonsensical templates (for a rest-plugin action) like
>    WEB-INF/content/subdivision-success.ftl
>    WEB-INF/content/subdivision.ftl
> 
> I wonder if something else is required to invoke the
> FreemarkerTemplateEngine for the ftl extension.  The rest plugin seems to
> squash this somehow.  What am I missing...?
> 
> 
> 
> 
> Bill Stilwell wrote:
>> 
>> I'm not sure if this applies, but I have found that with the rest
>> plugin and freemarker, I _have_ to have a Controller. It's not clear
>> to me from reading the docs if this is the intention with the rest
>> plugin, but that's how things are working for me.
>> 
>> -b
>> 
>> On Tue, Mar 10, 2009 at 1:56 PM, Musachy Barroso <mu...@gmail.com>
>> wrote:
>>> xml and json are the output types (the response sent to the client).
>>> JSP and FreeMarker are the result types, which are mapped by
>>> Convention. Check the Convention documentation for details on how the
>>> templates are found (same rules apply for jsp(s) and ftl(s))
>> 
>> 
>> -- 
>> Bill Stilwell - http://www.marginalia.org/
>> bill.stilwell@gmail.com
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Mapping-FreeMarker-results-in-struts-rest-plugin-tp22443339p22571229.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Mapping FreeMarker results in struts-rest-plugin

Posted by wkbutler <ke...@gmail.com>.
Thanks Bill -  my action class is actually called SubdivisionController. 
Interesting you're getting responses for ftl requests. 

These URI's resolve for me:
   http://localhost:8080/lotmap/subdivision/id1
   http://localhost:8080/lotmap/subdivision/id1.xml

and these fail with a 404
   http://localhost:8080/lotmap/subdivision/id1.jsp   (can't find local file
- see below)
   http://localhost:8080/lotmap/subdivision/id1.ftl    (nothing logged at
all)

and these are what I think should be the relevant templates 
   WEB-INF/content/subdivision-show.jsp
   WEB-INF/content/subdivision-show.ftl

The URI with no extension is resolved via a forward from
ServletDispatcherResult. It is the only one of this group that is handled
this way though.  Of note, for the cases that succeed, the action method
appears to be unknown in the ActionInvocation:

DEBUG [btpool0-2] RestWorkflowInterceptor.debug(57) | Skipping
Interceptor... Method [show] found in exclude list.
DEBUG [btpool0-2] RestActionInvocation.debug(57) | Executing action method =
null

which I think means that a registered UnknownHandler should process this
Result, based on the RestActionInvocation class's invokeAction() method. And
the only UnknownHandler candidate I see is Convention's, and it seems to
give up on unknown methods. So I don't think I found the right handler. 

It's a bit confusing that with no extension the result is processed, and
with a .jsp extension, this error is logged:

2009-03-11 07:11:51.703::WARN:  PWC6117: File
"D:\projects\lotmap-restful-ep\src\main\webapp\subdivision\F11.jsp" not
found

And for the .ftl extension there is nothing logged at all.

Musachy - thanks for the reminder, in haste I had blurred the distinction. 
It appears that the Rest plugin's strategy for result handling defers to
Convention or struts core definitions, but this appears to be working only
for the rest-plugin's default extension "" (or "xhtml" to be more correct). 

The rest plugin does properly handle different ContentTypes based on
extension via its Interceptor, which is much different than the Action
mechanism's use of extension to map result type.  

I think my URL's above and their content templates are accurate. I have also
tried some nonsensical templates (for a rest-plugin action) like
   WEB-INF/content/subdivision-success.ftl
   WEB-INF/content/subdivision.ftl

I wonder if something else is required to invoke the
FreemarkerTemplateEngine for the ftl extension.  The rest plugin seems to
squash this somehow.  What am I missing...?




Bill Stilwell wrote:
> 
> I'm not sure if this applies, but I have found that with the rest
> plugin and freemarker, I _have_ to have a Controller. It's not clear
> to me from reading the docs if this is the intention with the rest
> plugin, but that's how things are working for me.
> 
> -b
> 
> On Tue, Mar 10, 2009 at 1:56 PM, Musachy Barroso <mu...@gmail.com>
> wrote:
>> xml and json are the output types (the response sent to the client).
>> JSP and FreeMarker are the result types, which are mapped by
>> Convention. Check the Convention documentation for details on how the
>> templates are found (same rules apply for jsp(s) and ftl(s))
> 
> 
> -- 
> Bill Stilwell - http://www.marginalia.org/
> bill.stilwell@gmail.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Mapping-FreeMarker-results-in-struts-rest-plugin-tp22443339p22456790.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Mapping FreeMarker results in struts-rest-plugin

Posted by Bill Stilwell <bi...@gmail.com>.
I'm not sure if this applies, but I have found that with the rest
plugin and freemarker, I _have_ to have a Controller. It's not clear
to me from reading the docs if this is the intention with the rest
plugin, but that's how things are working for me.

-b

On Tue, Mar 10, 2009 at 1:56 PM, Musachy Barroso <mu...@gmail.com> wrote:
> xml and json are the output types (the response sent to the client).
> JSP and FreeMarker are the result types, which are mapped by
> Convention. Check the Convention documentation for details on how the
> templates are found (same rules apply for jsp(s) and ftl(s))


-- 
Bill Stilwell - http://www.marginalia.org/
bill.stilwell@gmail.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Mapping FreeMarker results in struts-rest-plugin

Posted by Musachy Barroso <mu...@gmail.com>.
xml and json are the output types (the response sent to the client).
JSP and FreeMarker are the result types, which are mapped by
Convention. Check the Convention documentation for details on how the
templates are found (same rules apply for jsp(s) and ftl(s))

musachy

On Tue, Mar 10, 2009 at 4:52 PM, wkbutler <ke...@gmail.com> wrote:
>
> Hi -
> Has anyone  had luck using .ftl templates with the struts2-rest-plugin?  I
> see that .ftl is mapped by the struts-default.xml in struts-core, and
> somehow Convention enables this mapping itself, although I don't quite get
> how that happens.
>
> The REST plugin resolves .jsp  (or is Convention doing that..?)  but I'm not
> sure how, there is no explicit mapping for it in plugin-struts.xml, as there
> are for its other supported extensions like xml and json.  I'd imagine that
> a .ftl result should resolve in a similar way to a .jsp - some kind of
> pass-through to struts-core - for me though, requests to *.ftl result in a
> 404 when using the rest plugin.
>
> Anybody get this to work?
> Thanks -
> Kent
> --
> View this message in context: http://www.nabble.com/Mapping-FreeMarker-results-in-struts-rest-plugin-tp22443339p22443339.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org