java.lang.IllegalStateException error while rendering a file output

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

java.lang.IllegalStateException error while rendering a file output

bilgehan
Hi

On a production system with Grails 2.2.3 running on Tomcat 7, i sometime get 

IllegalStateException occurred when processing request: [GET]
java.lang.IllegalStateException: getOutputStream() has already been called for this response error on log files. 

The code is:

byte[] docFile = docInstance.docContent
response.contentType = "application/pdf"
response.outputStream << docFile

Error doesn't happen always. Does anyone has such a problem? I found this bug report but not sure my case is related because i don't use render file shortcut


Thanks

Bilgehan
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException error while rendering a file output

sergiomichels
Do you have something after response.outputStream << docFile ?

--
Sérgio Michels


On Fri, Nov 29, 2013 at 8:14 AM, Bilgehan Maraş <[hidden email]> wrote:
Hi

On a production system with Grails 2.2.3 running on Tomcat 7, i sometime get 

IllegalStateException occurred when processing request: [GET]
java.lang.IllegalStateException: getOutputStream() has already been called for this response error on log files. 

The code is:

byte[] docFile = docInstance.docContent
response.contentType = "application/pdf"
response.outputStream << docFile

Error doesn't happen always. Does anyone has such a problem? I found this bug report but not sure my case is related because i don't use render file shortcut


Thanks

Bilgehan

Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException error while rendering a file output

bilgehan
No, that's all.

--
Bilgehan Maraş

On 30 November 2013 Saturday at 00:53, Sergio Michels wrote:

Do you have something after response.outputStream << docFile ?

--
Sérgio Michels


On Fri, Nov 29, 2013 at 8:14 AM, Bilgehan Maraş <[hidden email]> wrote:
Hi

On a production system with Grails 2.2.3 running on Tomcat 7, i sometime get 

IllegalStateException occurred when processing request: [GET]
java.lang.IllegalStateException: getOutputStream() has already been called for this response error on log files. 

The code is:

byte[] docFile = docInstance.docContent
response.contentType = "application/pdf"
response.outputStream << docFile

Error doesn't happen always. Does anyone has such a problem? I found this bug report but not sure my case is related because i don't use render file shortcut


Thanks

Bilgehan


Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException error while rendering a file output

Steve Hummingbird
In reply to this post by bilgehan
Yeah, I am having a similar problem since quite some time. I have posted to this list, but haven’t had much luck. I am still facing that issue. This is the mail I had sent back then:

I am trying to return a file in a controller, which I have returned from GridFS.
This is the relevant code from my controller:


def download(String versionId) {

GridFSDBFile dbFile = versionService.getFile(versionId)
response.setContentType(dbFile.getContentType())
response.setHeader("Content-disposition", "attachment;filename=${dbFile.getFilename()}")
response.outputStream << dbFile.inputStream
}


The service looks like this:

def getFile(ObjectId id) {
return gridfs.findOne(id)
}

This works well most of the time. However, I discovered that when I use Safari on an iPhone to call my Service, I randomly see the following Exception in my log. The file still downloads fine.
Any ideas how I could work around this or what I might be doing wrong?

Thanks, 
Steve


Error 2013-09-02 21:32:16,362 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - SocketException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
Broken pipe. Stacktrace follows:
Message: Broken pipe
  Line | Method
->>  92 | socketWrite in java.net.SocketOutputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   136 | write       in     ''
|   168 | download .  in org.app.core.VersionController$$EOGJLVJw
|   895 | runTask     in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . . . in     ''
^   680 | run         in java.lang.Thread
| Error 2013-09-02 21:32:16,372 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - IllegalStateException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
getOutputStream() has already been called for this response. Stacktrace follows:
Message: Error processing GroovyPageView: getOutputStream() has already been called for this response
  Line | Method
->> 639 | runTask in /grails-app/views/error.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Caused by IllegalStateException: getOutputStream() has already been called for this response
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,375 [http-bio-8080-exec-26] ERROR [/App].[grails]  - Servlet.service() for servlet grails threw exception
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,377 [http-bio-8080-exec-26] ERROR [/App].[default]  - Servlet.service() for servlet [default] in context with path [/App] threw exception [Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: getOutputStream() has already been called for this response] with root cause
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
——————————————————————————————————


