7 Replies Latest reply on Oct 8, 2009 10:28 AM by jaikiran

    Accessing Directories Outside A Web Application's Context

      Hello,

      I am developing a JSF Web Application that needs to load files (html, pdf, images etc) based on users' selections. I do not want to include these files as part of the EAR deployment as they amount the several Gigabytes of data. Ideally, I would like to place these files outside the WAR's context root, say in the server's data directory.

      My problem is I don't know how to access these files from within the Web application. As I understand it (And I am fairly new to JBoss AS!) any files outside the WAR's root context cannot be accessed from within the Web application.

      Any help to solve this would be much appreciated.

      Regards,

      Michael

        • 1. Re: Accessing Directories Outside A Web Application's Contex
          alesj

          With JBoss5 this is not impossible, but you would have to write some code to achieve this.

          Some pseudo code:

          MainDeployer main = ...; // get "MainDeployer" injected from MC
          
          // use VFS's assembled notion
          AssembledDirectory ear = AssembledDirectoryFactory.create("my-virtual-ear.ear");
          AssembledDirectory external = ear.mkdir("huge-ext.war");
          VirtualFile extPath = VFS.getRoot(urlToExternalPileOfFiles);
          external.addPath(extPath);
          // add the rest of the resources
          
          Deployment deployment = new AbstractVFSDeployment(ear);
          
          main.deploy(deployment);
          


          You can try this and see if it works.
          (there might be some VFS's URL issues ...)

          • 2. Re: Accessing Directories Outside A Web Application's Contex

            Thanks Alesj for your reply,

            I was hoping there was a simpler solution like making a directory outside the Wep app's context available via security e.g. Making the data directory accessible with an entry in the web.xml file.

            Michael

            • 3. Re: Accessing Directories Outside A Web Application's Contex
              jaikiran
              • 4. Re: Accessing Directories Outside A Web Application's Contex
                peterj

                Another possibility it to add another deploy directory to the profile service and then place an exploded WAR directory there and put your file into that WAR.

                I could be more specific, but you never said which version of JBoss AS you are using.

                • 5. Re: Accessing Directories Outside A Web Application's Contex

                  Hello Peter,

                  Thanks for the reply - Great book by the way (JBIA) - really enjoying reading it. I'm using JBoss AS 5.1.0 GA. I really want the resources to be separate from the EAR deployment and in 'exploded' format as the content will change frequently. I think the link provided by Jaikiran has the approach I am looking for.

                  Regards,

                  Michael

                  • 6. Re: Accessing Directories Outside A Web Application's Contex

                    Hi,

                    I followed the instructions in the link posted by Jaikiran but the XML element "Context" is invalid within <Host name=.....>. The file I modified was /deploy/jbossweb.sar/server/xml.

                    I followed a link from the link provided by Jaikiran entitled "How to deploy my application in an external directory in JBoss-5" and made the following modification in the conf/bootstrap/profile.xml file:

                     <bean name="BootstrapProfileFactory" class="org.jboss.system.server.profileservice.repository.StaticProfileFactory">
                     <property name="bindingsURI">${jboss.server.home.url}conf/bindingservice.beans</property>
                    ...
                    ...
                     <list elementClass="java.net.URI">
                     <value>${jboss.server.home.url}deploy</value>
                     <value>${jboss.server.home.url}data/ebooks</value>
                     </list>
                    


                    When I try to access data within the "data/ebooks" directory I get a "Requested resource not available" error message.

                    I am using jboss-5.1.0.GA installation. Any help much appreciated.

                    Regards,

                    Michael

                    • 7. Re: Accessing Directories Outside A Web Application's Contex
                      jaikiran

                       

                      "dobreden2" wrote:

                      I followed a link from the link provided by Jaikiran entitled "How to deploy my application in an external directory in JBoss-5" and made the following modification in the conf/bootstrap/profile.xml file:

                       <bean name="BootstrapProfileFactory" class="org.jboss.system.server.profileservice.repository.StaticProfileFactory">
                       <property name="bindingsURI">${jboss.server.home.url}conf/bindingservice.beans</property>
                      ...
                      ...
                       <list elementClass="java.net.URI">
                       <value>${jboss.server.home.url}deploy</value>
                       <value>${jboss.server.home.url}data/ebooks</value>
                       </list>
                      


                      When I try to access data within the "data/ebooks" directory I get a "Requested resource not available" error message.

                      I am using jboss-5.1.0.GA installation. Any help much appreciated.

                      Regards,

                      Michael


                      Try:

                      <bean name="BootstrapProfileFactory" class="org.jboss.system.server.profileservice.repository.StaticProfileFactory">
                       <property name="bindingsURI">${jboss.server.home.url}conf/bindingservice.beans</property>
                      ...
                      ...
                       <list elementClass="java.net.URI">
                       <value>${jboss.server.home.url}deploy</value>
                       <value>${jboss.server.home.url}data</value>
                       </list>


                      and then in ${jboss.server.home.url}data folder create a (exploded) application ebooks.war and then place the documents under that. The docs will then be available at http://localhost:8080/ebooks

                      By the way, are you sure you want to place it in ${jboss.server.home.url}data folder, which can sometimes end up being cleaned out. Instead why not keep the files outside JBoss directory structure.