You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by developer researcher <ja...@gmail.com> on 2012/02/09 22:57:56 UTC

REST in Struts 2 Web Applications

     Hello,

     I am using Struts2 2.3.1. I am evaluating the rest plugin and I have
the next requirements:

1. both normal action and restful action in the same web application.
2. The URL structure for resources must be:
- /list/ ==> show a list of resoruces in json format
- /list/{id} ==> show the resource identified by id

     I reviewed the information in
http://struts.apache.org/2.x/docs/rest-plugin.html but it does not seem to
fit my requirements.

     My doubts are:

1. Is possible implement my requirements with Struts2?
2. Where do I can found more information of rest plugin? any example or
tutorial?

Thanks and regards,

Re: REST in Struts 2 Web Applications

Posted by Łukasz Lenart <lu...@googlemail.com>.
It should be like this:

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


Regards
-- 
Łukasz
Mobile +48 606 323 122
Office +27 11 0838747
http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

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


Re: REST in Struts 2 Web Applications

Posted by developer researcher <ja...@gmail.com>.
     Hello,

     Seems that there is not much documentation, examples or tutorials on
this topic. The only resource I have found on a similar case is in the
following forum:
http://forum.springsource.org/showthread.php?83417-How-to-use-struts2-rest-style-and-default-style-at-same-time

     This seems a case for
org.apache.struts2.dispatcher.mapper.CompositeActionMapper but neither
there is much information about this class.

     An alternative solutions is use the Spring's support for REST for web
applications that used both frameworks.

     Does anyone have an example or tutorial for this case using only
struts2 and rest plugin?

Thanks and regards,

2012/2/10 developer researcher <ja...@gmail.com>

>      Hello Lukasz, thank you for your answer,
>
> *1.* I have severals problems when include the configuration for the
> rest-plugin in struts.xml (attachment the file):
>
> - Get HTTP for http://ipserver:port/weapp/index.action (for example)
> return HTTP 404 code error. Before include the rest plugin configuration
> the application worked fine.
>
> - The generated code for <s:a title="Link Index Action"
> action="index.action"> now is <a href="/webapp/index.action.xhtml"
> title="Link Index Action" />. Before include the rest plugin configuration
> the generated code was <a href="/webapp/index.action" title="Link Index
> Action" />. Why is added the suffix '.xhtml' to the URL of the actions?
> This result in the next Exception: *java.lang.NoSuchMethodException:
> com.opensymphony.xwork2.ActionSupport.index()*
>
> *2.* For the rest's methods (index, show, create, update, destry, edit
> and new) Do the REST Actions must extend from some class or implement some
> interface of the Struts2 API?
>
>      I hope you can help me understand and use the rest plugin since my
> application is based on struts2 and the ideal, in my case, would be that
> the rest requirements are implemented within the same application and
> because I not found much information about rest plugin.
>
> Thanks and regards,
>
>
> 2012/2/10 Łukasz Lenart <lu...@googlemail.com>
>
>> 2012/2/9 developer researcher <ja...@gmail.com>:
>> > 1. both normal action and restful action in the same web application.
>>
>> Define struts.rest.namespace as mentioned in the docs
>>
>> > 2. The URL structure for resources must be:
>> > - /list/ ==> show a list of resoruces in json format
>> > - /list/{id} ==> show the resource identified by id
>>
>> /list/ => implement ListAction.index
>> /list/{id} => implement ListAction.show
>>
>>
>> Regards
>> --
>> Łukasz
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>

Re: REST in Struts 2 Web Applications

Posted by developer researcher <ja...@gmail.com>.
     Hello Lukasz, thank you for your answer,

*1.* I have severals problems when include the configuration for the
rest-plugin in struts.xml (attachment the file):

- Get HTTP for http://ipserver:port/weapp/index.action (for example) return
HTTP 404 code error. Before include the rest plugin configuration the
application worked fine.

- The generated code for <s:a title="Link Index Action"
action="index.action"> now is <a href="/webapp/index.action.xhtml"
title="Link Index Action" />. Before include the rest plugin configuration
the generated code was <a href="/webapp/index.action" title="Link Index
Action" />. Why is added the suffix '.xhtml' to the URL of the actions?
This result in the next Exception: *java.lang.NoSuchMethodException:
com.opensymphony.xwork2.ActionSupport.index()*

*2.* For the rest's methods (index, show, create, update, destry, edit and
new) Do the REST Actions must extend from some class or implement some
interface of the Struts2 API?

     I hope you can help me understand and use the rest plugin since my
application is based on struts2 and the ideal, in my case, would be that
the rest requirements are implemented within the same application and
because I not found much information about rest plugin.

Thanks and regards,

2012/2/10 Łukasz Lenart <lu...@googlemail.com>

> 2012/2/9 developer researcher <ja...@gmail.com>:
> > 1. both normal action and restful action in the same web application.
>
> Define struts.rest.namespace as mentioned in the docs
>
> > 2. The URL structure for resources must be:
> > - /list/ ==> show a list of resoruces in json format
> > - /list/{id} ==> show the resource identified by id
>
> /list/ => implement ListAction.index
> /list/{id} => implement ListAction.show
>
>
> Regards
> --
> Łukasz
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: REST in Struts 2 Web Applications

Posted by Łukasz Lenart <lu...@googlemail.com>.
2012/2/9 developer researcher <ja...@gmail.com>:
> 1. both normal action and restful action in the same web application.

Define struts.rest.namespace as mentioned in the docs

> 2. The URL structure for resources must be:
> - /list/ ==> show a list of resoruces in json format
> - /list/{id} ==> show the resource identified by id

/list/ => implement ListAction.index
/list/{id} => implement ListAction.show


Regards
-- 
Łukasz

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