myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <pr...@centrum.cz>
Subject ExtensionsFilter corrupt xlsx during download
Date Tue, 08 Apr 2014 11:13:52 GMT
Hi, I'am using tomahawk-1.1.9 and JSF 1.2 for uploading file via t:inputFileUpload. When I
add following lines to my web.xml 

        <filter>
            <filter-name>MyFacesExtensionsFilter</filter-name>
            <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
                <init-param>
                        <description>
                            Set the size limit for uploaded files. 
                                Format: 10  - 10 bytes 
                                        10k - 10 KB 
                                        10m - 10 MB 
                                        1g  - 1 GB 
                        </description>
                        <param-name>uploadMaxFileSize</param-name>
                        <param-value>20m</param-value>
                    </init-param>
        </filter>
        <filter-mapping>
            <filter-name>MyFacesExtensionsFilter</filter-name>
          <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
        </filter-mapping>

It starts to corrupt Excel files during download. (When I opening downloaded Excel spreadsheet
it reports that it's corrupted and it has to be repaired). In next step it repairs Excel but
it's annoying to repair it every time. 

This is my download code.. It's not complete but main parts are contained. 

<h:commandLink value="#{ms['win.list_transcription.prescriptionExportAndDownload']}" actionListener="#{transcriptionBean.downloadExportPrescriptions}"
title="#{ms['win.list_transcription.prescriptionExportAndDownload']}"  />

FacesContext fc = FacesContext.getCurrentInstance(); 
HttpServletResponse response = (HttpServletResponse) fc.getExternalContext().getResponse();


response.reset(); 
response.setHeader("Content-Disposition", "attachment;filename=" + fileName); 
response.setContentLength(size); 
response.setContentType(StringUtils.isBlank(contentType) ? DEFAULT_CONTENT_TYPE : contentType);


OutputStream out = null; 
InputStream input = null; 

try { 
        input = new FileInputStream(file); 

        inputToOutputWriter(input, response, out); 
        } catch (Exception err) { 
                err.printStackTrace(); 
        } finally { 
                if (deleteOnClose) { 
                        file.delete(); 
                } 
} 
fc.responseComplete(); 

I don't know if it's possible to register ExtensionsFilter only for one jsf page (import page).
My attempts were not successfull. I tried for example this, but it ends that on import_payments.jsf
is no servlet present (no action works). 

        <filter-mapping>
            <filter-name>MyFacesExtensionsFilter</filter-name>
          <servlet-name>Import Faces Servlet</servlet-name>
            <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
        </filter-mapping>
         <servlet>
                <servlet-name>Import Faces Servlet</servlet-name>
                <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
                <servlet-name>Import Faces Servlet</servlet-name>
                <url-pattern>/private/import_payments.jsf</url-pattern>
        </servlet-mapping>
        <servlet>
                <servlet-name>Faces Servlet</servlet-name>
                <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                <load-on-startup>2</load-on-startup>
        </servlet>
        <servlet-mapping>
                <servlet-name>Faces Servlet</servlet-name>
                <url-pattern>*.jsf</url-pattern>
        </servlet-mapping>

Thank you 
Zdend

Mime
View raw message