4 Replies Latest reply on Nov 3, 2009 9:13 AM by lvdberg

    How do I access a generated file?

    mstang

      I am generating pdf files as external files.  This is being done in background at night.  However, I also need to display them through the UI.  I try to open them in an window and I get:


      The url requested does not exist. Please update your saved bookmarks, or check that requested url is not mistyped.


      I get the same response if I type url directly in the browser.  However, if I type favicon.ico it appears.  I have tried using a writer and sending the content back, but I end up with an exception:


      Caused by: java.lang.IllegalStateException: Servlet response already use stream, Writer not possible


      So, short of creating a specialized servlet or some thing else, how do I get my content back to the browser.  The file is generated, it should be simple for the browser to access the file!

        • 1. Re: How do I access a generated file?
          lvdberg

          Hi,


          I ususally save them in the always-present root-directory of the server. In my case I use the


          JBOSS_HOME



          variable which gives me the absolute path to the server dir on disk and work my way up. It's is not easy to use a sub-dir of your own application if you want to preserve the files, because Jboss creates a temporary dir where the deployed dir resides. If you don't care , get the absolute path from  the servlet context. With Seam you just inject the FacesContext and you can get the absolute dir from there.


          Leo

          • 2. Re: How do I access a generated file?
            cash1981

            You can also take a look here which might be helpful. Personally I always put my files in the database. That way it is much easier to get hold of them.


            http://www.seamframework.org/Community/LargeFileDownload

            • 3. Re: How do I access a generated file?
              mstang

              I am able to get access to the root of webapp:



              1. {request.contextPath



              I can create files here, but seam/jboss is blocking my access.  I get the error:


              The url requested does not exist. Please update your saved bookmarks, or check that requested url is not mistyped.


              Why can't I access generated files in the webapp directory???

              • 4. Re: How do I access a generated file?
                lvdberg

                To get a specific resource:





                @In FacesContext facesContext;
                
                ...
                
                ServletContext ctx = (ServletContext) facesContext.getExternalContext().getContext(); 
                URL url = ctx.getResource("/subDir/subDir/YourFile");



                So if you place your file in the indicated YourFile starting from the root-directory of your application, it should work. However, if you use a WAR-file those files are created in a temporary deploy directory. When the server re-starts after a deploy you won't see the same directory. You can solve that by deploying as an  WAR.DIR under your deploy directory. Your application will always atart in the same directory and your files are persisted.


                Leo