Jasper on a jsf app in heroku

2019-08-31 07:16发布

I am working in an application that uses jasperreports. It uses Primefaces with Mojarra, and is deployed in Jetty. When I deploy the app locally, it does work ok. But when I deploy in heroku it is not working.

When I deploy it to heroku I obtain:

HTTP ERROR 500

 Problem accessing /pages/client.jsf. Reason:
  STREAM Caused by:
 java.lang.IllegalStateException: STREAM    at
     org.eclipse.jetty.server.Response.getWriter(Response.java:683)     at
     com.sun.faces.context.ExternalContextImpl.getResponseOutputWriter(ExternalContextImpl.java:723)
        at
     com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:930)
        at
     com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:376)
        at
     com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
        at
     com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)    at
     com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)   at
     org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:598)
        at
     org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1367)
        at
     org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
        at
     org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1338)
        at
     org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
        at
     org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at
     org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1338)
        at
     org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:484)
        at
     org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
        at
     org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:524)
        at
     org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)
        at
     org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1065)
        at
     org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:413)
        at
     org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:192)
        at
     org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:999)
        at
     org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
        at
     org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
        at
     org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
        at
     org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:111)
        at org.eclipse.jetty.server.Server.handle(Server.java:350)  at
     org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:454)
        at
     org.eclipse.jetty.server.AbstractHttpConnection.content(AbstractHttpConnection.java:900)
        at
     org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.content(AbstractHttpConnection.java:954)
        at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:851)
        at
     org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)
        at
     org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:77)
        at
     org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:620)
        at
     org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:46)
        at
     org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:603)
        at
     org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:538)
        at java.lang.Thread.run(Thread.java:744)

As you can see it is deployed using Jetty.

The code that sends the pdf report is this:

@ManagedBean(name="reportGeneratorMB")
@RequestScoped
public class ReportGeneratorMB {
    public void generateReport(ActionEvent actionEvent) throws ClassNotFoundException,
            SQLException, IOException, JRException {
        Connection connection;
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext()
                .getResponse();
        InputStream reportStream = facesContext.getExternalContext().getResourceAsStream(
                "/resources/reports/index.jasper");
        ServletOutputStream servletOutputStream = response.getOutputStream();
        Class.forName("org.postgresql.Driver");
        connection = DriverManager.getConnection("jdbc:postgresql://localhost:5432/sid", "sid", 
                "sid");
        facesContext.getExternalContext().setResponseContentType("application/pdf");
        response.setContentType("application/pdf");
        JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, new HashMap(),
                connection);
        connection.close();
        servletOutputStream.flush();
        servletOutputStream.close();
        facesContext.responseComplete();
    }
}

And in the c.xhtml:

...
<h:form id="reportForm">
    <p:commandButton value="Generate Report" id="generate_report"
            actionListener="#{reportGeneratorMB.generateReport} ajax="false"/>
</form>
...

I've searched by I still haven't found a thing that can help me, and since it is working locally I do not know what can I do. I am not sure if this data is enough, but if it isn't I'll be grateful if you tell me what information I need to provide to get some help.

Thanks in advance,

Juan G

1条回答
疯言疯语
2楼-- · 2019-08-31 07:20

The error ...

java.lang.IllegalStateException: STREAM at
   org.eclipse.jetty.server.Response.getWriter(Response.java:683) at 

... means that your access to ServletResponse.getWriter() failed because something else in your application has previously accessed ServletResponse.getOutputStream(). That is not allowed per the servlet spec. You can either use a Writer or an OutputStream for your response, but not both. See javadoc on both of those methods for IllegalStateException.

查看更多
登录 后发表回答