Tomcat 5.5.15 running as a service or manually started... and trying to read a File

C

ccjjharmon

In a java bean, I am attempting to read a File object, which is a
mapped drive (X:\\) on a Windows 2003 Server. What I am trying to do is
read a file from this mapped drive.

Running Tomcat 5.5.15, with JRE 1.5.0_06.

When I have Tomcat started as a Windows service, the .canRead() method
returns false.

When I have Tomcat started manually (command-line), the .canRead()
method returns true. When I start it, I am logged into the server via
Remote Desktop as my network account login.

The mapped drive is setup under my login, and my login has read+write
privileges on this share.

Initially I figured this would occur when the Tomcat service is left
alone to "run-as" Local System, but even when I changed it to run as my
network account login, this still occurs.

I can't figure it out. Any ideas?

Code snippet:

String dir = "X:\\";
File theDir = new File(dir);
if (!theDir.canRead()) throw new Exception("cannot read from the
share");


Thanks in advance!

Chris Harmon
 
C

ccjjharmon

I just checked to see if I have it read from a local drive's folder,
and change the security on this folder what will happen. Here is the
results (only tested on the problem scenario of running as a service):

When service is running as local system, canRead() returns true when it
has system account with read privileges. When system account does not
have read privileges, canRead() returns false.

When service is running as my network account, canRead() returns true
when my network account has read privileges. When it does not have read
privileges, canRead() returns false.

End result: it worked as I expected. But apparently this issue only
appears when dealing with mapped drives???

If this is the case, what is the recommended procedure for reading
Files from remote file servers? Assuming there is no per-se server
(like an FTP server or WWW server) on this remote file server....

Chris Harmon
 
J

Juha Laiho

(e-mail address removed) said:
In a java bean, I am attempting to read a File object, which is a
mapped drive (X:\\) on a Windows 2003 Server. What I am trying to do is
read a file from this mapped drive. [...]
When I have Tomcat started as a Windows service, the .canRead() method
returns false.

When I have Tomcat started manually (command-line), the .canRead()
method returns true. When I start it, I am logged into the server via
Remote Desktop as my network account login.

Hmm.. just a thought (and I'm not too familiar with Windows), it
might well be that the drive mappings are only done when you do an
interactive login - so, when you're just running a service, the
drive is not mapped.

You might try using the UNC file paths (so,
\\servername\share\path\file.ext ).
 
C

ccjjharmon

Juha,

That was the first thing I came across in the newsgroups to try - using
the UNC path instead of the mapped drive. Unfortunately, I couldn't get
it to work at all... checking newsgroups again, I haven't tried using
runtime.exec() to make sure the drive is mapped...

But in all honesty, using the UNC path would be the more desirable
option in case the server (and/or share) changes I would rather be able
to dynamically deal with this change without needing to ensure the
mapped drive is changed also. Par for the course of this, it would be
*great* to know how I can provide the username and password to connect
to the UNC file path... but as far as I can tell, this isn't possible.

I believe it probably is some "quirk" that a Windows Java programmer
would quickly identify and know what they do to get past this... any
Windows Java programmers out there to chime in?

I am likely going to call a professor that is teaching an advanced Java
class I am taking (to get up to speed quicker on Java technology) - if
I get anywhere, I will post the news.

I am still hoping someone has some idea of what I can do though.

Chris
 
C

Chris Uppal

But in all honesty, using the UNC path would be the more desirable
option in case the server (and/or share) changes I would rather be able
to dynamically deal with this change without needing to ensure the
mapped drive is changed also. Par for the course of this, it would be
*great* to know how I can provide the username and password to connect
to the UNC file path... but as far as I can tell, this isn't possible.

I think you have to specify these as part of the service defintion, not of the
UNC filename.

Some stuff from MS:
http://msdn.microsoft.com/library/en-us/dllproc/base/service_user_accounts.asp

And this link may help (it's talking about a completely different service, but
the issues are the same):


http://www.monitorware.com/Common/en/FAQ/UNC-Path-Does-Not-Work-For-MWProducts.php

-- chris
 
C

ccjjharmon

I found it.... I had actually saved a link to a Sun forums thread about
this topic, but had forgot about it.... the thread is available at:

http://forum.java.sun.com/thread.jspa?threadID=695024&tstart=0

The key point? UNC works, but you have to use it with URI when
specifying new File(). What I was doing was using the File()
constructor using String as a parameter. What I needed to do was use a
URI object as a parameter! Someone posted some sample code that worked
for this guy, and it worked for me too. Here's the sample code that did
it:

URI myURI = new URI( "file://///server_one/images/unitMaps" );
File myFile = new File( myURI );

Newsgroups are just grand :) especially when posters include sample
code!! ;)


I still have Tomcat running as Local System, but I must specify the
share to have Everyone with sufficient access. Obviously to properly
secure the share, I would want to have a specific domain user created,
and have the share configured with the desired access, and run Tomcat
as this domain user... that's for later.

Cheers! And thanks for the comments.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top