You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by xnpeng <xn...@163.com> on 2009/05/20 04:04:58 UTC

Struts2+ReST-plugin prolems need help!!!

I'm doing my project with struts2+rest-plugin for about 3 months.there is a lot of problems unresolved.
 
With rest-plugin and convention-plugin,all action-mapping are done automatically,manual action-mapping in struts.xml cannot work.so,
1, I cannot define global-error-result;
2, I cannot do forward;
3, I cannot insert my own Interceptors.

I 'm watching this mail-list day and day, there is not much discuss on rest-plugin, neithere is enough materials on the internet. Does someone have much experience on this topic? I need your help ergently!
 

 

Re:RE: Struts2+ReST-plugin prolems need help!!!

Posted by xnpeng <xn...@163.com>.
Hi Martin,
   don't know howto do it. can you please give me some detailed materials?



在2009-05-20,"Martin Gainty" <mg...@hotmail.com> 写道:
>
>let the StrutsDispatcher handle the navigation details
>you'll have to fill in any necessary java classes as well as input/output jsps 
>but the basic structure is outlined in struts.xml illustrated below
>
>Martin Gainty 
>______________________________________________ 
>Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
> 
>Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
>Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.
>
>
>
>
>> Date: Wed, 20 May 2009 18:36:57 +0800
>> From: xnpeng@163.com
>> To: user@struts.apache.org
>> Subject: Re:Re: Struts2+ReST-plugin prolems need help!!!
>> 
>> 
>> Hi Dave!
>>    I'm using Struts2.1.6 and struts2-rest-plugin-2.1.6.
>> 
>> first ,I need a global error page when exception happen like this:
>> 
>> Stacktraces
>> java.lang.NoSuchMethodException: com.xunan.sitexa.rest.MainController.a() 
>>     java.lang.Class.getMethod(Unknown Source)
>>     org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:75)
>>     org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:47)
>>     com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
>>     com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
>>     com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
>>     com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
>>     org.apache.struts2.rest.ContentTypeInterceptor.intercept(ContentTypeInterceptor.java:67)
>>     com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
>> 
>> and second,I want to forward request to  action like the follow:
>> if(type=='1'){
>>     request.forward("action1);
>> }else if(type=='2'){
>>     request.forward("action1);
>> }
>
>struts.xml
><package name="default" extends="struts-default" namespace="/">
>     <interceptors>
><interceptor name="tokenSession" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>
>      <interceptor name="authentication"  class="com.xunan.framework.web.interceptor.SimpleInterceptor"/>     
>
><!--define which interceptors you need for default behaviour inside here -->
>       <interceptor-stack name="defaultStack">
>       </interceptor=stack>
><!-- define which interceptors you need for suser-submit inside here -->
>    <interceptor-stack name="user-submit">
>
>     <interceptor-ref name="tokenSession"/>
>    
><interceptor-ref name="user"/>
>   
></interceptor-stack>
>    <interceptor-stack name="user">
>      <interceptor-ref name="authentication"/>
>      <interceptor-ref name="defaultStack"/>
>    </interceptor-stack>
>
>   <interceptor-stack name="guest">
>  </interceptors>
><!--default to user interceptor stack of user-->
>  <default-interceptor-ref name="user"/>
>
> <global-results>
><!--freemarker uses .ftl filename jsp uses jsp -->
> <result name="error" type="jsp">/error.jsp</result>
> </global-results>
>
> <global-exception-mappings>
>     <exception-mapping exception="java.lang.Exception" result="error">
>    </exception-mapping>
> </global-exception-mappings>
>
>    <action name="login" class="chatLoginAction">
>      <interceptor-ref name="defaultStack" />
>       <result type="redirect">/action${ClassName.type}.action</result>
>      <result name="input">/index.jsp</result>
>    </action>
>   <action name="action1">
>      <interceptor-ref name="defaultStack" />
>       <result name="success">action1_success.jsp</result>
>       <result name="error">action1_error.jsp</result>
>    </action>
>   <action name="action2">
>
>      <interceptor-ref name="defaultStack" />
>
>      <result name="success">action2_success.jsp</result>
>      <result name="error">action2_error.jsp</result>
>
>    </action>
></package>
>
>> third, a SimpleInterceptor doing login check,
>>  <package name="default" namespace="/" extends="struts-default">
>>         <interceptors>
>>             <interceptor name="authentication"  class="com.xunan.framework.web.interceptor.SimpleInterceptor"/>
>>             <interceptor-stack name="user">
>>                 <interceptor-ref name="authentication"/>
>>                 <interceptor-ref name="defaultStack"/>
>>             </interceptor-stack>
>>             <interceptor-stack name="user-submit">
>>                 <interceptor-ref name="tokenSession"/>
>>                 <interceptor-ref name="user"/>
>>             </interceptor-stack>
>>             <interceptor-stack name="guest">
>>                 <interceptor-ref name="defaultStack"/>
>>             </interceptor-stack>
>>         </interceptors>
>>         <default-interceptor-ref name="user"/>
>>         <global-results>
>>             <result name="error" type="freemarker">/error.jsp</result>
>>         </global-results>
>>         <global-exception-mappings>
>>             <exception-mapping exception="java.lang.Exception" result="error">
>>             </exception-mapping>
>>         </global-exception-mappings>
>>     </package>
>> 
>> thank you very much.
>> 
>> 
>> 在2009-05-20,"Dave Newton" <ne...@yahoo.com> 写道:
>> >xnpeng wrote:
>> >> I'm doing my project with struts2+rest-plugin for about 3 months.there is a lot of problems unresolved.
>> >>  
>> >> With rest-plugin and convention-plugin,all action-mapping are done automatically,manual action-mapping in struts.xml cannot work.so,
>> >> 1, I cannot define global-error-result;
>> >> 2, I cannot do forward;
>> >> 3, I cannot insert my own Interceptors.
>> >> 
>> >> I 'm watching this mail-list day and day, there is not much discuss on rest-plugin, neithere is enough materials on the internet. Does someone have much experience on this topic? I need your help ergently!
>> >>  
>> >> 
>> >>  
>> >
>> >It's definitely possible to combine REST and XML mappings.
>> >
>> >You might have better luck telling us what specific issues you're 
>> >having, along with what version of S2 you're using.
>> >
>> >Dave
>> >
>> >---------------------------------------------------------------------
>> >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> >For additional commands, e-mail: user-help@struts.apache.org
>> >
>
>_________________________________________________________________
>Hotmail® goes with you. 
>http://windowslive.com/Tutorial/Hotmail/Mobile?ocid=TXT_TAGLM_WL_HM_Tutorial_Mobile1_052009

RE: Struts2+ReST-plugin prolems need help!!!

Posted by Martin Gainty <mg...@hotmail.com>.
let the StrutsDispatcher handle the navigation details
you'll have to fill in any necessary java classes as well as input/output jsps 
but the basic structure is outlined in struts.xml illustrated below

Martin Gainty 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.




> Date: Wed, 20 May 2009 18:36:57 +0800
> From: xnpeng@163.com
> To: user@struts.apache.org
> Subject: Re:Re: Struts2+ReST-plugin prolems need help!!!
> 
> 
> Hi Dave!
>    I'm using Struts2.1.6 and struts2-rest-plugin-2.1.6.
> 
> first ,I need a global error page when exception happen like this:
> 
> Stacktraces
> java.lang.NoSuchMethodException: com.xunan.sitexa.rest.MainController.a() 
>     java.lang.Class.getMethod(Unknown Source)
>     org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:75)
>     org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:47)
>     com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
>     com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
>     com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
>     com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
>     org.apache.struts2.rest.ContentTypeInterceptor.intercept(ContentTypeInterceptor.java:67)
>     com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
> 
> and second,I want to forward request to  action like the follow:
> if(type=='1'){
>     request.forward("action1);
> }else if(type=='2'){
>     request.forward("action1);
> }

struts.xml
<package name="default" extends="struts-default" namespace="/">
     <interceptors>
<interceptor name="tokenSession" class="org.apache.struts2.interceptor.TokenSessionStoreInterceptor"/>
      <interceptor name="authentication"  class="com.xunan.framework.web.interceptor.SimpleInterceptor"/>     

<!--define which interceptors you need for default behaviour inside here -->
       <interceptor-stack name="defaultStack">
       </interceptor=stack>
<!-- define which interceptors you need for suser-submit inside here -->
    <interceptor-stack name="user-submit">

     <interceptor-ref name="tokenSession"/>
    
<interceptor-ref name="user"/>
   
</interceptor-stack>
    <interceptor-stack name="user">
      <interceptor-ref name="authentication"/>
      <interceptor-ref name="defaultStack"/>
    </interceptor-stack>

   <interceptor-stack name="guest">
  </interceptors>
<!--default to user interceptor stack of user-->
  <default-interceptor-ref name="user"/>

 <global-results>
<!--freemarker uses .ftl filename jsp uses jsp -->
 <result name="error" type="jsp">/error.jsp</result>
 </global-results>

 <global-exception-mappings>
     <exception-mapping exception="java.lang.Exception" result="error">
    </exception-mapping>
 </global-exception-mappings>

    <action name="login" class="chatLoginAction">
      <interceptor-ref name="defaultStack" />
       <result type="redirect">/action${ClassName.type}.action</result>
      <result name="input">/index.jsp</result>
    </action>
   <action name="action1">
      <interceptor-ref name="defaultStack" />
       <result name="success">action1_success.jsp</result>
       <result name="error">action1_error.jsp</result>
    </action>
   <action name="action2">

      <interceptor-ref name="defaultStack" />

      <result name="success">action2_success.jsp</result>
      <result name="error">action2_error.jsp</result>

    </action>
</package>

> third, a SimpleInterceptor doing login check,
>  <package name="default" namespace="/" extends="struts-default">
>         <interceptors>
>             <interceptor name="authentication"  class="com.xunan.framework.web.interceptor.SimpleInterceptor"/>
>             <interceptor-stack name="user">
>                 <interceptor-ref name="authentication"/>
>                 <interceptor-ref name="defaultStack"/>
>             </interceptor-stack>
>             <interceptor-stack name="user-submit">
>                 <interceptor-ref name="tokenSession"/>
>                 <interceptor-ref name="user"/>
>             </interceptor-stack>
>             <interceptor-stack name="guest">
>                 <interceptor-ref name="defaultStack"/>
>             </interceptor-stack>
>         </interceptors>
>         <default-interceptor-ref name="user"/>
>         <global-results>
>             <result name="error" type="freemarker">/error.jsp</result>
>         </global-results>
>         <global-exception-mappings>
>             <exception-mapping exception="java.lang.Exception" result="error">
>             </exception-mapping>
>         </global-exception-mappings>
>     </package>
> 
> thank you very much.
> 
> 
> 在2009-05-20,"Dave Newton" <ne...@yahoo.com> 写道:
> >xnpeng wrote:
> >> I'm doing my project with struts2+rest-plugin for about 3 months.there is a lot of problems unresolved.
> >>  
> >> With rest-plugin and convention-plugin,all action-mapping are done automatically,manual action-mapping in struts.xml cannot work.so,
> >> 1, I cannot define global-error-result;
> >> 2, I cannot do forward;
> >> 3, I cannot insert my own Interceptors.
> >> 
> >> I 'm watching this mail-list day and day, there is not much discuss on rest-plugin, neithere is enough materials on the internet. Does someone have much experience on this topic? I need your help ergently!
> >>  
> >> 
> >>  
> >
> >It's definitely possible to combine REST and XML mappings.
> >
> >You might have better luck telling us what specific issues you're 
> >having, along with what version of S2 you're using.
> >
> >Dave
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >For additional commands, e-mail: user-help@struts.apache.org
> >

_________________________________________________________________
Hotmail® goes with you. 
http://windowslive.com/Tutorial/Hotmail/Mobile?ocid=TXT_TAGLM_WL_HM_Tutorial_Mobile1_052009

Re:Re: Struts2+ReST-plugin prolems need help!!!

Posted by xnpeng <xn...@163.com>.
Hi Dave!
   I'm using Struts2.1.6 and struts2-rest-plugin-2.1.6.

first ,I need a global error page when exception happen like this:

Stacktraces
java.lang.NoSuchMethodException: com.xunan.sitexa.rest.MainController.a() 
    java.lang.Class.getMethod(Unknown Source)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.getActionMethod(AnnotationValidationInterceptor.java:75)
    org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:47)
    com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)
    org.apache.struts2.rest.ContentTypeInterceptor.intercept(ContentTypeInterceptor.java:67)
    com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236)

