6 Replies Latest reply on Jun 19, 2013 10:38 PM by jaikiran

    Cannot save file when deploying to JBoss AS through maven

    hfluz

      JBoss AS maven plugin deploys my web application to JBoss virtual filesystem (/tpm/vfs/).

       

      When I try to save a picture to the relative path I get:

       

      /home/hfluz/Servers/standalone 7.1.1/standalone/tmp/vfs/temp3081e1eb97c799e8/content-b5984e02f5b23513/images/tmp/200701500694.png (No such file or directory)

       

      According to James R. Perkins the issue happens because the java.io.file does not support VFS.

       

      I could save the picture using an absolute path, but primefaces imageCropper can only find images through relative paths.

       

       

      My method that tries to save the uploaded picture:

       

       

      public void carregarArquivo(FileUploadEvent event)
              throws FileNotFoundException, IOException {
          InputStream input = event.getFile().getInputstream();
          ServletContext servletContext = (ServletContext) FacesContext
                  .getCurrentInstance().getExternalContext().getContext();
          File arquivo = new File(servletContext.getRealPath("") + File.separator
                  + "images" + File.separator + "tmp" + File.separator
                  + numMatricula + ".png");
          OutputStream output = null;
          try {
              output = new FileOutputStream(arquivo);
              IOUtils.copy(input, output);
              System.out.println("Arquivo salvo com sucesso em "
                      + arquivo.getAbsolutePath());
              tmpFotoPath = "/images/tmp/" + numMatricula + ".png";
              IOUtils.copy(input, output);
              System.out.println("Arquivo salvo com sucesso em "
                      + arquivo.getAbsolutePath());
              tmpFotoPath = "/images/tmp/" + numMatricula + ".png";
          } finally {
              IOUtils.closeQuietly(output);
              IOUtils.closeQuietly(input);
          }
      }

       

       

      Is there any workaround to be able to save the image to application's relative path?

        • 1. Re: Cannot save file when deploying to JBoss AS through maven
          jaikiran

          Is this a real application? Or are you just trying out some sample applications? If it's a real application then its better to not save the application data which gets added at runtime into the deployed application. Just imagine what would happen if that application had to be redeployed - you are going to lose the data which was uploaded earlier.

          • 2. Re: Cannot save file when deploying to JBoss AS through maven
            hfluz

            This is indeed a real application. The application is gonna be used to receive the students photos that'll be printed in their identification card.

             

            I am aware about the photos being deleted on redeploy, but the photos in relative path are actually temporary, the final photo is saved in another directory.

             

            It follows this workflow:

            1. The student send his photo by upload (primefaces uploader) or by webcam (primefaces photocam);
            2. The photo is saved temporarily in the relative path;
            3. The temporary photo is cropped (primefaces imageCropper) and saved temporarily in another folder of the relative path;
            4. The student accepts the mandatory terms and confirms the cropped photo.
            5. Then the photo is moved to another directory (absolute path).

             

            My issue is that in the 3rd step primefaces imageCropper requires that the photo to be cropped has to be in the relative path, but I cannot save it in relative path in the 2nd step because the application is deployed in JBoss AS VFS.

             

            I don't know how to deal with that.

            • 3. Re: Cannot save file when deploying to JBoss AS through maven
              jaikiran

              Humberto Ferreira da Luz Jr. wrote:

               

               

              My issue is that in the 3rd step primefaces imageCropper requires that the photo to be cropped has to be in the relative path,

              Not really. The PrimeFaces documentation says:

               

              External Images

               

              ImageCropper has the ability to crop external images as well.

               

              <p:imageCropper value="#{cropper.croppedImage}" image="http://primefaces.prime.com.tr/en/images/schema.png">
              </p:imageCropper>
              

               

              So you can perhaps try specifying the absolute path name (outside of the deployed web app) something like image="file:///home/me/somepath/foo.jpg"

               

              I haven't tried it myself.

              • 4. Re: Cannot save file when deploying to JBoss AS through maven
                hfluz

                You had a really good idea, but I tried using "file:///path_to_image" and unhappily it didn't work. It just doesn't load the image.

                 

                Actually I'm not really sure anymore if the issue is caused by VFS.

                 

                I deployed my maven webapp as an exploded war through JBoss Developer Studio and the same issue is happening. Both are identical, the only difference is that one is an ant project created by devstudio and the other one is a maven webapp.

                • 5. Re: Cannot save file when deploying to JBoss AS through maven
                  hfluz

                  I solved the problem. It was actually my fault.

                  I was so focused on comparing the java and xhtml code between both projects that I didn't realize I forgot to create images folder in maven project.

                  In the case of deploy through jboss as maven plugins, the empty directories were not included, so I added dummy files (documenting folder purpose) to include them during maven deploy to tmp/vfs.

                  • 6. Re: Cannot save file when deploying to JBoss AS through maven
                    jaikiran

                    Humberto Ferreira da Luz Jr. wrote:

                     

                     

                    In the case of deploy through jboss as maven plugins, the empty directories were not included,

                    Can you create a JIRA with the relevant details and a sample project which reproduces this?