perwendel / spark

A simple expressive web framework for java. Spark has a kotlin DSL https://github.com/perwendel/spark-kotlin
Apache License 2.0
9.65k stars 1.56k forks source link

java.io.IOException: Closed while trying to send binary content in response #18

Closed kronar closed 11 years ago

kronar commented 12 years ago

Following code

@Override public Object handle(Request request, Response response) { byte[] result = createChartImage(findByBMetric); response.status(200); response.type(JPG_CONTENT_TYPE); final HttpServletResponse rawResponse = response.raw(); rawResponse.setContentType("image/jpeg"); rawResponse.setContentLength(result.length); final ServletOutputStream outputStream = rawResponse .getOutputStream();

        outputStream.write(result);
        return result;

}

works but produces warning in console

2012-05-03 14:00:49,323 WARN - log - /stabilitygraph?metric=ru.selenium.express.web.CheckMessaging.clearRecentMessagesUser2: java.io.IOException: Closed

Possibly I writing binary content in a wrong way, please show me the correct one.

dol commented 12 years ago

Take a look at this example ( http://schipplock.de/projects/2011/005_AutoScanner/src/src/com/schipplock/autoscanner/AutoScanner.java ). Helped me to write raw data.

perwendel commented 11 years ago

I've located the problem. There's a problem in the HTTP filter where it doesn't understand that the outputstream has been consumed and tries to use it. A solution could be to wrap the Outputstream and flag when close has been called. What do you guys think?

perwendel commented 11 years ago

Fixed by isCommited check in MatcherFilter.