On 29 Nov 2013, at 11:14, Bilgehan Maraş <[hidden email]> wrote:

Hi

On a production system with Grails 2.2.3 running on Tomcat 7, i sometime get 

IllegalStateException occurred when processing request: [GET]
java.lang.IllegalStateException: getOutputStream() has already been called for this response error on log files. 

The code is:

byte[] docFile = docInstance.docContent
response.contentType = "application/pdf"
response.outputStream << docFile

Error doesn't happen always. Does anyone has such a problem? I found this bug report but not sure my case is related because i don't use render file shortcut


Thanks

Bilgehan

Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException error while rendering a file output

sergiomichels
If some of you run grails prod run-app, the problem appears?

--
Sérgio Michels


On Sat, Nov 30, 2013 at 2:40 PM, Steve Hummingbird <[hidden email]> wrote:
Yeah, I am having a similar problem since quite some time. I have posted to this list, but haven’t had much luck. I am still facing that issue. This is the mail I had sent back then:

I am trying to return a file in a controller, which I have returned from GridFS.
This is the relevant code from my controller:


def download(String versionId) {

GridFSDBFile dbFile = versionService.getFile(versionId)
response.setContentType(dbFile.getContentType())
response.setHeader("Content-disposition", "attachment;filename=${dbFile.getFilename()}")
response.outputStream << dbFile.inputStream
}


The service looks like this:

def getFile(ObjectId id) {
return gridfs.findOne(id)
}

This works well most of the time. However, I discovered that when I use Safari on an iPhone to call my Service, I randomly see the following Exception in my log. The file still downloads fine.
Any ideas how I could work around this or what I might be doing wrong?

Thanks, 
Steve


Error 2013-09-02 21:32:16,362 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - SocketException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
Broken pipe. Stacktrace follows:
Message: Broken pipe
  Line | Method
->>  92 | socketWrite in java.net.SocketOutputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   136 | write       in     ''
|   168 | download .  in org.app.core.VersionController$$EOGJLVJw
|   895 | runTask     in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . . . in     ''
^   680 | run         in java.lang.Thread
| Error 2013-09-02 21:32:16,372 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - IllegalStateException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
getOutputStream() has already been called for this response. Stacktrace follows:
Message: Error processing GroovyPageView: getOutputStream() has already been called for this response
  Line | Method
->> 639 | runTask in /grails-app/views/error.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Caused by IllegalStateException: getOutputStream() has already been called for this response
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,375 [http-bio-8080-exec-26] ERROR [/App].[grails]  - Servlet.service() for servlet grails threw exception
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,377 [http-bio-8080-exec-26] ERROR [/App].[default]  - Servlet.service() for servlet [default] in context with path [/App] threw exception [Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: getOutputStream() has already been called for this response] with root cause
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
——————————————————————————————————


On 29 Nov 2013, at 11:14, Bilgehan Maraş <[hidden email]> wrote:

Hi

On a production system with Grails 2.2.3 running on Tomcat 7, i sometime get 

IllegalStateException occurred when processing request: [GET]
java.lang.IllegalStateException: getOutputStream() has already been called for this response error on log files. 

The code is:

byte[] docFile = docInstance.docContent
response.contentType = "application/pdf"
response.outputStream << docFile

Error doesn't happen always. Does anyone has such a problem? I found this bug report but not sure my case is related because i don't use render file shortcut


Thanks

Bilgehan


Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException error while rendering a file output

Steve Hummingbird
In my case using 'grails prod run-app’ instead of 'grails run-app’ seem to not make any difference.


On 30 Nov 2013, at 20:21, Sergio Michels <[hidden email]> wrote:

If some of you run grails prod run-app, the problem appears?

--
Sérgio Michels


On Sat, Nov 30, 2013 at 2:40 PM, Steve Hummingbird <[hidden email]> wrote:
Yeah, I am having a similar problem since quite some time. I have posted to this list, but haven’t had much luck. I am still facing that issue. This is the mail I had sent back then:

