Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Download file in ssl

843844Jul 29 2008 — edited Jul 30 2008
Hi,
i have problem when download file with content type"application/octet-stream" in HTTPS,
when use HTTP download file is ok!!

in IE when click actionLink the browser open a popup box with the text "Cannot download file.jsf from host. Can not open the website. Site not available or found. Please try again at a later time"

in Firefox it's OK

My application server is glassfish v2 and action method for download is:
<h:commandLink actionListener="#{PreventivoFindBB.downloadAttached}">
  <h:outputText value="#{allegato.name}" styleClass="label"/>
  <f:param name="fileId" value="#{allegato.name}"/>
</h:commandLink>


public String downloadAttached(ActionEvent event) {
        String sid = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("fileId");
        System.out.println("Param: " + sid);
        BufferedInputStream input = null;
        HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();

        for (File file : preventivo.getListFile()) {
            if (file.getName().equals(sid)) {
                try {
                    input = new BufferedInputStream(new FileInputStream(file));
                    int contentLength = input.available();
                    response.setContentType("application/octet-stream");
                    response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
                    response.setHeader("Cache-Control", "no-cache");

                    // Write file contents to response.
                    while (contentLength-- > 0) {
                        response.getOutputStream().write(input.read());
                    }
                } catch (Exception ex) {
                    String msg = "Sorry";
                    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
                    ex.printStackTrace();
                    return null;
                }
                FacesContext faces = FacesContext.getCurrentInstance();
                faces.responseComplete();
            }
        }
        return null;
    }
Have you any idea?

Edited by: Rosario on Jul 29, 2008 4:30 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 27 2008
Added on Jul 29 2008
1 comment
127 views