java.lang.IllegalStateException: Cannot obtain Writer because OutputStream is already in use

Liferay Issues | Waldemar Kłaczyński | 6 years ago
  1. 0

    where use in action response.getOutputStream() FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); PortletResponse portletResponse = (PortletResponse) externalContext.getResponse(); HttpServletResponse response = PortalUtil.getHttpServletResponse(portletResponse); //ReportConfigUtil.compileReport(context, getCompileDir(), raportFileName); File reportFile = new File(ReportConfigUtil.getJasperFilePath(externalContext, getCompileDir(), raportFileName + ".jasper")); JasperPrint jasperPrint = ReportConfigUtil.fillReport(reportFile, params, dataSource); FileBufferedOutputStream fbos = new FileBufferedOutputStream(); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fbos); try { exporter.exportReport(); fbos.close(); if (fbos.size() > 0) { String filename = raportFileName + System.currentTimeMillis() + ".pdf"; response.reset(); response.setContentType("application/pdf"); response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.setContentType("application/force-download"); response.setCharacterEncoding("UTF-8"); response.setContentLength(fbos.size()); ServletOutputStream ouputStream = response.getOutputStream(); try { fbos.writeData(ouputStream); fbos.dispose(); ouputStream.flush(); } finally { if (ouputStream != null) { try { ouputStream.close(); } catch (IOException ex) { } } } //response. } } finally { fbos.close(); fbos.dispose(); } response.flushBuffer(); response.setStatus(HttpServletResponse.SC_OK); facesContext.responseComplete(); The system generates an error: 7:01:45,756 ERROR [[Friendly URL Servlet - Public]] Servlet.service() for servlet Friendly URL Servlet - Public threw exception java.lang.IllegalStateException: Cannot obtain Writer because OutputStream is already in use at com.liferay.portal.kernel.servlet.StringServletResponse.getWriter(StringServletResponse.java:111) at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125) at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118) at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:180) at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118) at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77) at org.apache.jsp.html.common.themes.portal_jsp._jspService(portal_jsp.java:757) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638) at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:543) at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:480) at com.liferay.portal.struts.StrutsUtil.include(StrutsUtil.java:135) at com.liferay.portal.struts.PortalRequestProcessor.doInclude(PortalRequestProcessor.java:265) at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:237) at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:302) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241) at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:152) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

    Liferay Issues | 6 years ago | Waldemar Kłaczyński
    java.lang.IllegalStateException: Cannot obtain Writer because OutputStream is already in use
  2. 0

    where use in action response.getOutputStream() FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); PortletResponse portletResponse = (PortletResponse) externalContext.getResponse(); HttpServletResponse response = PortalUtil.getHttpServletResponse(portletResponse); //ReportConfigUtil.compileReport(context, getCompileDir(), raportFileName); File reportFile = new File(ReportConfigUtil.getJasperFilePath(externalContext, getCompileDir(), raportFileName + ".jasper")); JasperPrint jasperPrint = ReportConfigUtil.fillReport(reportFile, params, dataSource); FileBufferedOutputStream fbos = new FileBufferedOutputStream(); JRPdfExporter exporter = new JRPdfExporter(); exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); exporter.setParameter(JRExporterParameter.OUTPUT_STREAM, fbos); try { exporter.exportReport(); fbos.close(); if (fbos.size() > 0) { String filename = raportFileName + System.currentTimeMillis() + ".pdf"; response.reset(); response.setContentType("application/pdf"); response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "\""); response.setContentType("application/force-download"); response.setCharacterEncoding("UTF-8"); response.setContentLength(fbos.size()); ServletOutputStream ouputStream = response.getOutputStream(); try { fbos.writeData(ouputStream); fbos.dispose(); ouputStream.flush(); } finally { if (ouputStream != null) { try { ouputStream.close(); } catch (IOException ex) { } } } //response. } } finally { fbos.close(); fbos.dispose(); } response.flushBuffer(); response.setStatus(HttpServletResponse.SC_OK); facesContext.responseComplete(); The system generates an error: 7:01:45,756 ERROR [[Friendly URL Servlet - Public]] Servlet.service() for servlet Friendly URL Servlet - Public threw exception java.lang.IllegalStateException: Cannot obtain Writer because OutputStream is already in use at com.liferay.portal.kernel.servlet.StringServletResponse.getWriter(StringServletResponse.java:111) at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125) at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118) at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:180) at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118) at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77) at org.apache.jsp.html.common.themes.portal_jsp._jspService(portal_jsp.java:757) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638) at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:543) at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:480) at com.liferay.portal.struts.StrutsUtil.include(StrutsUtil.java:135) at com.liferay.portal.struts.PortalRequestProcessor.doInclude(PortalRequestProcessor.java:265) at org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:237) at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:302) at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241) at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:152) at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196) at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432) at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)

    Liferay Issues | 6 years ago | Waldemar Kłaczyński
    java.lang.IllegalStateException: Cannot obtain Writer because OutputStream is already in use
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    Simple JSF Ajax causes ViewExpiredException on Weblogic - Forums | Liferay

    liferay.com | 1 year ago
    java.lang.IllegalStateException: Cannot obtain OutputStream because Writer is already in use
  5. 0

    Exception in getting OutputStream from response object - Forums | Liferay

    liferay.com | 8 months ago
    java.lang.IllegalStateException: Cannot obtain Writer because OutputStream is already in use

    Not finding the right solution?
    Take a tour to get the most out of Samebug.

    Tired of useless tips?

    Automated exception search integrated into your IDE

    Root Cause Analysis

    1. java.lang.IllegalStateException

      Cannot obtain Writer because OutputStream is already in use

      at com.liferay.portal.kernel.servlet.StringServletResponse.getWriter()
    2. Liferay Portal Service
      StringServletResponse.getWriter
      1. com.liferay.portal.kernel.servlet.StringServletResponse.getWriter(StringServletResponse.java:111)
      1 frame
    3. GWT dev
      JspFactoryImpl.releasePageContext
      1. org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
      2. org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
      3. org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:180)
      4. org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118)
      5. org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77)
      5 frames
    4. org.apache.jsp
      portal_jsp._jspService
      1. org.apache.jsp.html.common.themes.portal_jsp._jspService(portal_jsp.java:757)
      1 frame
    5. GWT dev
      HttpJspBase.service
      1. org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      1 frame
    6. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      1 frame
    7. GWT dev
      JspServlet.service
      1. org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
      2. org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
      3. org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
      3 frames
    8. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      1 frame
    9. Glassfish Core
      ApplicationDispatcher.include
      1. org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      2. org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      3. org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
      4. org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:543)
      5. org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:480)
      5 frames
    10. Liferay Portal Impl
      PortalRequestProcessor.doInclude
      1. com.liferay.portal.struts.StrutsUtil.include(StrutsUtil.java:135)
      2. com.liferay.portal.struts.PortalRequestProcessor.doInclude(PortalRequestProcessor.java:265)
      2 frames
    11. struts
      RequestProcessor.process
      1. org.apache.struts.tiles.TilesRequestProcessor.processTilesDefinition(TilesRequestProcessor.java:237)
      2. org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:302)
      3. org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:241)
      3 frames
    12. Liferay Portal Impl
      PortalRequestProcessor.process
      1. com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:152)
      1 frame
    13. struts
      ActionServlet.doPost
      1. org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
      2. org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
      2 frames
    14. JavaServlet
      HttpServlet.service
      1. javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      1 frame