I am trying to return a file in a controller, which I have returned from GridFS.
This is the relevant code from my controller:


def download(String versionId) {

GridFSDBFile dbFile = versionService.getFile(versionId)
response.setContentType(dbFile.getContentType())
response.setHeader("Content-disposition", "attachment;filename=${dbFile.getFilename()}")
response.outputStream << dbFile.inputStream
}


The service looks like this:

def getFile(ObjectId id) {
return gridfs.findOne(id)
}

This works well most of the time. However, I discovered that when I use Safari on an iPhone to call my Service, I randomly see the following Exception in my log. The file still downloads fine.
Any ideas how I could work around this or what I might be doing wrong?

Thanks, 
Steve


Error 2013-09-02 21:32:16,362 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - SocketException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
Broken pipe. Stacktrace follows:
Message: Broken pipe
  Line | Method
->>  92 | socketWrite in java.net.SocketOutputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   136 | write       in     ''
|   168 | download .  in org.app.core.VersionController$$EOGJLVJw
|   895 | runTask     in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . . . in     ''
^   680 | run         in java.lang.Thread
| Error 2013-09-02 21:32:16,372 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - IllegalStateException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
getOutputStream() has already been called for this response. Stacktrace follows:
Message: Error processing GroovyPageView: getOutputStream() has already been called for this response
  Line | Method
->> 639 | runTask in /grails-app/views/error.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Caused by IllegalStateException: getOutputStream() has already been called for this response
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,375 [http-bio-8080-exec-26] ERROR [/App].[grails]  - Servlet.service() for servlet grails threw exception
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,377 [http-bio-8080-exec-26] ERROR [/App].[default]  - Servlet.service() for servlet [default] in context with path [/App] threw exception [Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: getOutputStream() has already been called for this response] with root cause
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
——————————————————————————————————


On 29 Nov 2013, at 11:14, Bilgehan Maraş <[hidden email]> wrote:

Hi

On a production system with Grails 2.2.3 running on Tomcat 7, i sometime get 

IllegalStateException occurred when processing request: [GET]
java.lang.IllegalStateException: getOutputStream() has already been called for this response error on log files. 

The code is:

byte[] docFile = docInstance.docContent
response.contentType = "application/pdf"
response.outputStream << docFile

Error doesn't happen always. Does anyone has such a problem? I found this bug report but not sure my case is related because i don't use render file shortcut


Thanks

Bilgehan



Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException error while rendering a file output

Lari Hotari -
In reply to this post by Steve Hummingbird

Add these lines as the last ones in the action method:
webRequest.renderView = false
return null

-Lari

30.11.2013 18.41 kirjoitti "Steve Hummingbird" <[hidden email]>:
Yeah, I am having a similar problem since quite some time. I have posted to this list, but haven’t had much luck. I am still facing that issue. This is the mail I had sent back then:

I am trying to return a file in a controller, which I have returned from GridFS.
This is the relevant code from my controller:


def download(String versionId) {

GridFSDBFile dbFile = versionService.getFile(versionId)
response.setContentType(dbFile.getContentType())
response.setHeader("Content-disposition", "attachment;filename=${dbFile.getFilename()}")
response.outputStream << dbFile.inputStream
}


The service looks like this:

def getFile(ObjectId id) {
return gridfs.findOne(id)
}

This works well most of the time. However, I discovered that when I use Safari on an iPhone to call my Service, I randomly see the following Exception in my log. The file still downloads fine.
Any ideas how I could work around this or what I might be doing wrong?

Thanks, 
Steve


Error 2013-09-02 21:32:16,362 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - SocketException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
Broken pipe. Stacktrace follows:
Message: Broken pipe
  Line | Method
->>  92 | socketWrite in java.net.SocketOutputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   136 | write       in     ''
|   168 | download .  in org.app.core.VersionController$$EOGJLVJw
|   895 | runTask     in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . . . in     ''
^   680 | run         in java.lang.Thread
| Error 2013-09-02 21:32:16,372 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - IllegalStateException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
getOutputStream() has already been called for this response. Stacktrace follows:
Message: Error processing GroovyPageView: getOutputStream() has already been called for this response
  Line | Method
