You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by john lee <sh...@yahoo.com> on 2013/05/23 23:29:40 UTC

struts 2 Intercepter ServletRequestAware

Please advise the following

for struts2, for an login action, an predefined interceptor is triggered for checking cookie , the code is the following

for  SecurityVerifySessionIntercepter, i implement the ServletRequestAware, but get null catached.

my question is:

for intercepter, Request object can not be implemented? if can, why i get null? 

thanks in advance

john 



public class SecurityVerifySessionIntercepter extends AbstractInterceptor implements ServletResponseAware, ServletRequestAware {

    
    protected HttpServletResponse servletResponse;
    public void setServletResponse(HttpServletResponse servletResponse)
              { this.servletResponse = servletResponse; }

    protected HttpServletRequest servletRequest;
    public void setServletRequest(HttpServletRequest servletRequest) { this.servletRequest = servletRequest; }

public String intercept(ActionInvocation invocation) throws Exception {

       ActionContext ctx=invocation.getInvocationContext();
      Map session= ctx.getContext().getSession();
      
         if (servletRequest==null)
             System.out.println(" Request object is null catched");
          Cookie cookieList[]=servletRequest.getCookies();

Re: struts 2 Intercepter ServletRequestAware

Posted by john lee <sh...@yahoo.com>.
because if cookie exist, then interceptor can catch it and assign the session object if user open the new webpage.




________________________________
 From: "jlmagc@gmail.com" <jl...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org>; john lee <sh...@yahoo.com> 
Sent: Thursday, May 23, 2013 6:25 PM
Subject: Re: struts 2 Intercepter ServletRequestAware
 

You need to access the request directly. But why do you want to use a cookie in an interceptor?
Sent via BlackBerry from T-Mobile

-----Original Message-----
From: john lee <sh...@yahoo.com>
Date: Thu, 23 May 2013 16:20:08 
To: Struts Users Mailing List<us...@struts.apache.org>
Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
Subject: Re: struts 2 Intercepter ServletRequestAware



thanks,

so, how can I access Cookie in the interceptor? as my knowledge, to access cookie, i have to get Servlet first, then get Request object, then access Cookie..

please advise 



john

________________________________
From: Chris Pratt <th...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org>; john lee <sh...@yahoo.com> 
Sent: Thursday, May 23, 2013 5:02 PM
Subject: Re: struts 2 Intercepter ServletRequestAware


You cannot use ServletRequestAware or ServletResponseAware in an
Interceptor.
  (*Chris*)


On Thu, May 23, 2013 at 2:58 PM, john lee <sh...@yahoo.com> wrote:

> please explain more, thanks in advance
>
>
> ________________________________
>  From: Dave Newton <da...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Thursday, May 23, 2013 4:53 PM
> Subject: Re: struts 2 Intercepter ServletRequestAware
>
>
> You may have misunderstood what I said.
>
> those interfaces are for actions, not interceptors.
> On May 23, 2013 5:51 PM, "john lee" <sh...@yahoo.com> wrote:
>
> > it is interceptor, the following is struts.xml, (i just not include last
> > time)
> >
> > <struts>
> >  <package name="default" extends="struts-default">
> >
> >         <interceptors>
> >              <interceptor name="securityverifysessionIntercepter"
> > class="SecurityVerifySessionIntercepter">
> >              </interceptor>
> >              <interceptor-stack name="SecurityStack">
> >                <interceptor-ref name="securityverifysessionIntercepter"/>
> >              </interceptor-stack>
> >         </interceptors>
> >
> >           <action name="LoginAction" class="LoginAction">
> >                     <interceptor-ref name="SecurityStack"/>
> >                     <result name="input">PageLogin.jsp</result>
> >                     <result name="success">PageMain.jsp</result>
> >        </package>
> >
> > </struts>
> >
> >
> >
> > ________________________________
> >  From: Dave Newton <da...@gmail.com>
> > To: Struts Users Mailing List <us...@struts.apache.org>
> > Sent: Thursday, May 23, 2013 4:31 PM
> > Subject: Re: struts 2 Intercepter ServletRequestAware
> >
> >
> > That interface is for actions, not interceptors.
> > On May 23, 2013 5:30 PM, "john lee" <sh...@yahoo.com> wrote:
> >
> > > Please advise the following
> > >
> > > for struts2, for an login action, an predefined interceptor is
> triggered
> > > for checking cookie , the code is the following
> > >
> > > for  SecurityVerifySessionIntercepter, i implement the
> > > ServletRequestAware, but get null catached.
> > >
> > > my question is:
> > >
> > > for intercepter, Request object can not be implemented? if can, why i
> get
> > > null?
> > >
> > > thanks in advance
> > >
> > > john
> > >
> > >
> > >
> > > public class SecurityVerifySessionIntercepter extends
> AbstractInterceptor
> > > implements ServletResponseAware, ServletRequestAware {
> > >
> > >
> > >     protected HttpServletResponse servletResponse;
> > >     public void setServletResponse(HttpServletResponse servletResponse)
> > >               { this.servletResponse = servletResponse; }
> > >
> > >     protected HttpServletRequest servletRequest;
> > >     public void setServletRequest(HttpServletRequest servletRequest) {
> > > this.servletRequest = servletRequest; }
> > >
> > > public String intercept(ActionInvocation invocation) throws Exception {
> > >
> > >        ActionContext ctx=invocation.getInvocationContext();
> > >       Map session= ctx.getContext().getSession();
> > >
> > >          if (servletRequest==null)
> > >              System.out.println(" Request object is null catched");
> > >           Cookie cookieList[]=servletRequest.getCookies();
> > >
>

Re: struts 2 Intercepter ServletRequestAware

Posted by jl...@gmail.com.
You need to access the request directly. But why do you want to use a cookie in an interceptor?
Sent via BlackBerry from T-Mobile

-----Original Message-----
From: john lee <sh...@yahoo.com>
Date: Thu, 23 May 2013 16:20:08 
To: Struts Users Mailing List<us...@struts.apache.org>
Reply-To: "Struts Users Mailing List" <us...@struts.apache.org>
Subject: Re: struts 2 Intercepter ServletRequestAware



thanks,

so, how can I access Cookie in the interceptor? as my knowledge, to access cookie, i have to get Servlet first, then get Request object, then access Cookie..

please advise 



john

________________________________
 From: Chris Pratt <th...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org>; john lee <sh...@yahoo.com> 
Sent: Thursday, May 23, 2013 5:02 PM
Subject: Re: struts 2 Intercepter ServletRequestAware
 

You cannot use ServletRequestAware or ServletResponseAware in an
Interceptor.
  (*Chris*)


On Thu, May 23, 2013 at 2:58 PM, john lee <sh...@yahoo.com> wrote:

> please explain more, thanks in advance
>
>
> ________________________________
>  From: Dave Newton <da...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Thursday, May 23, 2013 4:53 PM
> Subject: Re: struts 2 Intercepter ServletRequestAware
>
>
> You may have misunderstood what I said.
>
> those interfaces are for actions, not interceptors.
> On May 23, 2013 5:51 PM, "john lee" <sh...@yahoo.com> wrote:
>
> > it is interceptor, the following is struts.xml, (i just not include last
> > time)
> >
> > <struts>
> >  <package name="default" extends="struts-default">
> >
> >         <interceptors>
> >              <interceptor name="securityverifysessionIntercepter"
> > class="SecurityVerifySessionIntercepter">
> >              </interceptor>
> >              <interceptor-stack name="SecurityStack">
> >                <interceptor-ref name="securityverifysessionIntercepter"/>
> >              </interceptor-stack>
> >         </interceptors>
> >
> >           <action name="LoginAction" class="LoginAction">
> >                     <interceptor-ref name="SecurityStack"/>
> >                     <result name="input">PageLogin.jsp</result>
> >                     <result name="success">PageMain.jsp</result>
> >        </package>
> >
> > </struts>
> >
> >
> >
> > ________________________________
> >  From: Dave Newton <da...@gmail.com>
> > To: Struts Users Mailing List <us...@struts.apache.org>
> > Sent: Thursday, May 23, 2013 4:31 PM
> > Subject: Re: struts 2 Intercepter ServletRequestAware
> >
> >
> > That interface is for actions, not interceptors.
> > On May 23, 2013 5:30 PM, "john lee" <sh...@yahoo.com> wrote:
> >
> > > Please advise the following
> > >
> > > for struts2, for an login action, an predefined interceptor is
> triggered
> > > for checking cookie , the code is the following
> > >
> > > for  SecurityVerifySessionIntercepter, i implement the
> > > ServletRequestAware, but get null catached.
> > >
> > > my question is:
> > >
> > > for intercepter, Request object can not be implemented? if can, why i
> get
> > > null?
> > >
> > > thanks in advance
> > >
> > > john
> > >
> > >
> > >
> > > public class SecurityVerifySessionIntercepter extends
> AbstractInterceptor
> > > implements ServletResponseAware, ServletRequestAware {
> > >
> > >
> > >     protected HttpServletResponse servletResponse;
> > >     public void setServletResponse(HttpServletResponse servletResponse)
> > >               { this.servletResponse = servletResponse; }
> > >
> > >     protected HttpServletRequest servletRequest;
> > >     public void setServletRequest(HttpServletRequest servletRequest) {
> > > this.servletRequest = servletRequest; }
> > >
> > > public String intercept(ActionInvocation invocation) throws Exception {
> > >
> > >        ActionContext ctx=invocation.getInvocationContext();
> > >       Map session= ctx.getContext().getSession();
> > >
> > >          if (servletRequest==null)
> > >              System.out.println(" Request object is null catched");
> > >           Cookie cookieList[]=servletRequest.getCookies();
> > >
>

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

Re: struts 2 Intercepter ServletRequestAware

Posted by Chris Pratt <th...@gmail.com>.
It's static, you call it just like I sent in the previous email
  (*Chris*)
On May 23, 2013 4:55 PM, "john lee" <sh...@yahoo.com> wrote:

> in the interceptor,
>
> in order to access ServletActionContext, in the interceptor class, which
> interface should be implement?
>
> tks in advance
>
> john
>
>   ------------------------------
>  *From:* Chris Pratt <th...@gmail.com>
> *To:* Struts Users Mailing List <us...@struts.apache.org>; john lee <
> sh_thorn_bird@yahoo.com>
> *Sent:* Thursday, May 23, 2013 6:25 PM
> *Subject:* Re: struts 2 Intercepter ServletRequestAware
>
> ServletActionContext.getRequest().getCookies()
>   (*Chris*)
>
>
> On Thu, May 23, 2013 at 4:20 PM, john lee <sh...@yahoo.com> wrote:
>
>
>
> thanks,
>
> so, how can I access Cookie in the interceptor? as my knowledge, to access
> cookie, i have to get Servlet first, then get Request object, then access
> Cookie..
>
> please advise
>
>
>
> john
>
> ________________________________
>  From: Chris Pratt <th...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>; john lee <
> sh_thorn_bird@yahoo.com>
> Sent: Thursday, May 23, 2013 5:02 PM
> Subject: Re: struts 2 Intercepter ServletRequestAware
>
>
> You cannot use ServletRequestAware or ServletResponseAware in an
> Interceptor.
>   (*Chris*)
>
>
> On Thu, May 23, 2013 at 2:58 PM, john lee <sh...@yahoo.com> wrote:
>
> > please explain more, thanks in advance
> >
> >
> > ________________________________
> >  From: Dave Newton <da...@gmail.com>
> > To: Struts Users Mailing List <us...@struts.apache.org>
> > Sent: Thursday, May 23, 2013 4:53 PM
> > Subject: Re: struts 2 Intercepter ServletRequestAware
> >
> >
> > You may have misunderstood what I said.
> >
> > those interfaces are for actions, not interceptors.
> > On May 23, 2013 5:51 PM, "john lee" <sh...@yahoo.com> wrote:
> >
> > > it is interceptor, the following is struts.xml, (i just not include
> last
> > > time)
> > >
> > > <struts>
> > >  <package name="default" extends="struts-default">
> > >
> > >         <interceptors>
> > >              <interceptor name="securityverifysessionIntercepter"
> > > class="SecurityVerifySessionIntercepter">
> > >              </interceptor>
> > >              <interceptor-stack name="SecurityStack">
> > >                <interceptor-ref
> name="securityverifysessionIntercepter"/>
> > >              </interceptor-stack>
> > >         </interceptors>
> > >
> > >           <action name="LoginAction" class="LoginAction">
> > >                     <interceptor-ref name="SecurityStack"/>
> > >                     <result name="input">PageLogin.jsp</result>
> > >                     <result name="success">PageMain.jsp</result>
> > >        </package>
> > >
> > > </struts>
> > >
> > >
> > >
> > > ________________________________
> > >  From: Dave Newton <da...@gmail.com>
> > > To: Struts Users Mailing List <us...@struts.apache.org>
> > > Sent: Thursday, May 23, 2013 4:31 PM
> > > Subject: Re: struts 2 Intercepter ServletRequestAware
> > >
> > >
> > > That interface is for actions, not interceptors.
> > > On May 23, 2013 5:30 PM, "john lee" <sh...@yahoo.com> wrote:
> > >
> > > > Please advise the following
> > > >
> > > > for struts2, for an login action, an predefined interceptor is
> > triggered
> > > > for checking cookie , the code is the following
> > > >
> > > > for  SecurityVerifySessionIntercepter, i implement the
> > > > ServletRequestAware, but get null catached.
> > > >
> > > > my question is:
> > > >
> > > > for intercepter, Request object can not be implemented? if can, why i
> > get
> > > > null?
> > > >
> > > > thanks in advance
> > > >
> > > > john
> > > >
> > > >
> > > >
> > > > public class SecurityVerifySessionIntercepter extends
> > AbstractInterceptor
> > > > implements ServletResponseAware, ServletRequestAware {
> > > >
> > > >
> > > >     protected HttpServletResponse servletResponse;
> > > >     public void setServletResponse(HttpServletResponse
> servletResponse)
> > > >               { this.servletResponse = servletResponse; }
> > > >
> > > >     protected HttpServletRequest servletRequest;
> > > >     public void setServletRequest(HttpServletRequest servletRequest)
> {
> > > > this.servletRequest = servletRequest; }
> > > >
> > > > public String intercept(ActionInvocation invocation) throws
> Exception {
> > > >
> > > >        ActionContext ctx=invocation.getInvocationContext();
> > > >       Map session= ctx.getContext().getSession();
> > > >
> > > >          if (servletRequest==null)
> > > >              System.out.println(" Request object is null catched");
> > > >           Cookie cookieList[]=servletRequest.getCookies();
> > > >
> >
>
>
>
>
>

Re: struts 2 Intercepter ServletRequestAware

Posted by john lee <sh...@yahoo.com>.
in the interceptor, 

in order to access ServletActionContext, in the interceptor class, which interface should be implement?

tks in advance

john


________________________________
 From: Chris Pratt <th...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org>; john lee <sh...@yahoo.com> 
Sent: Thursday, May 23, 2013 6:25 PM
Subject: Re: struts 2 Intercepter ServletRequestAware
 


ServletActionContext.getRequest().getCookies()
  (*Chris*)



On Thu, May 23, 2013 at 4:20 PM, john lee <sh...@yahoo.com> wrote:


>
>thanks,
>
>so, how can I access Cookie in the interceptor? as my knowledge, to access cookie, i have to get Servlet first, then get Request object, then access Cookie..
>
>please advise 
>
>
>
>john
>
>
>________________________________
> From: Chris Pratt <th...@gmail.com>
>To: Struts Users Mailing List <us...@struts.apache.org>; john lee <sh...@yahoo.com>
>Sent: Thursday, May 23, 2013 5:02 PM
>
>Subject: Re: struts 2 Intercepter ServletRequestAware
>
>
>You cannot use ServletRequestAware or ServletResponseAware in an
>Interceptor.
>  (*Chris*)
>
>
>On Thu, May 23, 2013 at 2:58 PM, john lee <sh...@yahoo.com> wrote:
>
>> please explain more, thanks in advance
>>
>>
>> ________________________________
>>  From: Dave Newton <da...@gmail.com>
>> To: Struts Users Mailing List <us...@struts.apache.org>
>> Sent: Thursday, May 23, 2013 4:53 PM
>> Subject: Re: struts 2 Intercepter ServletRequestAware
>>
>>
>> You may have misunderstood what I said.
>>
>> those interfaces are for actions, not interceptors.
>> On May 23, 2013 5:51 PM, "john lee" <sh...@yahoo.com> wrote:
>>
>> > it is interceptor, the following is struts.xml, (i just not include last
>> > time)
>> >
>> > <struts>
>> >  <package name="default" extends="struts-default">
>> >
>> >         <interceptors>
>> >              <interceptor name="securityverifysessionIntercepter"
>> > class="SecurityVerifySessionIntercepter">
>> >              </interceptor>
>> >              <interceptor-stack name="SecurityStack">
>> >                <interceptor-ref name="securityverifysessionIntercepter"/>
>> >              </interceptor-stack>
>> >         </interceptors>
>> >
>> >           <action name="LoginAction" class="LoginAction">
>> >                     <interceptor-ref name="SecurityStack"/>
>> >                     <result name="input">PageLogin.jsp</result>
>> >                     <result name="success">PageMain.jsp</result>
>> >        </package>
>> >
>> > </struts>
>> >
>> >
>> >
>> > ________________________________
>> >  From: Dave Newton <da...@gmail.com>
>> > To: Struts Users Mailing List <us...@struts.apache.org>
>> > Sent: Thursday, May 23, 2013 4:31 PM
>> > Subject: Re: struts 2 Intercepter ServletRequestAware
>> >
>> >
>> > That interface is for actions, not interceptors.
>> > On May 23, 2013 5:30 PM, "john lee" <sh...@yahoo.com> wrote:
>> >
>> > > Please advise the following
>> > >
>> > > for struts2, for an login action, an predefined interceptor is
>> triggered
>> > > for checking cookie , the code is the following
>> > >
>> > > for  SecurityVerifySessionIntercepter, i implement the
>> > > ServletRequestAware, but get null catached.
>> > >
>> > > my question is:
>> > >
>> > > for intercepter, Request object can not be implemented? if can, why i
>> get
>> > > null?
>> > >
>> > > thanks in advance
>> > >
>> > > john
>> > >
>> > >
>> > >
>> > > public class SecurityVerifySessionIntercepter extends
>> AbstractInterceptor
>> > > implements ServletResponseAware, ServletRequestAware {
>> > >
>> > >
>> > >     protected HttpServletResponse servletResponse;
>> > >     public void setServletResponse(HttpServletResponse servletResponse)
>> > >               { this.servletResponse = servletResponse; }
>> > >
>> > >     protected HttpServletRequest servletRequest;
>> > >     public void setServletRequest(HttpServletRequest servletRequest) {
>> > > this.servletRequest = servletRequest; }
>> > >
>> > > public String intercept(ActionInvocation invocation) throws Exception {
>> > >
>> > >        ActionContext ctx=invocation.getInvocationContext();
>> > >       Map session= ctx.getContext().getSession();
>> > >
>> > >          if (servletRequest==null)
>> > >              System.out.println(" Request object is null catched");
>> > >           Cookie cookieList[]=servletRequest.getCookies();
>> > >
>>

Re: struts 2 Intercepter ServletRequestAware

Posted by Chris Pratt <th...@gmail.com>.
ServletActionContext.getRequest().getCookies()
  (*Chris*)


On Thu, May 23, 2013 at 4:20 PM, john lee <sh...@yahoo.com> wrote:

>
>
> thanks,
>
> so, how can I access Cookie in the interceptor? as my knowledge, to access
> cookie, i have to get Servlet first, then get Request object, then access
> Cookie..
>
> please advise
>
>
>
> john
>
> ________________________________
>  From: Chris Pratt <th...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>; john lee <
> sh_thorn_bird@yahoo.com>
> Sent: Thursday, May 23, 2013 5:02 PM
> Subject: Re: struts 2 Intercepter ServletRequestAware
>
>
> You cannot use ServletRequestAware or ServletResponseAware in an
> Interceptor.
>   (*Chris*)
>
>
> On Thu, May 23, 2013 at 2:58 PM, john lee <sh...@yahoo.com> wrote:
>
> > please explain more, thanks in advance
> >
> >
> > ________________________________
> >  From: Dave Newton <da...@gmail.com>
> > To: Struts Users Mailing List <us...@struts.apache.org>
> > Sent: Thursday, May 23, 2013 4:53 PM
> > Subject: Re: struts 2 Intercepter ServletRequestAware
> >
> >
> > You may have misunderstood what I said.
> >
> > those interfaces are for actions, not interceptors.
> > On May 23, 2013 5:51 PM, "john lee" <sh...@yahoo.com> wrote:
> >
> > > it is interceptor, the following is struts.xml, (i just not include
> last
> > > time)
> > >
> > > <struts>
> > >  <package name="default" extends="struts-default">
> > >
> > >         <interceptors>
> > >              <interceptor name="securityverifysessionIntercepter"
> > > class="SecurityVerifySessionIntercepter">
> > >              </interceptor>
> > >              <interceptor-stack name="SecurityStack">
> > >                <interceptor-ref
> name="securityverifysessionIntercepter"/>
> > >              </interceptor-stack>
> > >         </interceptors>
> > >
> > >           <action name="LoginAction" class="LoginAction">
> > >                     <interceptor-ref name="SecurityStack"/>
> > >                     <result name="input">PageLogin.jsp</result>
> > >                     <result name="success">PageMain.jsp</result>
> > >        </package>
> > >
> > > </struts>
> > >
> > >
> > >
> > > ________________________________
> > >  From: Dave Newton <da...@gmail.com>
> > > To: Struts Users Mailing List <us...@struts.apache.org>
> > > Sent: Thursday, May 23, 2013 4:31 PM
> > > Subject: Re: struts 2 Intercepter ServletRequestAware
> > >
> > >
> > > That interface is for actions, not interceptors.
> > > On May 23, 2013 5:30 PM, "john lee" <sh...@yahoo.com> wrote:
> > >
> > > > Please advise the following
> > > >
> > > > for struts2, for an login action, an predefined interceptor is
> > triggered
> > > > for checking cookie , the code is the following
> > > >
> > > > for  SecurityVerifySessionIntercepter, i implement the
> > > > ServletRequestAware, but get null catached.
> > > >
> > > > my question is:
> > > >
> > > > for intercepter, Request object can not be implemented? if can, why i
> > get
> > > > null?
> > > >
> > > > thanks in advance
> > > >
> > > > john
> > > >
> > > >
> > > >
> > > > public class SecurityVerifySessionIntercepter extends
> > AbstractInterceptor
> > > > implements ServletResponseAware, ServletRequestAware {
> > > >
> > > >
> > > >     protected HttpServletResponse servletResponse;
> > > >     public void setServletResponse(HttpServletResponse
> servletResponse)
> > > >               { this.servletResponse = servletResponse; }
> > > >
> > > >     protected HttpServletRequest servletRequest;
> > > >     public void setServletRequest(HttpServletRequest servletRequest)
> {
> > > > this.servletRequest = servletRequest; }
> > > >
> > > > public String intercept(ActionInvocation invocation) throws
> Exception {
> > > >
> > > >        ActionContext ctx=invocation.getInvocationContext();
> > > >       Map session= ctx.getContext().getSession();
> > > >
> > > >          if (servletRequest==null)
> > > >              System.out.println(" Request object is null catched");
> > > >           Cookie cookieList[]=servletRequest.getCookies();
> > > >
> >
>

Re: struts 2 Intercepter ServletRequestAware

Posted by john lee <sh...@yahoo.com>.

thanks,

so, how can I access Cookie in the interceptor? as my knowledge, to access cookie, i have to get Servlet first, then get Request object, then access Cookie..

please advise 



john

________________________________
 From: Chris Pratt <th...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org>; john lee <sh...@yahoo.com> 
Sent: Thursday, May 23, 2013 5:02 PM
Subject: Re: struts 2 Intercepter ServletRequestAware
 

You cannot use ServletRequestAware or ServletResponseAware in an
Interceptor.
  (*Chris*)


On Thu, May 23, 2013 at 2:58 PM, john lee <sh...@yahoo.com> wrote:

> please explain more, thanks in advance
>
>
> ________________________________
>  From: Dave Newton <da...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Thursday, May 23, 2013 4:53 PM
> Subject: Re: struts 2 Intercepter ServletRequestAware
>
>
> You may have misunderstood what I said.
>
> those interfaces are for actions, not interceptors.
> On May 23, 2013 5:51 PM, "john lee" <sh...@yahoo.com> wrote:
>
> > it is interceptor, the following is struts.xml, (i just not include last
> > time)
> >
> > <struts>
> >  <package name="default" extends="struts-default">
> >
> >         <interceptors>
> >              <interceptor name="securityverifysessionIntercepter"
> > class="SecurityVerifySessionIntercepter">
> >              </interceptor>
> >              <interceptor-stack name="SecurityStack">
> >                <interceptor-ref name="securityverifysessionIntercepter"/>
> >              </interceptor-stack>
> >         </interceptors>
> >
> >           <action name="LoginAction" class="LoginAction">
> >                     <interceptor-ref name="SecurityStack"/>
> >                     <result name="input">PageLogin.jsp</result>
> >                     <result name="success">PageMain.jsp</result>
> >        </package>
> >
> > </struts>
> >
> >
> >
> > ________________________________
> >  From: Dave Newton <da...@gmail.com>
> > To: Struts Users Mailing List <us...@struts.apache.org>
> > Sent: Thursday, May 23, 2013 4:31 PM
> > Subject: Re: struts 2 Intercepter ServletRequestAware
> >
> >
> > That interface is for actions, not interceptors.
> > On May 23, 2013 5:30 PM, "john lee" <sh...@yahoo.com> wrote:
> >
> > > Please advise the following
> > >
> > > for struts2, for an login action, an predefined interceptor is
> triggered
> > > for checking cookie , the code is the following
> > >
> > > for  SecurityVerifySessionIntercepter, i implement the
> > > ServletRequestAware, but get null catached.
> > >
> > > my question is:
> > >
> > > for intercepter, Request object can not be implemented? if can, why i
> get
> > > null?
> > >
> > > thanks in advance
> > >
> > > john
> > >
> > >
> > >
> > > public class SecurityVerifySessionIntercepter extends
> AbstractInterceptor
> > > implements ServletResponseAware, ServletRequestAware {
> > >
> > >
> > >     protected HttpServletResponse servletResponse;
> > >     public void setServletResponse(HttpServletResponse servletResponse)
> > >               { this.servletResponse = servletResponse; }
> > >
> > >     protected HttpServletRequest servletRequest;
> > >     public void setServletRequest(HttpServletRequest servletRequest) {
> > > this.servletRequest = servletRequest; }
> > >
> > > public String intercept(ActionInvocation invocation) throws Exception {
> > >
> > >        ActionContext ctx=invocation.getInvocationContext();
> > >       Map session= ctx.getContext().getSession();
> > >
> > >          if (servletRequest==null)
> > >              System.out.println(" Request object is null catched");
> > >           Cookie cookieList[]=servletRequest.getCookies();
> > >
>

Re: struts 2 Intercepter ServletRequestAware

Posted by Chris Pratt <th...@gmail.com>.
You cannot use ServletRequestAware or ServletResponseAware in an
Interceptor.
  (*Chris*)


On Thu, May 23, 2013 at 2:58 PM, john lee <sh...@yahoo.com> wrote:

> please explain more, thanks in advance
>
>
> ________________________________
>  From: Dave Newton <da...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Thursday, May 23, 2013 4:53 PM
> Subject: Re: struts 2 Intercepter ServletRequestAware
>
>
> You may have misunderstood what I said.
>
> those interfaces are for actions, not interceptors.
> On May 23, 2013 5:51 PM, "john lee" <sh...@yahoo.com> wrote:
>
> > it is interceptor, the following is struts.xml, (i just not include last
> > time)
> >
> > <struts>
> >  <package name="default" extends="struts-default">
> >
> >         <interceptors>
> >              <interceptor name="securityverifysessionIntercepter"
> > class="SecurityVerifySessionIntercepter">
> >              </interceptor>
> >              <interceptor-stack name="SecurityStack">
> >                <interceptor-ref name="securityverifysessionIntercepter"/>
> >              </interceptor-stack>
> >         </interceptors>
> >
> >           <action name="LoginAction" class="LoginAction">
> >                     <interceptor-ref name="SecurityStack"/>
> >                     <result name="input">PageLogin.jsp</result>
> >                     <result name="success">PageMain.jsp</result>
> >        </package>
> >
> > </struts>
> >
> >
> >
> > ________________________________
> >  From: Dave Newton <da...@gmail.com>
> > To: Struts Users Mailing List <us...@struts.apache.org>
> > Sent: Thursday, May 23, 2013 4:31 PM
> > Subject: Re: struts 2 Intercepter ServletRequestAware
> >
> >
> > That interface is for actions, not interceptors.
> > On May 23, 2013 5:30 PM, "john lee" <sh...@yahoo.com> wrote:
> >
> > > Please advise the following
> > >
> > > for struts2, for an login action, an predefined interceptor is
> triggered
> > > for checking cookie , the code is the following
> > >
> > > for  SecurityVerifySessionIntercepter, i implement the
> > > ServletRequestAware, but get null catached.
> > >
> > > my question is:
> > >
> > > for intercepter, Request object can not be implemented? if can, why i
> get
> > > null?
> > >
> > > thanks in advance
> > >
> > > john
> > >
> > >
> > >
> > > public class SecurityVerifySessionIntercepter extends
> AbstractInterceptor
> > > implements ServletResponseAware, ServletRequestAware {
> > >
> > >
> > >     protected HttpServletResponse servletResponse;
> > >     public void setServletResponse(HttpServletResponse servletResponse)
> > >               { this.servletResponse = servletResponse; }
> > >
> > >     protected HttpServletRequest servletRequest;
> > >     public void setServletRequest(HttpServletRequest servletRequest) {
> > > this.servletRequest = servletRequest; }
> > >
> > > public String intercept(ActionInvocation invocation) throws Exception {
> > >
> > >        ActionContext ctx=invocation.getInvocationContext();
> > >       Map session= ctx.getContext().getSession();
> > >
> > >          if (servletRequest==null)
> > >              System.out.println(" Request object is null catched");
> > >           Cookie cookieList[]=servletRequest.getCookies();
> > >
>

Re: struts 2 Intercepter ServletRequestAware

Posted by john lee <sh...@yahoo.com>.
please explain more, thanks in advance 


________________________________
 From: Dave Newton <da...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org> 
Sent: Thursday, May 23, 2013 4:53 PM
Subject: Re: struts 2 Intercepter ServletRequestAware
 

You may have misunderstood what I said.

those interfaces are for actions, not interceptors.
On May 23, 2013 5:51 PM, "john lee" <sh...@yahoo.com> wrote:

> it is interceptor, the following is struts.xml, (i just not include last
> time)
>
> <struts>
>  <package name="default" extends="struts-default">
>
>         <interceptors>
>              <interceptor name="securityverifysessionIntercepter"
> class="SecurityVerifySessionIntercepter">
>              </interceptor>
>              <interceptor-stack name="SecurityStack">
>                <interceptor-ref name="securityverifysessionIntercepter"/>
>              </interceptor-stack>
>         </interceptors>
>
>           <action name="LoginAction" class="LoginAction">
>                     <interceptor-ref name="SecurityStack"/>
>                     <result name="input">PageLogin.jsp</result>
>                     <result name="success">PageMain.jsp</result>
>        </package>
>
> </struts>
>
>
>
> ________________________________
>  From: Dave Newton <da...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Thursday, May 23, 2013 4:31 PM
> Subject: Re: struts 2 Intercepter ServletRequestAware
>
>
> That interface is for actions, not interceptors.
> On May 23, 2013 5:30 PM, "john lee" <sh...@yahoo.com> wrote:
>
> > Please advise the following
> >
> > for struts2, for an login action, an predefined interceptor is triggered
> > for checking cookie , the code is the following
> >
> > for  SecurityVerifySessionIntercepter, i implement the
> > ServletRequestAware, but get null catached.
> >
> > my question is:
> >
> > for intercepter, Request object can not be implemented? if can, why i get
> > null?
> >
> > thanks in advance
> >
> > john
> >
> >
> >
> > public class SecurityVerifySessionIntercepter extends AbstractInterceptor
> > implements ServletResponseAware, ServletRequestAware {
> >
> >
> >     protected HttpServletResponse servletResponse;
> >     public void setServletResponse(HttpServletResponse servletResponse)
> >               { this.servletResponse = servletResponse; }
> >
> >     protected HttpServletRequest servletRequest;
> >     public void setServletRequest(HttpServletRequest servletRequest) {
> > this.servletRequest = servletRequest; }
> >
> > public String intercept(ActionInvocation invocation) throws Exception {
> >
> >        ActionContext ctx=invocation.getInvocationContext();
> >       Map session= ctx.getContext().getSession();
> >
> >          if (servletRequest==null)
> >              System.out.println(" Request object is null catched");
> >           Cookie cookieList[]=servletRequest.getCookies();
> >

Re: struts 2 Intercepter ServletRequestAware

Posted by Dave Newton <da...@gmail.com>.
You may have misunderstood what I said.

those interfaces are for actions, not interceptors.
 On May 23, 2013 5:51 PM, "john lee" <sh...@yahoo.com> wrote:

> it is interceptor, the following is struts.xml, (i just not include last
> time)
>
> <struts>
>  <package name="default" extends="struts-default">
>
>         <interceptors>
>              <interceptor name="securityverifysessionIntercepter"
> class="SecurityVerifySessionIntercepter">
>              </interceptor>
>              <interceptor-stack name="SecurityStack">
>                <interceptor-ref name="securityverifysessionIntercepter"/>
>              </interceptor-stack>
>         </interceptors>
>
>           <action name="LoginAction" class="LoginAction">
>                     <interceptor-ref name="SecurityStack"/>
>                     <result name="input">PageLogin.jsp</result>
>                     <result name="success">PageMain.jsp</result>
>        </package>
>
> </struts>
>
>
>
> ________________________________
>  From: Dave Newton <da...@gmail.com>
> To: Struts Users Mailing List <us...@struts.apache.org>
> Sent: Thursday, May 23, 2013 4:31 PM
> Subject: Re: struts 2 Intercepter ServletRequestAware
>
>
> That interface is for actions, not interceptors.
> On May 23, 2013 5:30 PM, "john lee" <sh...@yahoo.com> wrote:
>
> > Please advise the following
> >
> > for struts2, for an login action, an predefined interceptor is triggered
> > for checking cookie , the code is the following
> >
> > for  SecurityVerifySessionIntercepter, i implement the
> > ServletRequestAware, but get null catached.
> >
> > my question is:
> >
> > for intercepter, Request object can not be implemented? if can, why i get
> > null?
> >
> > thanks in advance
> >
> > john
> >
> >
> >
> > public class SecurityVerifySessionIntercepter extends AbstractInterceptor
> > implements ServletResponseAware, ServletRequestAware {
> >
> >
> >     protected HttpServletResponse servletResponse;
> >     public void setServletResponse(HttpServletResponse servletResponse)
> >               { this.servletResponse = servletResponse; }
> >
> >     protected HttpServletRequest servletRequest;
> >     public void setServletRequest(HttpServletRequest servletRequest) {
> > this.servletRequest = servletRequest; }
> >
> > public String intercept(ActionInvocation invocation) throws Exception {
> >
> >        ActionContext ctx=invocation.getInvocationContext();
> >       Map session= ctx.getContext().getSession();
> >
> >          if (servletRequest==null)
> >              System.out.println(" Request object is null catched");
> >           Cookie cookieList[]=servletRequest.getCookies();
> >

Re: struts 2 Intercepter ServletRequestAware

Posted by john lee <sh...@yahoo.com>.
it is interceptor, the following is struts.xml, (i just not include last time)

<struts>
 <package name="default" extends="struts-default">

        <interceptors>
             <interceptor name="securityverifysessionIntercepter" class="SecurityVerifySessionIntercepter">
             </interceptor>
             <interceptor-stack name="SecurityStack">   
               <interceptor-ref name="securityverifysessionIntercepter"/>
             </interceptor-stack>
        </interceptors>
        
          <action name="LoginAction" class="LoginAction">
                    <interceptor-ref name="SecurityStack"/>
                    <result name="input">PageLogin.jsp</result>
                    <result name="success">PageMain.jsp</result>
       </package>

</struts>
                   


________________________________
 From: Dave Newton <da...@gmail.com>
To: Struts Users Mailing List <us...@struts.apache.org> 
Sent: Thursday, May 23, 2013 4:31 PM
Subject: Re: struts 2 Intercepter ServletRequestAware
 

That interface is for actions, not interceptors.
On May 23, 2013 5:30 PM, "john lee" <sh...@yahoo.com> wrote:

> Please advise the following
>
> for struts2, for an login action, an predefined interceptor is triggered
> for checking cookie , the code is the following
>
> for  SecurityVerifySessionIntercepter, i implement the
> ServletRequestAware, but get null catached.
>
> my question is:
>
> for intercepter, Request object can not be implemented? if can, why i get
> null?
>
> thanks in advance
>
> john
>
>
>
> public class SecurityVerifySessionIntercepter extends AbstractInterceptor
> implements ServletResponseAware, ServletRequestAware {
>
>
>     protected HttpServletResponse servletResponse;
>     public void setServletResponse(HttpServletResponse servletResponse)
>               { this.servletResponse = servletResponse; }
>
>     protected HttpServletRequest servletRequest;
>     public void setServletRequest(HttpServletRequest servletRequest) {
> this.servletRequest = servletRequest; }
>
> public String intercept(ActionInvocation invocation) throws Exception {
>
>        ActionContext ctx=invocation.getInvocationContext();
>       Map session= ctx.getContext().getSession();
>
>          if (servletRequest==null)
>              System.out.println(" Request object is null catched");
>           Cookie cookieList[]=servletRequest.getCookies();
>

Re: struts 2 Intercepter ServletRequestAware

Posted by Dave Newton <da...@gmail.com>.
That interface is for actions, not interceptors.
 On May 23, 2013 5:30 PM, "john lee" <sh...@yahoo.com> wrote:

> Please advise the following
>
> for struts2, for an login action, an predefined interceptor is triggered
> for checking cookie , the code is the following
>
> for  SecurityVerifySessionIntercepter, i implement the
> ServletRequestAware, but get null catached.
>
> my question is:
>
> for intercepter, Request object can not be implemented? if can, why i get
> null?
>
> thanks in advance
>
> john
>
>
>
> public class SecurityVerifySessionIntercepter extends AbstractInterceptor
> implements ServletResponseAware, ServletRequestAware {
>
>
>     protected HttpServletResponse servletResponse;
>     public void setServletResponse(HttpServletResponse servletResponse)
>               { this.servletResponse = servletResponse; }
>
>     protected HttpServletRequest servletRequest;
>     public void setServletRequest(HttpServletRequest servletRequest) {
> this.servletRequest = servletRequest; }
>
> public String intercept(ActionInvocation invocation) throws Exception {
>
>        ActionContext ctx=invocation.getInvocationContext();
>       Map session= ctx.getContext().getSession();
>
>          if (servletRequest==null)
>              System.out.println(" Request object is null catched");
>           Cookie cookieList[]=servletRequest.getCookies();
>