users@grizzly.java.net

Sending response headers from a filter

From: Igor Minar <iiminar_at_gmail.com>
Date: Sat, 2 Aug 2008 17:18:17 -0700

Hi Guys,

I'm working on an async filter for grizzly (glassfish 9.1_02) and I
ran into a problem when trying to set headers in the filter.

I set headers in my filter like this:

public boolean doFilter(AsyncExecutor asyncExecutor) {
         AsyncProcessorTask apt =
(AsyncProcessorTask)asyncExecutor.getAsyncTask();
         DefaultProcessorTask task = (DefaultProcessorTask)
apt.getProcessorTask();

         task.invokeAdapter();

        Response response = task.getRequest().getResponse();

         ...

         response.setContentType("application/octet-stream");
         response.setContentLength((int) file.length());

         // or alternatively:
         //response.setHeader("Content-Length", 1234);
         //response.setHeader("Content-Type", "application/octet-
stream");

         ...
         return false;
}

But no matter what I do, the request is sent without headers:

$ wget -O /dev/null http://localhost:8080/test.jsp
--17:12:11-- http://localhost:8080/test.jsp
            => `/dev/null'
Resolving localhost... 127.0.0.1, ::1, fe80::1
Connecting to localhost|127.0.0.1|:8080... connected.
HTTP request sent, awaiting response... 200 No headers, assuming HTTP/
0.9
...


Any idea what I'm doing wrong?

Is the response object retrieved via "task.getRequest().getResponse()"
a writable response instance?

thanks,
Igor