0

I am using my-faces 2.1.5 primefaces 3.2 and WebLogic Server Version: 10.3.2.0

While I am generating files and trying to download them via p:fileDownload I get the following error message:

java.lang.IllegalStateException: strict servlet API: cannot call getWriter() after getOutputStream()
at weblogic.servlet.internal.ServletResponseImpl.getWriter(ServletResponseImpl.java:309)
at org.apache.myfaces.context.servlet.ServletExternalContextImpl.getResponseOutputWriter(ServletExternalContextImpl.java:185)
at org.apache.myfaces.renderkit.ErrorPageWriter.handle(ErrorPageWriter.java:469)
at org.apache.myfaces.context.MyFacesExceptionHandlerWrapperImpl.handle(MyFacesExceptionHandlerWrapperImpl.java:301)
at javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:64)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:191)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:117)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3592)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2202)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2108)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1432)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

I don’t know if it’s a bug in the weblogic or perhaps it’s a bug in my code ?

This message is the only reference that I got and I don’t have any clue how to solve this issue

The jsf file:

<p:commandButton id="genButton" value="Generate Files" disabled="#{bean.disableButton}" actionListener="#{bean.generate}" onclick="PrimeFaces.monitorDownload(showStatus, hideStatus)" ajax="false" style="width:200px" icon="ui-icon-shuffle">
        <p:fileDownload value="#{bean.zipfile}"/>  
        </p:commandButton> 

The bean:

     File zip = File.createTempFile(selectedCode, "zip");  

            ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip.getPath()));  
            for (File file : adapter.listFiles) {  
                addFileToZip(file, zos);  
            }  

            InputStream in = new FileInputStream(zip);  
            file = new DefaultStreamedContent(in, "zip", selectedCode + ".zip");  
            adapter.listFiles.clear();  
            zos.flush();  
            zos.close(); 
angus
  • 3,210
  • 10
  • 41
  • 71
  • You are probably right and the problem is in my code but I have no idea how to isolate the defect? What do you mean by “point out which servlets/pages are writing to the output stream” Can you please add some example ? – angus Jul 14 '12 at 15:58

2 Answers2

2

The stacktrace tells that the MyFaces exception handler tried to handle it.

at org.apache.myfaces.context.MyFacesExceptionHandlerWrapperImpl.handle(MyFacesExceptionHandlerWrapperImpl.java:301)
at javax.faces.context.ExceptionHandlerWrapper.handle(ExceptionHandlerWrapper.java:64)

This would only happen when an exception has been thrown. But the exception detail of that exception is in turn apparently suppressed because the MyFaces exception handler failed to handle the exception because the response writer couldn't be obtained.

Turn the MyFaces exception handler off and you'll get the real exception detail.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

It's look like i found the solution :)

in case the list is empty then ...

  else {
            if (streamedContent != null) {
                streamedContent.getStream().close();
                streamedContent = null;
            }
        }

Thanks for the help.

angus
  • 3,210
  • 10
  • 41
  • 71