Re: [S2] Accessing HTTP Header

2007-06-13 Thread Yoni Amir

Here is an interceptor that I use to manipulate the HttpResponse
object. You can do the same for the HttpRequest.

public String intercept(ActionInvocation actionInvocation) throws Exception {
 HttpServletResponse resp = ServletActionContext.getResponse();
 resp.setHeader(Pragma, no-cache);
 // etc ...
}

Notice that ActionContext (and ServletActionContext) is ThreadLocal.
That's why this code is so concise.


On 6/13/07, Dave Newton [EMAIL PROTECTED] wrote:

--- chengas123 [EMAIL PROTECTED] wrote:
 However, now I'm having the problem that I can't
 figure out how to access the HTTP request headers
 from the interceptor.

Follow the yellow brick API...

What's the signature of Interceptor.intercept?

String intercept(ActionInvocation)

What's an ActionInvocation? Oh, it's an interface. One
thing that looks particularly interesting is
ActionInvocation.getInvocationContext(...) -- it's
interesting because it contains the word context.

Okay, that returns an ActionContext. One
*particularly* interesting implementation of
ActionContext is ServletActionContext.

 Is ServletRequestAware meant to be used only in
 Actions?  I am receiving a null HTTP Request Servlet

 in my Interceptor.

Um... yeah. Well, I mean, you can use it anywhere you
want, but the framework (AFAIK) only pays attention to
it in Actions, where an interceptor uses it to decide
if it needs to set anything in the Action.

d.





Be a better Heartthrob. Get better relationship answers from someone who knows. 
Yahoo! Answers - Check it out.
http://answers.yahoo.com/dir/?link=listsid=396545433

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [S2] Accessing HTTP Header

2007-06-13 Thread chengas123

Thank you both for your responses.  While I had tried going down the
ActionInvocation.getInvocationContext(...) road I didn't see anything
interesting that way and probably would have never thought to cast it to a
ServletActionContext (although hopefully I will next time).  I'm using the
ThreadLocal approach right now for brevity.  Is there any performance
difference or other difference between the two approaches that I should be
aware of?  



Yoni Amir-2 wrote:
 
 Here is an interceptor that I use to manipulate the HttpResponse
 object. You can do the same for the HttpRequest.
 
 public String intercept(ActionInvocation actionInvocation) throws
 Exception {
   HttpServletResponse resp = ServletActionContext.getResponse();
   resp.setHeader(Pragma, no-cache);
   // etc ...
 }
 
 Notice that ActionContext (and ServletActionContext) is ThreadLocal.
 That's why this code is so concise.
 
 
 On 6/13/07, Dave Newton [EMAIL PROTECTED] wrote:
 Follow the yellow brick API...

 What's the signature of Interceptor.intercept?

 String intercept(ActionInvocation)

 What's an ActionInvocation? Oh, it's an interface. One
 thing that looks particularly interesting is
 ActionInvocation.getInvocationContext(...) -- it's
 interesting because it contains the word context.

 Okay, that returns an ActionContext. One
 *particularly* interesting implementation of
 ActionContext is ServletActionContext.

 d.

 

-- 
View this message in context: 
http://www.nabble.com/-S2--Accessing-HTTP-Header-tf3907721.html#a11100917
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [S2] Accessing HTTP Header

2007-06-13 Thread Yoni Amir

I don't know of any performance differences, but I am not a struts expert.
I think that the static methods of ServletActionContext were provided
exactly for this reason, namely convenience, so you don't need to deal
with casting. Also, if the internal working objects change in a later
struts release, then casting might be broken, while the static api is
more likely to remain the same.

You can have a look at the source code of the ServletConfigInteceptor.
I learned from it how ActionContext actually works. However, that code
is at a higher level of expertise (as is expected from the struts
developers, I suppose), so I just stick with the thread local
approach.

On 6/13/07, chengas123 [EMAIL PROTECTED] wrote:


Thank you both for your responses.  While I had tried going down the
ActionInvocation.getInvocationContext(...) road I didn't see anything
interesting that way and probably would have never thought to cast it to a
ServletActionContext (although hopefully I will next time).  I'm using the
ThreadLocal approach right now for brevity.  Is there any performance
difference or other difference between the two approaches that I should be
aware of?



Yoni Amir-2 wrote:

 Here is an interceptor that I use to manipulate the HttpResponse
 object. You can do the same for the HttpRequest.

 public String intercept(ActionInvocation actionInvocation) throws
 Exception {
   HttpServletResponse resp = ServletActionContext.getResponse();
   resp.setHeader(Pragma, no-cache);
   // etc ...
 }

 Notice that ActionContext (and ServletActionContext) is ThreadLocal.
 That's why this code is so concise.


 On 6/13/07, Dave Newton [EMAIL PROTECTED] wrote:
 Follow the yellow brick API...

 What's the signature of Interceptor.intercept?

 String intercept(ActionInvocation)

 What's an ActionInvocation? Oh, it's an interface. One
 thing that looks particularly interesting is
 ActionInvocation.getInvocationContext(...) -- it's
 interesting because it contains the word context.

 Okay, that returns an ActionContext. One
 *particularly* interesting implementation of
 ActionContext is ServletActionContext.

 d.



