You're calling response.setHeader()
after you've already sent the data to the response stream. If the response stream buffer wasn't big enough to handle all of that data, it would have to write the headers out in order to write the content. Frankly I'm surprised that setHeader
isn't throwing an exception to say that the response body has already been started, but anyway...
Just move the header setting part to before the call to IOUtils.copy
.
I would also strongly recommend specifying a character encoding in the String.getBytes()
call, and specifying the same encoding in the response header. (I generally use UTF-8.)