14 Replies Latest reply on Oct 6, 2007 3:55 AM by Adrian Mitev

    Stupid ajax4jsf filter when downloading files

    Franck MARTIN Newbie

      Hi,

      I was trying to use a typical seam backing bean for handling a file download. So i used the many examples posted on this forum. sthg like :

      @Stateful
      @Scope(EVENT)
      @Name("editWebdoc")
      public class EditWebdocAction implements EditWebdoc {
       @In(required=true)
       private Client client;
      
      
       @In(required=false)
       private Webdoc webdoc;
      
       @In(value = "#{facesContext}")
       private FacesContext mFacesContext;
      
      ....
       public void getDocFichier(Webdoc webdoc) {
       if (webdoc == null) {
       return;
       }
       byte[] data = webdoc.getDocFicData();
       HttpServletResponse response = (HttpServletResponse) mFacesContext.getExternalContext().getResponse();
       response.setContentType("application/pdf");
       response.setContentLength(data.length);
       response.addHeader("Content-disposition", "attachment; filename=\"" + webdoc.getDocFicNom() + "\"");
      
       try {
       ServletOutputStream responseOutputStream = response.getOutputStream();
       responseOutputStream.write(webdoc.getDocFicData());
       responseOutputStream.flush();
       responseOutputStream.close();
       mFacesContext.responseComplete();
       response.flushBuffer();
       } catch (IOException ioe) {
       log.error("IOException lors de la restitution du document webdoc", ioe);
       }
      


      AND

      <s:fileUpload id="fichierPDF"
       data="#{webdoc.docFicData}"
       accept="application/PDF"
       contentType="#{editWebdoc.fichierContentType}"
       fileName="#{webdoc.docFicNom}"
       fileSize="#{editWebdoc.fichierTaille}" />


      But i kept getting the following error :





      
      17:35:40,872 ERROR [[Faces Servlet]] "Servlet.service()" pour la servlet Faces Servlet a généré une exception
      java.lang.NullPointerException
       at java.util.regex.Matcher.getTextLength(Matcher.java:1127)
       at java.util.regex.Matcher.reset(Matcher.java:284)
       at java.util.regex.Matcher.<init>(Matcher.java:205)
       at java.util.regex.Pattern.matcher(Pattern.java:879)
       at org.ajax4jsf.webapp.ParserConfig.getParser(ParserConfig.java:28)
       at org.ajax4jsf.webapp.ConfigurableXMLFilter.getParser(ConfigurableXMLFilter.java:109)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:259)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:281)
       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
       at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:150)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
       at java.lang.Thread.run(Thread.java:595)
      
      


      So i thought it was this stupid ajax4jsf filter and i switched the force-parser attribute to false hence ending up to this in components.xml :

      
       <web:ajax4jsf-filter force-parser="true"
       enable-cache="true"
       log4j-init-file="custom-log4j.xml"
       url-pattern="*.seam"/>
      
      


      The pdf download now works, but of course the ajax validation w/ hibernate validator is not working in the other pages of my application.

      Can't we have both ajax-hibernate validation AND download file functionnality within the same application?

      Is there a way to bypass ajax filter for certain actions?