->> 639 | runTask in /grails-app/views/error.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Caused by IllegalStateException: getOutputStream() has already been called for this response
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,375 [http-bio-8080-exec-26] ERROR [/App].[grails]  - Servlet.service() for servlet grails threw exception
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,377 [http-bio-8080-exec-26] ERROR [/App].[default]  - Servlet.service() for servlet [default] in context with path [/App] threw exception [Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: getOutputStream() has already been called for this response] with root cause
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
——————————————————————————————————


On 29 Nov 2013, at 11:14, Bilgehan Maraş <[hidden email]> wrote:

Hi

On a production system with Grails 2.2.3 running on Tomcat 7, i sometime get 

IllegalStateException occurred when processing request: [GET]
java.lang.IllegalStateException: getOutputStream() has already been called for this response error on log files. 

The code is:

byte[] docFile = docInstance.docContent
response.contentType = "application/pdf"
response.outputStream << docFile

Error doesn't happen always. Does anyone has such a problem? I found this bug report but not sure my case is related because i don't use render file shortcut


Thanks

Bilgehan

Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException error while rendering a file output

Steve Hummingbird
No luck on my side unfortunately.
My controller method now ends like this:

 response.outputStream << dbFile.inputStream // this is line 205 btw...
 webRequest.renderView = false
 return null

However, I just noticed that the stack trace has changed since my last post a couple of months ago and now mentions springsecurity. Maybe this is related to the update of the spring security core plugin?
But, the trace is the same, with and without the two suggested lines added.

| Error 2013-11-30 21:28:16,445 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver  - SocketException occurred when processing request: [GET] /myApp/song/529a1357c026ce2a23e20378/version/529a1357c026ce2a23e20379/audio
Broken pipe. Stacktrace follows:
Message: Broken pipe
    Line | Method
->>  113 | socketWrite in java.net.SocketOutputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    159 | write       in     ''
|    205 | download .  in org.myApp.core.RevisionController$$EOOi1DVA
|     53 | doFilter    in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|     49 | doFilter .  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter    in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker . in java.util.concurrent.ThreadPoolExecutor
|    615 | run         in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run . . . . in java.lang.Thread
| Error 2013-11-30 21:28:16,456 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver  - IllegalStateException occurred when processing request: [GET] /myApp/song/529a1357c026ce2a23e20378/version/529a1357c026ce2a23e20379/audio
getOutputStream() has already been called for this response. Stacktrace follows:
Message: Error processing GroovyPageView: getOutputStream() has already been called for this response
    Line | Method
->>  639 | doFilter  in /Users/stefan/Code/Grails/myApp/grails-app/views/error.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Caused by IllegalStateException: getOutputStream() has already been called for this response
->>   53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
| Error 2013-11-30 21:28:16,464 [http-bio-8080-exec-9] ERROR [/myApp].[grails]  - Servlet.service() for servlet grails threw exception
Message: getOutputStream() has already been called for this response
    Line | Method
->>   53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
| Error 2013-11-30 21:28:16,466 [http-bio-8080-exec-9] ERROR [/myApp].[default]  - Servlet.service() for servlet [default] in context with path [/myApp] threw exception [Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: getOutputStream() has already been called for this response] with root cause
Message: getOutputStream() has already been called for this response
    Line | Method
->>   53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread

On 30 Nov 2013, at 21:08, Lari Hotari <[hidden email]> wrote:

Add these lines as the last ones in the action method:
webRequest.renderView = false
return null

-Lari

30.11.2013 18.41 kirjoitti "Steve Hummingbird" <[hidden email]>:
Yeah, I am having a similar problem since quite some time. I have posted to this list, but haven’t had much luck. I am still facing that issue. This is the mail I had sent back then:

I am trying to return a file in a controller, which I have returned from GridFS.
This is the relevant code from my controller:


def download(String versionId) {

GridFSDBFile dbFile = versionService.getFile(versionId)
response.setContentType(dbFile.getContentType())
response.setHeader("Content-disposition", "attachment;filename=${dbFile.getFilename()}")
response.outputStream << dbFile.inputStream
}


