3 Replies Latest reply on Jul 1, 2014 2:29 PM by stetali

    java.io.File.isDirectory() & java.io.File.exists() are not working fine on jboss-as 6.0 for mapped network drive on Windows 2008 R2 (64 bit) machine but the same methods are working fine if called from plain java file (outside Jboss)

    stetali

      Hi,

       

           On jboss-as 6.0,  with JASS configurations on, I am facing issues while trying to check if the file exists and if the file is a directory when the file is present on a mapped network drive on Windows 2008 R2 (64 bit).

           Even though the file exists and is a directory on a mapped network drive,  the following methods always returns false on Jboss 6 :

       

           1) java.io.File.exists()

           2) java.io.File.isDirectory()

           So, when I tried to write a simple java file (outside jboss), the above methods works fine and returns true (in case if the file exists or is a directory on a mapped network drive)

       

           I am not sure of the reason for this behaviour on Jboss 6.

       

          The way I created mapped network drive on Windows 2008 R2 by right clicking on "My Computer" and select "Map Network Drive" and added the network dirve path with credentials and assigned a drive letter to it.

       

           I have also tried the following :

       

           1) I checked if I have to set properties on Jboss service to allow network account but Jboss doesn't come up. (It was by default working on "Local System Account")

           2) I tried to remove security constraints from the war in which the above methods are called from java files but still I see the same issue.

       

           Can someone please help me out on this issue.(Do I need to configure any other parameters on Jboss to access mapped network drive or is it an existing issue on Jboss (or) if any other workaround exists to get rid of this problem.)

       

           OS & App details are as follows :

       

          1) OS : Windows 2008 R2 (64 bit)

              Jboss service : jboss-as 6.0

              Java : JDK 1.6.0_29

       

           Kindly, let me know if any further details are required. Thanks in advance and I hope to get an earliest support.

       

      Thanks & Regards,

      stetali.

        • 1. Re: java.io.File.isDirectory() & java.io.File.exists() are not working fine on jboss-as 6.0 for mapped network drive on Windows 2008 R2 (64 bit) machine but the same methods are working fine if called from plain java file (outside Jboss)
          stetali

          Hi,

           

               I have also tried the following on Jboss-as 6.0 :

           

               1) Passing "Mapped Network Drive" (Z:)

                   (where Z: is actually mapped to \\a.b.c.d\test where a.b.c.d is the ipaddress which is mapped on windows)

                           

                            try

                            { 

                                 File f = new File("Z:");

                                 boolean ifFileExists = f.exists();

                                 boolean ifFileisDirectory = f.isDirectory();

                                 FileWriter fw = new FileWriter(file,true);

                                 pw = new PrintWriter(fw);

                             } catch (IOException e) {

                             // TODO Auto-generated catch block

                             System.out.println("Exception : " + e.getMessage());

                             e.printStackTrace();

                             }

                             finally

                            {

                               if(pw!=null)

                               pw.close();

                            }

           

                   Output : f.exists() & f.isDirectory() returned false.

                   Exception obtained is "java.io.FileNotFoundException: Z: (The system cannot find the path specified)

                   

               2) Passing Network Path directly

                              

                            try

                            { 

                                File f = new File("\\a.b.c.d\test");

                                 boolean ifFileExists = f.exists();

                                 boolean ifFileisDirectory = f.isDirectory();

                                 FileWriter fw = new FileWriter(file,true);

                                 pw = new PrintWriter(fw);

                             } catch (IOException e) {

                             // TODO Auto-generated catch block

                             System.out.println("Exception : " + e.getMessage());

                             e.printStackTrace();

                             }

                             finally

                            {

                               if(pw!=null)

                               pw.close();

                            }

           

           

                   Output : f.exists() & f.isDirectory() returned false.

                   Exception obtained is "java.io.FileNotFoundException: \\a.b.c.d\test (Access is denied)"

           

                   Gave a valid accessible network ipaddress in the place of "a.b.c.d" above.


          As seen above, in case 2, Path is identified atleast but access is denied but still f.exists(), f.isDirectory() returned false


          Thanks & Regards,

          stetali.

          • 2. Re: java.io.File.isDirectory() & java.io.File.exists() are not working fine on jboss-as 6.0 for mapped network drive on Windows 2008 R2 (64 bit) machine but the same methods are working fine if called from plain java file (outside Jboss)
            ctomc

            This has noting to do with JBoss AS itself, but more general java.io.File problems.

             

            And to be fair,there  are many.

            I would recommend you to use JDK7 and use http://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html api as it will solve lots of your problems.

            • 3. Re: java.io.File.isDirectory() & java.io.File.exists() are not working fine on jboss-as 6.0 for mapped network drive on Windows 2008 R2 (64 bit) machine but the same methods are working fine if called from plain java file (outside Jboss)
              stetali

              Hi Tomaz Cerar,

               

                                      Thanks for your reply. The issue got resolved on JDK6 itself by doing the following :

               

                                       1) Stopped Jboss service

               

                                       2) Added "net use <drive letter>:\\<SERVERNAME>\<SERVERPATH> /user:<LocalSystemAccountUser> <LocalSystemAccountPassword>" to service.bat

               

                                           For ex : net use Z: \\1.1.1.1\testDirectory /user:Administrator admin

               

                                       3) Started Jboss service

               

                                        Hence, this might be happening because Jboss service on Windows is in local system account and adding the above statement makes the service use mapped network drive also for its operations.

               

              I feel that if JDK6 is the issue, then it wouldn't have run correctly when sample java program was run on same JDK6 outside Jboss which was not happening. This looks like an issue with service accessibility to network path on Windows.

               

              But thanks a lot for your feedback. I can try to use JDK7 and see if it works even by not adding this entry in service,bat. Kindly, let me know if you have any other thoughts on it.

               

              Thanks & Regards,

              stetali.