What Chris has said is right.

But what Jose Luis asked for is a inject mechanism likes
ParameterAware which takes all the request params through one Map, but
not through several property.

So I think the simpler (also more Quick And Dirty) way is:

(1)Create a interface, likes:
public interface HeaderAware {
        /**
         * Sets the map of request headers in the implementing class.
         *
         * @param headers
         *            a Map of headers (name/value Strings).
         */
        public void setHeaders(final Map<String, String[]> headers);
}

(2)implement this interface in your action class (or the common super
class of all of your actions)

(3)create a interceptor, which inject the headers map to your action
class likes what ServletConfigInterceptor is doing,
the code will likes:

public class RequestHeaderInterceptor extends AbstractInterceptor {
        @Override
        public String intercept(final ActionInvocation invocation) throws 
Exception {
                final Object action = invocation.getAction();

                if (action instanceof HeaderAware) {
                        Map<String, String[]> requestHeaders =
                                        
this.getRequestHeaders(ServletActionContext.getRequest());
                        ((HeaderAware) action).setHeaders(requestHeaders);
                }

                return invocation.invoke();
        }

        private Map<String, String[]> getRequestHeaders(
                        final HttpServletRequest request) {
                Map<String, String[]> headers = new HashMap<String, String[]>();

                // TODO: retrieve all the request headers by
                // HttpServletRequest.getHeaderNames(), 
HttpServletRequest.getHeaders()
                // and put them into Map

                return headers;
        }
}

(4)add RequestHeaderInterceptor into your interceptor-stack



2010/10/26 Chris Pratt <thechrispr...@gmail.com>:
> As far as I'm aware, there's not.  But it wouldn't be hard to write one.
> You could use the ParameterInterceptor as a pattern, but have it take it's
> data from the headers rather than the parameters and you'd be done in 1/2
> hr.  You could get fancier, to make sure Parameters and Headers with the
> same name don't clash, and use an Annotation to identify which headers to
> inject into which methods, but that would definitely take more than 1/2 hr.
> =8^)
>  (*Chris*)
>

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

Reply via email to