Access files on Netwrok drive from JBoss

I have a Java application running on JBoss on Windows. I am trying to access files on a network drive. Based on earlier reponses I tried accessing it as
File f = new File("\\computername\folder\filename.pdf");
I can access this file from the Windows "Run" console, but when I try to access it from the browser through my application it says, "<URL path> (Access Denied)"

When the application is running on the same system as where I can invoke the file from "Run" menu command, why can't the application access it? Any ideas?
ptjhaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
objectsConnect With a Mentor Commented:
easier to just disable the security manager, that will tell you if its what blocking your access.
0
 
CEHJCommented:
As i mentioned earlier, the access will have to be done purely by the 'back end' of the web app. You can't otherwise access anything outside the web folders
0
 
CEHJCommented:
... and any SecurityManager run by JBoss will have to allow this
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
objectsCommented:
you cannot access a file via a webapp like that, see my suggestions in your earlier question.
Basically it needs to be implemented on your app server (typically as a servlet)
0
 
ptjhaAuthor Commented:
Objects,
I am trying to test this in jsp. That is what gave the "access denied" message.

CEHJ,
I am not very familiar with such file handling. Could you elaborate on what you mean by - "the access will have to be done purely by the 'back end' of the web app". I will check the Security Manager setting but what back end access manipualtion are you referring to.

Thanks.
0
 
CEHJCommented:
>>but what back end access manipualtion are you referring to.

That's a general point, but since you're using a jsp, let's make it specific: please post the code you're trying
0
 
ptjhaAuthor Commented:
Here's it.
<%@ page language="java" %>
<%@ page import="java.io.File" 
%><%@ page import="java.io.FileInputStream"
%><%@ page import="java.io.InputStream"
%><%@ page import="java.io.OutputStream"
%><%@ page import="java.io.IOException"
%><%
    File f = null;
    InputStream is = null;
    OutputStream os = null;
    try
    {
      f = new File("\\\\server\\folder\\TestPDF.pdf");
      is = new FileInputStream(f);
      os = response.getOutputStream();
      response.setContentType("application/force-download");
      response.setHeader("Content-Disposition", "attachment; filename=\"TestPDF.pdf\"");
    
      int l;
      byte[] b = new byte[1024];
      while(true) 
      {
        l = is.read(b);
        if(l==0) break;
        os.write(b, 0, l);
      }
    }
    catch(IOException ioe)
    { %> <%= e.getMessage() %> <%} 
    finally
    {
      if (is != null)
        is.close();
      if (os != null)
        os.close();
    }
%>

Open in new window

0
 
objectsCommented:
> I am trying to test this in jsp. That is what gave the "access denied" message.

could be that jboss just does not have access to the remote drive.
Make sure you are trying to access it as a file, and not as a url

> Could you elaborate on what you mean by - "the access will have to be done purely by the 'back end' of the web app".

he means what i outlined in your earlier q
0
 
ptjhaAuthor Commented:
Sorry, that was the earlier version. "e.getMessage()" should be replaced with "ioe.getMessage()". I have that in the server version.
0
 
objectsCommented:
first thing to check would be your security manager (try disabling it as a test)
0
 
CEHJCommented:
That's probably being disallowed by the container's SecurityManager. If so, you need to change the policy file
0
 
ptjhaAuthor Commented:
Thanks for your quick response. I tested it out by setting the policies in java.policy file, but it still gives "Access is denied" message. Apart from AllPermissions to the SecurityManager, I even added,
 permission java.io.FilePermission "\\\\server\\folder\\TestPDF.pdf", "read, write, execute";
all java.policy. But it still doesn't seem to work.
    Where am I going wrong?

Objects - "could be that jboss just does not have access to the remote drive. Make sure you are trying to access it as a file, and not as a url"
How do I ensure that I am accessing it as file an not URL? Do I need to put "file:///\\\\corp.telephia.com......? Please let me know.
0
 
CEHJCommented:
>>I tested it out by setting the policies in java.policy file

Make sure it's the right file and it's being accessed

>>How do I ensure that I am accessing it as file an not URL?

As i mentioned before - you create a File object
0
 
ptjhaAuthor Commented:
>> As i mentioned before - you create a File object

Yes, that's what I am doing. Refering back to the cocde snipet I posted earlier. I am using it as,
 f = new File("\\\\server\\folder\\TestPDF.pdf");

As for the policy file, I made cchanges to the security policy file. Is it mandatory to make these chcanges in the user policy file too i.e. at ${USER.HOME}. Moreover, I haven't been able to locate the user policy file yet. The server has Windows Server 2003 and I did not find the C:\Windows\Profiles so I could not loate the user policy file. Where could it be?
0
 
CEHJCommented:
To be on the safe side, just do a global search and check the file stamps
0
 
ptjhaAuthor Commented:
By default JBoss does not start with Security Manager. So when I tried earlier with Security Manager disabled, it did not work. Now I have made relevant changes to run.bat - JAVA_OPTS to enable security manager and made changes to all java.policy files on the server. But unfortunately it is still not working. I still get access denied and infact it is not an AccessControlException but is an IOException. Not sure why.

Does anybody have any more ideas? I am just stuck at this point.
0
 
objectsCommented:
thought so, didn't seem security manager related.
would appear that jboss just don't have access to the drive

why aren't you mounting the drive in the 1st place?
0
 
CEHJConnect With a Mentor Commented:
>>and infact it is not an AccessControlException but is an IOException.

Make sure that the account under which JBoss is running has read permissions
0
 
ptjhaAuthor Commented:
Objects,
As for fileserver, it is a shared repository and some other applications use it too. So it resides on a separate system. However I did map it as network drive on the app server and tried but that doesn't work as well.

CEHJ,
JBoss service has the following specified as Log On as - Local System Account. I enabled "Allow services to interact with desktop).  As for the file server, folder and files on it, my user id has all read, write, execute and modify provileges. I even set the JBoss Log on to use my credentials which should mean that the application should be able to access the fileserver without any issues. But even then it did not work. Moreover I use the same credentials for the app server and the file server. So that should be simple for the setup as well. So now I can't figure out what else to do or set from my end.

Thanks.
0
 
CEHJCommented:
What do you get from

System.out.println(f.canRead());

?
0
 
objectsCommented:
> However I did map it as network drive on the app server and tried but that doesn't work as well.

did u change the path in your code?

> System.out.println(f.canRead());

that will fail
0
 
CEHJCommented:
Oh and please post the IOException stack trace
0
 
ptjhaAuthor Commented:
There is no stack trace in it. I am invoking it from jsp and the jsp just has whatever code you see in the above posted snipet. So stack trace does not print anything. The only message for IOException I get is,

"\\server\folder\TestPDF.pdf (Access is denied)"
0
 
CEHJCommented:
>>There is no stack trace in it. I am invoking it from jsp ...

The stack trace (if there IS an exception) should appear in your container's log file
0
 
ptjhaAuthor Commented:
It is working now. I did not change anything at our end but had asked the IT group to revisist and reset the permissions on the folders/files. Not sure if that worked because the JBoss user had "Full Control" on the fileserver folders and files from teh beginning.

Thanks for all your help and prompt responses.
0
 
CEHJCommented:
OK - glad you've got it
0
All Courses

From novice to tech pro — start learning today.