1

We have been providing a text report download to our client. Our managed bean generates a text report which a user can download from a JSF2 prime-faces application. The below mentioned code works most of the time. From my inspection it has been working for quite long and is also working for most of the cases. But today it failed to download the report for a client for one of their branch and it failed repeatedly for that client until we disable policy to allow non compliant HTTP. In that case Browser waits some time for report to get downloaded but after some time we get a blank file with network error status.

After looking for the firewall log we got some connections drop because firewall has policy to block HTTP Non compliant.

If we disable the policy to block Non Compliant HTTP the issue gets resolved. What can be the issue we have been facing?

The method of managed bean which starts streaming download is:

 public void downloadFile()throws IOException {
    FacesContext ctx = FacesContext.getCurrentInstance();
    ExternalContext ext = ctx.getExternalContext();
    ext.responseReset();

      OutputStream out2 = ext.getResponseOutputStream();
      ext.setResponseHeader("Content-disposition", "Attachment;filename=rep.dlt" );
      ext.setResponseContentType("text/plain");

     StringBuilder sb = new StringBuilder();
     sb.append("Some dynamic large string string");
     sb.append("Some dynamic large string string");
     InputStream in
             = new ByteArrayInputStream(sb.toString().getBytes("UTF-8"));

     byte[] outputByte = new byte[4096];
     //copy binary content to output stream
     int len;
     while ((len = in.read(outputByte, 0, 4096)) != -1) {
         out2.write(outputByte, 0, len);
     }
     in.close();

     out2.flush();
     out2.close();
     FacesContext.getCurrentInstance().responseComplete();
  }

And the xhtml which generates the request is

  <h:form id="formId">
        <h:panelGrid columns="4" cellspacing="20">
            <p:outputLabel value="To" for="toDate" />
            <p:inputMask  id="toDate" value="#{accountReportController.toDate}" mask="9999/99/99"  required="true" />

            <p:selectOneMenu value="#{accountReportController.selectedOrganization}" filter="true" filterMatchMode="contains" id="orgSel">
                <f:selectItem itemValue="#{null}" itemLabel="Select one" /> 
                <f:selectItems value="#{branchController.allBranches}" var="v" itemLabel="#{v.name}" itemValue="#{v}" />
            </p:selectOneMenu>

            <p:commandButton value="Credit Info"  action="#{accountReportController.downloadFile()}" ajax="false" id="btnDwonload"/>

        </h:panelGrid>
    </h:form>

Again I would like to re iterate that its working for 99% without disabling firewall policy to block NON Compliant HTTP.

The platform used are: Java 1.7, glassfish 3.2.2, CDI, JSF, Primefaces, seam3 etc.

Dev Khadka
  • 154
  • 1
  • 9
  • Does it work if you use all plain jsf components instead of PF ones? And in what way is the response non-http compliant? You yourself create the response – Kukeltje Sep 05 '17 at 18:56
  • @Kukeltje There is no difference between using the plain jsf components and PF components. – Dev Khadka Sep 08 '17 at 09:10
  • So the question is not PrimeFaces related... That narrows it down... Can you reproduce with a plain jdk in a class with just a main? If not, it is not java(-se) related. How is it Seam 3 related (other than you using it)? And besides all this, **how** is the http response not rfc compliant? You are the only one that can find this out – Kukeltje Sep 08 '17 at 09:53

0 Answers0