title: Problem to display a pdf from my JSF Portlet of Liferay
body: <p>I use liferay 5.2 with jsf-portlet.</p>
  
  <p>From the page I want to press a button to generate one PDF.
  In managedbean i build pdf and I want to show it in response.</p>
  
  <p>In a <code>ByteArrayOutputStream</code> named <code>outputStream</code> i have my pdf built with JasperReport.</p>
  
  <p>I write:</p>
  
  <pre><code>   PortletResponse portletResponse = (PortletResponse)externalCtx.getResponse(); 
     HttpServletResponse httpResponse = PortalUtil.getHttpServletResponse(portletResponse);
  
     ServletOutputStream out = httpResponse.getOutputStream();
     String filename="Pdf" + System.currentTimeMillis()+".pdf";
     httpResponse.reset();
  
     httpResponse.setContentType("application/pdf");
     httpResponse.setHeader("Content-Disposition", "attachment; filename=\""+ filename + "\"");
     httpResponse.setContentLength(outputStream.size());
  
     outputStream.writeTo(out);
  
     out.flush();
     out.close();
  </code></pre>
  
  <p>I do not see anything output! In jboss log i read: <code>IllegaStateException</code>....</p>
  
  <p>What is wrong?</p>
  
  <p>LOG</p>
  
  <pre><code>        11:03:19,716 INFO  [STDOUT] 11:03:19,716 ERROR [IncludeTag] Current URL /web/organo-di-governo/datawarehouse?p_p_id=1_WAR_Portlet_Datawarehouse_INSTANCE_D7s7&amp;p_p_lifecycle=1&amp;p_p_state=normal&amp;p_p_mode=view&amp;p_p_col_id=column-2&amp;p_p_col_count=1&amp;_1_WAR_Portlet_Datawarehouse_INSTANCE_D7s7_com.sun.faces.portlet.VIEW_ID=%2Fview.xhtml&amp;_1_WAR_Portlet_Datawarehouse_INSTANCE_D7s7_com.sun.faces.portlet.NAME_SPACE=_1_WAR_Portlet_Datawarehouse_INSTANCE_D7s7_ generates exception: null
                  11:03:19,717 INFO  [STDOUT] 11:03:19,717 ERROR [IncludeTag] java.lang.IllegalStateException
                      at com.liferay.portal.servlet.filters.strip.StripResponse.getWriter(StripResponse.java:85)
                      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.JspWriterImpl.write(JspWriterImpl.java:326)
                      at org.apache.jasper.runtime.JspWriterImpl.write(JspWriterImpl.java:342)
                      at org.apache.jasper.runtime.JspWriterImpl.print(JspWriterImpl.java:468)
                      at com.liferay.taglib.util.ThemeUtil.includeVM(ThemeUtil.java:208)
                      at com.liferay.taglib.util.ThemeUtil.include(ThemeUtil.java:68)
                      at com.liferay.taglib.util.IncludeTag.doEndTag(IncludeTag.java:59)
                      at org.apache.jsp.html.common.themes.portal_jsp._jspx_meth_liferay_002dtheme_005finclude_005f1(portal_jsp.java:816)
                      at org.apache.jsp.html.common.themes.portal_jsp._jspx_meth_c_005fotherwise_005f0(portal_jsp.java:788)
                      at org.apache.jsp.html.common.themes.portal_jsp._jspService(portal_jsp.java:724)
                      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
                      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
                      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                  11:03:19,718 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
                  java.lang.IllegalStateException
  
  
  
          11:03:19,719 ERROR [[Main Servlet]] Servlet.service() for servlet Main Servlet threw exception
          java.lang.IllegalStateException
              at com.liferay.portal.servlet.filters.strip.StripResponse.getWriter(StripResponse.java:85)
              at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
              at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
  
  
  
          11:03:19,722 INFO  [STDOUT] 11:03:19,720 ERROR [OpenSSOFilter] org.apache.jasper.JasperException: java.lang.IllegalStateException
          org.apache.jasper.JasperException: java.lang.IllegalStateException
              at org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)
              at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:409)
              at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
              at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
  
  
  
  
          11:03:19,722 INFO  [STDOUT] n.internalDoFilter(ApplicationFilterChain.java:235)
              at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
              at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  
  
          Caused by: java.lang.IllegalStateException
              at com.liferay.portal.servlet.filters.strip.StripResponse.getWriter(StripResponse.java:85)
              at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125)
              at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118)
  </code></pre>