This content has been marked as final.
Show 6 replies
-
1. Re: File download issue?
mpickell Jun 12, 2009 11:57 AM (in response to mpickell)This seems to have started when we implemented richfaces.
We have some links that work, outputting CSV files using writers to the outputstream in doGet of the servlet.
The doPost methods we use for writing binary data to the outputstream (such as pdfs) do not work at all anymore. Now the file is not making it to the client. The filename is fine, the "open or save file" dialog comes up, but when you try to open the file it is ZERO length. -
2. Re: File download issue?
nbelaevski Jun 12, 2009 1:37 PM (in response to mpickell)Hi,
Please post web.xml and code related to the issue. -
3. Re: File download issue?
mpickell Jun 12, 2009 1:49 PM (in response to mpickell)"nbelaevski" wrote:
Hi,
Please post web.xml and code related to the issue.<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <context-param> <param-name>org.apache.myfaces.ERROR_HANDLING</param-name> <param-value>false</param-value> </context-param> <context-param> <param-name>javax.faces.application.CONFIG_FILES</param-name> <param-value></param-value> </context-param> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> <context-param> <param-name>myfaces_allow_javascript</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>myfaces_pretty_html</param-name> <param-value>true</param-value> </context-param> <session-config> <session-timeout>20</session-timeout> </session-config> <listener> <listener-class> bessa.app.web.AppLifecycleListener </listener-class> </listener> <listener> <listener-class>bessa.app.web.AppSessionListenr</listener-class> </listener> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping> <servlet> <servlet-name>openFile</servlet-name> <servlet-class> com.b6Systems.pureFaces.servlet.OpenFileServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>openFile</servlet-name> <url-pattern>/openFile/*</url-pattern> </servlet-mapping> <servlet> <servlet-name>loopBack</servlet-name> <servlet-class>bessa.app.web.LoopBackServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>loopBack</servlet-name> <url-pattern>/loopBack</url-pattern> </servlet-mapping> <servlet> <servlet-name>oeForms</servlet-name> <servlet-class>bessa.pdf.HelloWorldServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>oeForms</servlet-name> <url-pattern>/oeForms</url-pattern> </servlet-mapping> <servlet> <servlet-name>csvExport</servlet-name> <servlet-class>bessa.web.export.CsvExportServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>csvExport</servlet-name> <url-pattern>/protected/csvExport</url-pattern> </servlet-mapping> <filter> <display-name>RichFaces Filter</display-name> <filter-name>richfaces</filter-name> <filter-class>org.ajax4jsf.Filter</filter-class> </filter> <filter-mapping> <filter-name>richfaces</filter-name> <servlet-name>Faces Servlet</servlet-name> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> </filter-mapping> <filter> <filter-name>extensionsFilter</filter-name> <filter-class> org.apache.myfaces.component.html.util.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>100m</param-value> </init-param> <init-param> <description> Set the threshold size - files below this limit are stored in memory, files above this limit are stored on disk. Format: 10 - 10 bytes 10k - 10 KB 10m - 10 MB 1g - 1 GB </description> <param-name>uploadThresholdSize</param-name> <param-value>100k</param-value> </init-param> </filter> <filter-mapping> <filter-name>extensionsFilter</filter-name> <url-pattern>*.faces</url-pattern> </filter-mapping> <filter-mapping> <filter-name>extensionsFilter</filter-name> <url-pattern>/faces/*</url-pattern> </filter-mapping> <filter> <filter-name>SecurityFilter</filter-name> <filter-class>bessa.app.web.SecurityFilter</filter-class> </filter> <filter> <filter-name>RequestControlFilter</filter-name> <filter-class>bessa.app.web.RequestControlFilter</filter-class> </filter> <filter-mapping> <filter-name>SecurityFilter</filter-name> <url-pattern>/protected/*</url-pattern> </filter-mapping> <filter-mapping> <filter-name>RequestControlFilter</filter-name> <url-pattern>/protected/*</url-pattern> </filter-mapping> <security-constraint> <display-name>Bessa</display-name> <web-resource-collection> <web-resource-name>bessa</web-resource-name> <url-pattern>/dev/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>admin</role-name> <role-name>superuser</role-name> </auth-constraint> </security-constraint> <login-config> <auth-method>FORM</auth-method> <realm-name>BessaRealm</realm-name> <form-login-config> <form-login-page>/dev/login.jsp</form-login-page> <form-error-page>/dev/loginFail.jsp</form-error-page> </form-login-config> </login-config> <security-role> <role-name>admin</role-name> </security-role> <security-role> <role-name>superuser</role-name> </security-role> <error-page> <error-code>403</error-code> <location>/403Error.jsp</location> </error-page> <error-page> <error-code>404</error-code> <location>/404Error.jsp</location> </error-page> <error-page> <error-code>500</error-code> <location>/error.jsp</location> </error-page> <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/error.jsp</location> </error-page> <error-page> <exception-type>bessa.common.exceptions.PermissionViolationException</exception-type> <location>/403Error.jsp</location> </error-page> </web-app>
And here is the Servlet, but we have tried multiple examples and versions of this, so i do not think it is here. I think it is in the configuration. the OpenFileCommand.updateOutputStream(outputstream) simple calls an "outputstream.write" command. This has been working until recently.public class OpenFileServlet extends HttpServlet { protected Log log = LogFactory.getLog(getClass()); private static final long serialVersionUID = 522861203816914786L; public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { process(request, response); } @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { process(request, response); } private void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { OpenFileCommand openFileCommand = (OpenFileCommand) request.getSession().getAttribute(OpenFileCommand.OPEN_FILE_SESSION_KEY); request.getSession().setAttribute(OpenFileCommand.OPEN_FILE_SESSION_KEY, null); log.info("OpenFileServlet openFileCommand=" + openFileCommand); response.setContentType(openFileCommand.getContentType()); response.setHeader("Content-Disposition", "attachment; filename=\"" + openFileCommand.getFileName()+"\""); response.setDateHeader("Expires", System.currentTimeMillis()); // response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate"); openFileCommand.updateOutputStream(response.getOutputStream()); } }
-
4. Re: File download issue?
nbelaevski Jun 12, 2009 3:28 PM (in response to mpickell)This should work. Just to clarify: are you redirecting to OpenFileServlet servlet or forwarding?
-
5. Re: File download issue?
mpickell Jun 12, 2009 4:15 PM (in response to mpickell)"nbelaevski" wrote:
This should work. Just to clarify: are you redirecting to OpenFileServlet servlet or forwarding?
I am pretty sure it is forwarded... How do i verify? I'm not telling it to do anything other than what you see in the code samples. -
6. Re: File download issue?
nbelaevski Jun 12, 2009 5:21 PM (in response to mpickell)Can you post action code (I assume JSF action is called by clicking buttons)?