--
View this message in context: 
http://www.nabble.com/-S2--Accessing-HTTP-Header-tf3907721.html#a11100917
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



[S2] Accessing HTTP Header

2007-06-12 Thread chengas123

Hi,
How do I access the request variable or HTTP request headers?  I want to do
something like the following in my action:
request.getHeader(Accept).toLowerCase().indexOf(vnd.wap)
I am trying to detect whether the user is using a wireless device such as a
Blackberry in my action to determine which .jsp to send the user to in order
to display the output in a nicely formatted manner.

Thanks,
Ben
http://benmccann.com benmccann.com 

-- 
View this message in context: 
http://www.nabble.com/-S2--Accessing-HTTP-Header-tf3907721.html#a11079394
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [S2] Accessing HTTP Header

2007-06-12 Thread Nuwan Chandrasoma

http://struts.apache.org/2.x/docs/how-can-we-access-the-httpservletrequest.html


- Original Message - 
From: chengas123 [EMAIL PROTECTED]

To: user@struts.apache.org
Sent: Tuesday, June 12, 2007 2:23 PM
Subject: [S2] Accessing HTTP Header




Hi,
How do I access the request variable or HTTP request headers?  I want to 
do

something like the following in my action:
request.getHeader(Accept).toLowerCase().indexOf(vnd.wap)
I am trying to detect whether the user is using a wireless device such as 
a
Blackberry in my action to determine which .jsp to send the user to in 
order

to display the output in a nicely formatted manner.

Thanks,
Ben
http://benmccann.com benmccann.com

--
View this message in context: 
http://www.nabble.com/-S2--Accessing-HTTP-Header-tf3907721.html#a11079394

Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [S2] Accessing HTTP Header

2007-06-12 Thread chengas123


nuwan chandrasoma-2 wrote:
 
 http://struts.apache.org/2.x/docs/how-can-we-access-the-httpservletrequest.html
 

Struts Documentation wrote:
 
 It is more difficult to test Actions with runtime dependencies on
 HttpServletRequest. Only implement ServletRequestAware as a last resort.
 If the use case cannot be solved by one of the other servet-config
 interfaces (ApplicationAware, SessionAware, ParameterAware), consider
 whether an custom Interceptor could be used instead of Action code.
 

Thanks for the link.  I started looking at implementing a custom interceptor
and think it's a much better solution for me than putting the code in the
action.  However, now I'm having the problem that I can't figure out how to
access the HTTP request headers from the interceptor.  Is
ServletRequestAware meant to be used only in Actions?  I am receiving a null
HTTP Request Servlet in my Interceptor.  Also, I have included a portion of
my struts.xml file below.  I am using servlet-config, so I'm not sure why
the object is not being set.

interceptors
interceptor name=wireless
class=com.sherwin.whitePages.interceptor.WirelessInterceptor/
interceptor-stack name=customStack
interceptor-ref name=exception/
interceptor-ref name=servlet-config/
interceptor-ref name=i18n/
interceptor-ref name=chain/
interceptor-ref name=checkbox/
interceptor-ref name=params/
interceptor-ref name=conversionError/
interceptor-ref name=wireless/
/interceptor-stack
/interceptors

default-interceptor-ref name=customStack/


-- 
View this message in context: 
http://www.nabble.com/-S2--Accessing-HTTP-Header-tf3907721.html#a11087892
Sent from the Struts - User mailing list archive at Nabble.com.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: [S2] Accessing HTTP Header

2007-06-12 Thread Dave Newton
--- chengas123 [EMAIL PROTECTED] wrote:
 However, now I'm having the problem that I can't 
 figure out how to access the HTTP request headers 
 from the interceptor.  

Follow the yellow brick API...

What's the signature of Interceptor.intercept?

String intercept(ActionInvocation)

What's an ActionInvocation? Oh, it's an interface. One
thing that looks particularly interesting is
ActionInvocation.getInvocationContext(...) -- it's
interesting because it contains the word context.

Okay, that returns an ActionContext. One
*particularly* interesting implementation of
ActionContext is ServletActionContext.

 Is ServletRequestAware meant to be used only in
 Actions?  I am receiving a null HTTP Request Servlet

 in my Interceptor.  

Um... yeah. Well, I mean, you can use it anywhere you
want, but the framework (AFAIK) only pays attention to
it in Actions, where an interceptor uses it to decide
if it needs to set anything in the Action.

d.



   

Be a better Heartthrob. Get better relationship answers from someone who knows. 
Yahoo! Answers - Check it out. 
http://answers.yahoo.com/dir/?link=listsid=396545433

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]