0

I would to download a PDF file from iframe it worked in Google chrome and firefox but it not worked in Internet explorer.

This is my code

public void downloadSubscriptionDocument(SessionObject object) {
    Document dt = getBlobCode(object);
    if (dt != null && dt.getData() != null) {
        final FacesContext fContext = FacesContext.getCurrentInstance();
        ExternalContext eContext = null;
        if (fContext != null && dt != null) {
            eContext = fContext.getExternalContext();

            if (eContext != null) {

                final HttpServletResponse response = (HttpServletResponse) eContext.getResponse();

                response.setContentType("application/pdf");
                response.addHeader("content-disposition", "attachment; filename=" + "BulletinAdhesion" + ".pdf");
                if (dt != null && dt.getData() != null) {
                    response.addHeader("Content-Length", String.valueOf(dt.getData().length));
                }

                try {
                    final ServletOutputStream sos = response.getOutputStream();
                    sos.write(dt.getData());
                    sos.flush();
                    sos.close();
                    fContext.responseComplete();
                } catch (final Exception ex) {
                    LOGGER.log(Level.SEVERE, ex.getMessage());
                }
            }
        }
    }
    else {
        Locale locale = new Locale("fr");
        this.addMessageError(ResourceBundle.getBundle("messages", locale).getString("eu.spb.afflelou.pdv.ba.not.found"));
        return ;
    }
}

I have this exception in console

Servlet] - 2019-12-04 10:30:29,289 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/spb-extranet-afflelou-pdv].[Faces Servlet]] (ajp-/10.7.2.55 {s2jbossrecex.spb.eu} :8809-3) JBWEB000236: Servlet.service() for servlet Faces Servlet threw exception: java.lang.IllegalStateException: JBWEB000028: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:621) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:191) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at com.sun.faces.context.ExternalContextImpl.getResponseOutputWriter(ExternalContextImpl.java:778) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at javax.faces.context.ExternalContextWrapper.getResponseOutputWriter(ExternalContextWrapper.java:669) [jboss-jsf-api_2.1_spec-2.1.28.SP2-redhat-1.jar:2.1.28.SP2-redhat-1]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1110) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:399) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286) [jboss-jsf-api_2.1_spec-2.1.28.SP2-redhat-1.jar:2.1.28.SP2-redhat-1]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286) [jboss-jsf-api_2.1_spec-2.1.28.SP2-redhat-1.jar:2.1.28.SP2-redhat-1]
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286) [jboss-jsf-api_2.1_spec-2.1.28.SP2-redhat-1.jar:2.1.28.SP2-redhat-1]
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.28.SP11-redhat-1.jar:2.1.28.SP11-redhat-1]
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.1.28.SP2-redhat-1.jar:2.1.28.SP2-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:295) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:149) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.event(JBossWebContext.java:91)
at org.jboss.modcluster.container.jbossweb.JBossWebContext$RequestListenerValve.invoke(JBossWebContext.java:72)
at org.jboss.as.web.security.SubjectInfoSetupValve.invoke(SubjectInfoSetupValve.java:34) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.web.session.ClusteredSessionValve.handleRequest(ClusteredSessionValve.java:134) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.web.session.ClusteredSessionValve.invoke(ClusteredSessionValve.java:99) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.web.session.JvmRouteValve.invoke(JvmRouteValve.java:95) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.web.session.LockingValve.invoke(LockingValve.java:64) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:169) [jboss-as-web-7.5.22.Final-redhat-1.jar:7.5.22.Final-redhat-1]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:102) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:97) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:490) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:422) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:926) [jbossweb-7.5.30.Final-redhat-1.jar:7.5.30.Final-redhat-1]
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
BNJ
  • 108
  • 1
  • 8
  • 1
    You forgot to include the rest of the stack trace which explains how exactly the code ended up into that condition. – BalusC Dec 04 '19 at 10:19
  • You mean the XHTML File ? – BNJ Dec 04 '19 at 10:26
  • 1
    Uhhh....https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors and https://stackoverflow.com/questions/12688068/how-to-read-and-understand-the-java-stack-trace – Kukeltje Dec 04 '19 at 10:30
  • Ok thank you this i update the question – BNJ Dec 04 '19 at 10:40
  • OK, the presence of `org.apache.catalina.valves.ErrorReportValve.invoke` indicates it's trying to show an error page, but it apparently couldn't do it. This in turn suggests that writing the PDF failed. Have you really paid close attention to server logs? There's most probably something logged via `LOGGER.log(Level.SEVERE, ex.getMessage());`. Your misunderstanding of my 1st comment strongly suggests you have no idea how exceptions work. I strongly recommend to replace that whole logger line by a `throw new FacesException(ex)`. It should end up in a clearer error reporting. – BalusC Dec 04 '19 at 11:13

0 Answers0