The service looks like this:

def getFile(ObjectId id) {
return gridfs.findOne(id)
}

This works well most of the time. However, I discovered that when I use Safari on an iPhone to call my Service, I randomly see the following Exception in my log. The file still downloads fine.
Any ideas how I could work around this or what I might be doing wrong?

Thanks, 
Steve


Error 2013-09-02 21:32:16,362 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - SocketException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
Broken pipe. Stacktrace follows:
Message: Broken pipe
  Line | Method
->>  92 | socketWrite in java.net.SocketOutputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   136 | write       in     ''
|   168 | download .  in org.app.core.VersionController$$EOGJLVJw
|   895 | runTask     in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . . . in     ''
^   680 | run         in java.lang.Thread
| Error 2013-09-02 21:32:16,372 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - IllegalStateException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
getOutputStream() has already been called for this response. Stacktrace follows:
Message: Error processing GroovyPageView: getOutputStream() has already been called for this response
  Line | Method
->> 639 | runTask in /grails-app/views/error.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Caused by IllegalStateException: getOutputStream() has already been called for this response
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,375 [http-bio-8080-exec-26] ERROR [/App].[grails]  - Servlet.service() for servlet grails threw exception
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,377 [http-bio-8080-exec-26] ERROR [/App].[default]  - Servlet.service() for servlet [default] in context with path [/App] threw exception [Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: getOutputStream() has already been called for this response] with root cause
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
——————————————————————————————————


On 29 Nov 2013, at 11:14, Bilgehan Maraş <[hidden email]> wrote:

Hi

On a production system with Grails 2.2.3 running on Tomcat 7, i sometime get 

IllegalStateException occurred when processing request: [GET]
java.lang.IllegalStateException: getOutputStream() has already been called for this response error on log files. 

The code is:

byte[] docFile = docInstance.docContent
response.contentType = "application/pdf"
response.outputStream << docFile

Error doesn't happen always. Does anyone has such a problem? I found this bug report but not sure my case is related because i don't use render file shortcut


Thanks

Bilgehan


Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException error while rendering a file output

Steve Hummingbird
Hm, it seems that I just found something while I was debugging a related issue when using howler.js. I was serving a mp3 file and had the following line in my controller, which I must have copied from somewhere when writing the controller:

response.setHeader('Content-disposition', 'attachment;filename='+ dbFile.getFilename())

Since I removed that line, I have never seen that exception. I will report back in case that exception should reappear, as I haven’t tested that for very long right now...


On 30 Nov 2013, at 21:35, Steve Hummingbird <[hidden email]> wrote:

No luck on my side unfortunately.
My controller method now ends like this:

 response.outputStream << dbFile.inputStream // this is line 205 btw...
 webRequest.renderView = false
 return null

However, I just noticed that the stack trace has changed since my last post a couple of months ago and now mentions springsecurity. Maybe this is related to the update of the spring security core plugin?
But, the trace is the same, with and without the two suggested lines added.

| Error 2013-11-30 21:28:16,445 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver  - SocketException occurred when processing request: [GET] /myApp/song/529a1357c026ce2a23e20378/version/529a1357c026ce2a23e20379/audio
Broken pipe. Stacktrace follows:
Message: Broken pipe
    Line | Method
->>  113 | socketWrite in java.net.SocketOutputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    159 | write       in     ''
|    205 | download .  in org.myApp.core.RevisionController$$EOOi1DVA
|     53 | doFilter    in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|     49 | doFilter .  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter    in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker . in java.util.concurrent.ThreadPoolExecutor
|    615 | run         in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run . . . . in java.lang.Thread
| Error 2013-11-30 21:28:16,456 [http-bio-8080-exec-9] ERROR errors.GrailsExceptionResolver  - IllegalStateException occurred when processing request: [GET] /myApp/song/529a1357c026ce2a23e20378/version/529a1357c026ce2a23e20379/audio
getOutputStream() has already been called for this response. Stacktrace follows:
Message: Error processing GroovyPageView: getOutputStream() has already been called for this response
    Line | Method
