Fix java.lang.IllegalStateException: Response has already been written