and second,I want to forward request to  action like the follow:
if(type=='1'){
    request.forward("action1);
}else if(type=='2'){
    request.forward("action1);
}

third, a SimpleInterceptor doing login check,
 <package name="default" namespace="/" extends="struts-default">
        <interceptors>
            <interceptor name="authentication"  class="com.xunan.framework.web.interceptor.SimpleInterceptor"/>
            <interceptor-stack name="user">
                <interceptor-ref name="authentication"/>
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>
            <interceptor-stack name="user-submit">
                <interceptor-ref name="tokenSession"/>
                <interceptor-ref name="user"/>
            </interceptor-stack>
            <interceptor-stack name="guest">
                <interceptor-ref name="defaultStack"/>
            </interceptor-stack>
        </interceptors>
        <default-interceptor-ref name="user"/>
        <global-results>
            <result name="error" type="freemarker">/error.jsp</result>
        </global-results>
        <global-exception-mappings>
            <exception-mapping exception="java.lang.Exception" result="error">
            </exception-mapping>
        </global-exception-mappings>
    </package>

thank you very much.


在2009-05-20,"Dave Newton" <ne...@yahoo.com> 写道:
>xnpeng wrote:
>> I'm doing my project with struts2+rest-plugin for about 3 months.there is a lot of problems unresolved.
>>  
>> With rest-plugin and convention-plugin,all action-mapping are done automatically,manual action-mapping in struts.xml cannot work.so,
>> 1, I cannot define global-error-result;
>> 2, I cannot do forward;
>> 3, I cannot insert my own Interceptors.
>> 
>> I 'm watching this mail-list day and day, there is not much discuss on rest-plugin, neithere is enough materials on the internet. Does someone have much experience on this topic? I need your help ergently!
>>  
>> 
>>  
>
>It's definitely possible to combine REST and XML mappings.
>
>You might have better luck telling us what specific issues you're 
>having, along with what version of S2 you're using.
>
>Dave
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>

Re: Struts2+ReST-plugin prolems need help!!!

Posted by Dave Newton <ne...@yahoo.com>.
xnpeng wrote:
> I'm doing my project with struts2+rest-plugin for about 3 months.there is a lot of problems unresolved.
>  
> With rest-plugin and convention-plugin,all action-mapping are done automatically,manual action-mapping in struts.xml cannot work.so,
> 1, I cannot define global-error-result;
> 2, I cannot do forward;
> 3, I cannot insert my own Interceptors.
> 
> I 'm watching this mail-list day and day, there is not much discuss on rest-plugin, neithere is enough materials on the internet. Does someone have much experience on this topic? I need your help ergently!
>  
> 
>  

It's definitely possible to combine REST and XML mappings.

You might have better luck telling us what specific issues you're 
having, along with what version of S2 you're using.

Dave

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


Re: Struts2+ReST-plugin prolems need help!!!

Posted by Stuart Ellidge <st...@adaptris.com>.
Hi,

I’m not an expert with the internals of the REST plugin, but am using it fairly extensively. By and large we use annotations in our classes to determine results (see org.apache.struts2.convention.annotation.Results) but it is certainly possible to define some globals and it is definitely possible to configure interceptors. Given that a picture is worth a thousand words, here is a snippet from our struts XML:

  <constant name="struts.convention.default.parent.package" value="globalPackage"/>

  <package name="globalPackage" extends="rest-default">    <result-types>      <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>    </result-types>          <interceptors>        <interceptor name="setReturnURL" class="com.xyz.webapp.interceptors.ReturnURLInterceptor"/>        <interceptor name="categoryInterceptor" class="com.xyz.webapp.interceptors.CategoryInterceptor"/>                <interceptor-stack name="restDefaultInterceptors">            <interceptor-ref name="restDefaultStack"/>                                    <interceptor-ref name="setReturnURL"/>            <interceptor-ref name="categoryInterceptor"/>        </interceptor-stack>    </interceptors>    <default-interceptor-ref name="restDefaultInterceptors"/>        <global-results>          <result name="login" type="redirectAction">              <param name="actionName">login</param>              <param name="namespace">/site</param>          </result>      </global-results>
 </package>
So you can see that our main package (globalPackage) is defined such that it extends rest-default. We then create a new interceptor stack and specify that as the default interceptor for the package. Finally, and perhaps most importantly, we ensure that the constant “struts.convention.default.parent.package” points to our globalPackage.

Hope that helps you

Regards
Stuart

On 28/05/2009 02:12, "xnpeng" <xn...@163.com> wrote:

can any one help? i use struts2.1.6.




在2009-05-20,xnpeng <xn...@163.com> 写道:
>I'm doing my project with struts2+rest-plugin for about 3 months.there is a lot of problems unresolved.
>
>With rest-plugin and convention-plugin,all action-mapping are done automatically,manual action-mapping in struts.xml cannot work.so,
>1, I cannot define global-error-result;
>2, I cannot do forward;
>3, I cannot insert my own Interceptors.
>
>I 'm watching this mail-list day and day, there is not much discuss on rest-plugin, neithere is enough materials on the internet. Does someone have much experience on this topic? I need your help ergently!
>
>
>


Re:Struts2+ReST-plugin prolems need help!!!

Posted by xnpeng <xn...@163.com>.
can any one help? i use struts2.1.6.




在2009-05-20,xnpeng <xn...@163.com> 写道:
>I'm doing my project with struts2+rest-plugin for about 3 months.there is a lot of problems unresolved.
> 
>With rest-plugin and convention-plugin,all action-mapping are done automatically,manual action-mapping in struts.xml cannot work.so,
>1, I cannot define global-error-result;
>2, I cannot do forward;
>3, I cannot insert my own Interceptors.
>
>I 'm watching this mail-list day and day, there is not much discuss on rest-plugin, neithere is enough materials on the internet. Does someone have much experience on this topic? I need your help ergently!
> 
>
>