You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Alfred Nathaniel <an...@apache.org> on 2008/11/02 18:49:43 UTC

Re: Sending different responses based on some conditions

On Wed, 2008-10-29 at 17:15 +0100, Kjetil Kjernsmo wrote:
> Hi all,
> 
> I have a StatelessAppleController which does some simple checking on the data 
> it receives. In most cases, it should sendPage, but there are a few rare 
> situations where it should redirect or return a 502 HTTP code. 
> 
> This part of the code looks like this:
> 
>       if ("explain".equalsIgnoreCase(operation) || 
> req.getCocoonRequest().getParameters().size() == 0) {
>           // We only need to retrieve the explain record, which is best done 
> by a redirect to the server
>           res.redirectTo(query);
>       }
> 
>       DOMParser parser = new DOMParser();
> 
>       try {
>           parser.parse(query);
>       } catch (Exception e) {
>   //        logger.fatal("SRUClient received an invalid response from the 
> server.");
>           res.sendStatus(502);
>           e.printStackTrace();
>       }
> 
> but I get
> java.lang.IllegalStateException: It's not possible to call redirectTo() and 
> sendStatus() at the same response object.
> 
> Surely, this must be possible to achieve, I guess I just did it the wrong way. 
> How can I do this?
> 
> 
> Kind regards 
> 
> Kjetil Kjernsmo

All res.redirectTo(query) does is to set the HTTP Location header.
Otherwise control flow continues normally.  You should put the parsing
part into an else clause.

HTH, Alfred.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org