->>  639 | doFilter  in /Users/stefan/Code/Grails/myApp/grails-app/views/error.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
Caused by IllegalStateException: getOutputStream() has already been called for this response
->>   53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
| Error 2013-11-30 21:28:16,464 [http-bio-8080-exec-9] ERROR [/myApp].[grails]  - Servlet.service() for servlet grails threw exception
Message: getOutputStream() has already been called for this response
    Line | Method
->>   53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
| Error 2013-11-30 21:28:16,466 [http-bio-8080-exec-9] ERROR [/myApp].[default]  - Servlet.service() for servlet [default] in context with path [/myApp] threw exception [Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: getOutputStream() has already been called for this response] with root cause
Message: getOutputStream() has already been called for this response
    Line | Method
->>   53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|     49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread

On 30 Nov 2013, at 21:08, Lari Hotari <[hidden email]> wrote:

Add these lines as the last ones in the action method:
webRequest.renderView = false
return null

-Lari

30.11.2013 18.41 kirjoitti "Steve Hummingbird" <[hidden email]>:
Yeah, I am having a similar problem since quite some time. I have posted to this list, but haven’t had much luck. I am still facing that issue. This is the mail I had sent back then:

I am trying to return a file in a controller, which I have returned from GridFS.
This is the relevant code from my controller:


def download(String versionId) {

GridFSDBFile dbFile = versionService.getFile(versionId)
response.setContentType(dbFile.getContentType())
response.setHeader("Content-disposition", "attachment;filename=${dbFile.getFilename()}")
response.outputStream << dbFile.inputStream
}


The service looks like this:

def getFile(ObjectId id) {
return gridfs.findOne(id)
}

This works well most of the time. However, I discovered that when I use Safari on an iPhone to call my Service, I randomly see the following Exception in my log. The file still downloads fine.
Any ideas how I could work around this or what I might be doing wrong?

Thanks, 
Steve


Error 2013-09-02 21:32:16,362 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - SocketException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
Broken pipe. Stacktrace follows:
Message: Broken pipe
  Line | Method
->>  92 | socketWrite in java.net.SocketOutputStream
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   136 | write       in     ''
|   168 | download .  in org.app.core.VersionController$$EOGJLVJw
|   895 | runTask     in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . . . in     ''
^   680 | run         in java.lang.Thread
| Error 2013-09-02 21:32:16,372 [http-bio-8080-exec-26] ERROR errors.GrailsExceptionResolver  - IllegalStateException occurred when processing request: [GET] /App/file/522348d4036417c84d65d9b4/version/522348d4036417c84d65d9b5
getOutputStream() has already been called for this response. Stacktrace follows:
Message: Error processing GroovyPageView: getOutputStream() has already been called for this response
  Line | Method
->> 639 | runTask in /grails-app/views/error.gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Caused by IllegalStateException: getOutputStream() has already been called for this response
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,375 [http-bio-8080-exec-26] ERROR [/App].[grails]  - Servlet.service() for servlet grails threw exception
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
| Error 2013-09-02 21:32:16,377 [http-bio-8080-exec-26] ERROR [/App].[default]  - Servlet.service() for servlet [default] in context with path [/App] threw exception [Request processing failed; nested exception is org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: getOutputStream() has already been called for this response] with root cause
Message: getOutputStream() has already been called for this response
  Line | Method
->>  14 | run     in Users_steve_Projects__App_grails_app_views_error_gsp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker
|   918 | run . . in     ''
^   680 | run     in java.lang.Thread
——————————————————————————————————


On 29 Nov 2013, at 11:14, Bilgehan Maraş <[hidden email]> wrote:

Hi

On a production system with Grails 2.2.3 running on Tomcat 7, i sometime get 

IllegalStateException occurred when processing request: [GET]
java.lang.IllegalStateException: getOutputStream() has already been called for this response error on log files. 

The code is:

byte[] docFile = docInstance.docContent
response.contentType = "application/pdf"
response.outputStream << docFile

Error doesn't happen always. Does anyone has such a problem? I found this bug report but not sure my case is related because i don't use render file shortcut


Thanks

Bilgehan