--- On Thu, 6/12/08, Page <[EMAIL PROTECTED]> wrote:
> I have an interceptor that I'm writing to handle all
> the needs of the client
> side framework and a second that manages the json objects
> called (not
> clever) JsonInterceptor. It grabs json strings from the
> header and
> instantiates them into JSONObjects which it stores in the
> request before the
> invoke. After the invoke I wanted to check the value stack
> for a particular
> object and if it exists, add a new X-JSON header to the
> response.
>
> Problem: it seems I can't alter the response. It
> doesn't give me an error if
> I user addHeader - but if I check for the header
> immediately after with
> containsHeader, it doesn't exist. below is a stripped
> down version of the
> interceptor
>
>
>
>
>
> public String intercept(ActionInvocation actInv) throws
> Exception {
>
> // ...checks header and adds objects from X-JSON
> header to request
> attributes
>
> //-------- BEFORE -----------
> String result = actInv.invoke();
> //-------- AFTER -----------
>
> //check for response object. If one doesn't
> exist, add default 200
> response
> SnipsResponse snipResp =
> (SnipsResponse)actInv.getStack().findValue("snipsResponse");
> if (snipResp == null) {
> snipResp = new
> SnipsResponse(200,"Autogenerated OK response");
>
> }
> //get the response
> HttpServletResponse response =
> (HttpServletResponse)actInv.getInvocationContext().get(StrutsStatics.HTTP_RESPONSE);
> if (response==null) {
> LOG.error("Unable to retrieve
> HttpServletResponse from invocation
> context");
> } else {
> response.addHeader("X-JSON",
> snipResp.getJSONString());
> if (response.containsHeader("X-JSON")) {
> LOG.debug("Added X-JSON header:
> "+snipResp.getJSONString());
> } else LOG.debug("adding header
> failed");
>
> }
>
> return result;
> }
http://struts.apache.org/2.x/docs/writing-interceptors.html
The result has already been rendered after the invoke, so header modification
would be a bit superfluous ;)
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]