> What would be the best way to share an example? Send it here on the list?
>You can register an issue and add text and example there or send it here


Since this is my first contribution I'll post it here :).  I based my
example on
https://cwiki.apache.org/confluence/display/WW/RestfulActionMapper so it
makes sense for someone viewing the wiki
Furthermore, I tested it struts 2.3.1.2 and I also have a similar working
example in production.

To use the Restful2ActionMapper in an existing struts application we have
to change the strus.mapper.class constant
and let it point to the Restful2ActionMapper
 <constant
name="struts.mapper.class"
value="org.apache.struts2.dispatcher.mapper.Restful2ActionMapper"
/>
The problem with the above approach is that we may break existing actions
because the Restful2ActionMapper tries to guess
the method name using conventions that aren't applicable to normal action
classes.

To overcome the above problem, we have to use a different action mapper
depending on the url we want to process.
REST actions will be processed by the Restful2ActionMapper and non-REST
actions by the DefaultActionMapper

To achieve that we have to rely on nampespaces and the
PrefixBasedActionMapper that can choose which action mapper to
use for a particular url based on a prefix (the action namespace).

To put everything together, we create a package for our rest actions
<package name="rest" namespace="/rest" extends="struts-default">
    ....interceptor config
     <action name="movie/*" class="app.MovieAction">
    <param name="id">{0}</param>
        ....results
     </action>
    ....
</package>
All other actions remain in their existing packages and namespaces

we use the PrefixBasedActionMapper telling it to use the
Restful2ActionMapper for actions
in the /rest namespace and the DefaultActionMapper for all other actions

<constant
name="struts.mapper.class"
value="org.apache.struts2.dispatcher.mapper.PrefixBasedActionMapper"
/>
<constant name="struts.mapper.prefixMapping" value="/rest:restful2,:struts"
/>

For the Restful2ActionMapper to work we also have to set
<constant name="struts.enable.SlashesInActionNames" value="true" />
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false" />

@Chad
1) I think you are looking at the issue of failing to guess the method
using Rest conventions for non-REST actions
but in the context of the ActionMapper used in the REST plugin
I don't know if something similar can be applied to the
RestFul2ActionMapper, I just documented how we used
the Restful2ActionMapper
2) I've read your book, when I started working with struts2. Nice work
indeed !

Regards,
Antonios


>
>

Reply via email to