ClientAbortException: java.io.IOException: Broken pipe

可紊 提交于 2019-12-13 05:15:03

问题


I have the following code to send a jpg image on the outputstream in Grails. I use this block inside a cache headers generate{...} statement.

                            def imageByteArray = // some image byte []
            response.setContentType("image/jpeg")
            response.setHeader("Content-disposition", "filename=\"${imageName}${imageExtension}\"")
            response.setContentLength(imageByteArray.size())

            def outputStream = null
            try {
                outputStream = response.outputStream
                outputStream << imageByteArray
            } catch (IOException e){
                log.error('getImage() - Canceled download?', e)
            } finally {
                if (outputStream != null){
                    try {
                        outputStream.close()
                    } catch (IOException e) {
                        log.error('Exception on close', e)
                    }
                }
                return
            }

I get the following error:

2013-09-17 12:51:55,033 [http-nio-80-exec-15] ERROR test.ItemController  - getImage() - Canceled download?
ClientAbortException:  java.io.IOException: Broken pipe
    at test.ItemController$_getImage_closure2_closure11.doCall(ItemController.groovy:287)
    at com.grailsrocks.cacheheaders.CacheHeadersService.callClosure(CacheHeadersService.groovy:209)
    at com.grailsrocks.cacheheaders.CacheHeadersService.withCacheHeaders(CacheHeadersService.groovy:201)
    at CacheHeadersGrailsPlugin$_addCacheMethods_closure7_closure11.doCall(CacheHeadersGrailsPlugin.groovy:61)
    at test.ItemController.getImage(ItemController.groovy:204)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at test.ItemController.getFacebookImage(ItemController.groovy:98)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:200)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:724)

I could not figure out what to change in order to avoid this error. I also tried to use flush() on the outputstream but it did not work. What to do?

From the error log I can see that "Canceled download?" is thrown thus I suppose that something went wrong on the write operation?

来源:https://stackoverflow.com/questions/18848588/clientabortexception-java-io-ioexception-broken-pipe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!