Simply return a StreamResponse
(http://tapestry.apache.org/tapestry5/guide/pagenav.html). I use a
custom StreamResponse which you can construct with a specific status
code:

public class TextStreamResponseWithStatus extends TextStreamResponse {
    private final int statusCode;

    public TextStreamResponseWithStatus(String contentType, String
text, int statusCode) {
        super(contentType, text);
        this.statusCode = statusCode;

    }

    @Override
    public void prepareResponse(Response response) {
        super.prepareResponse(response);
        response.setStatus(statusCode);
    }
}

Kalle


On Thu, Feb 11, 2010 at 10:04 AM, xfile80303 <l...@grokers.net> wrote:
>
> Hi all,
>
> I'm trying to understand how to send a specific HTTP error code to the
> client in the response, and I'm running into a bit of a snag.
>
> I thought it would be as simple as:
>
> @Inject RequestGlobals requestGlobals;
> HttpServletResponse httpResponse = requestGlobals.getHTTPServletResponse();
> httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN, "Forbidden");
>
> But when I do this, I get a NullPointerException from the Tapestry
> Internals:
>
> java.lang.NullPointerException
>        at
> org.apache.tapestry5.internal.services.ResponseCompressionAnalyzerImpl.isCompressable(ResponseCompressionAnalyzerImpl.java:65)
>        at
> $ResponseCompressionAnalyzer_126be2d6156.isCompressable($ResponseCompressionAnalyzer_126be2d6156.java)
>        at
> org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.openResponseOutputStream(BufferedGZipOutputStream.java:77)
>        at
> org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.checkForCutover(BufferedGZipOutputStream.java:70)
>        at
> org.apache.tapestry5.internal.gzip.BufferedGZipOutputStream.write(BufferedGZipOutputStream.java:116)
>
> Am I doing this incorrectly?  I'd appreciate your suggestions and insight.
>
> Thanks,
>
> Levi
> --
> View this message in context: 
> http://n2.nabble.com/T5-1-How-To-Send-HTTP-Error-as-Response-tp4556292p4556292.html
> Sent from the Tapestry Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

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

Reply via email to