I wrote a RESTful web service using Jersey library and in order to respond to the request I have to read a text file in local file system. C:\data.txt. The servlet works fine when I run it with tomcat on my own laptop.
But when I deploy the war on another machine running windows server OS and place the data.txt again at C:\data.txt. The servlet can't locate the file correctly. Anyone has idea about why is this?
Thanks a lot!
Check whether the Tomcat server process has read-access rights to file C:\data.txt. Check which user is used for running the tomcat process and check the corresponding user file permissions.
I also suspect it is a security error. Applications are usually restricted to reading and writing within their own directory under $TOMCAT_HOME/webapps. If this is the case, you need to change $TOMCAT_HOME/conf/catalina.policy to allow you to access other directories.
If you don't need to write to the file, consider moving its location inside of the classpath by putting in into $TOMCAT_HOME/lib instead.
I think this approach is also better in regards to being cross-platform.
Related
I am working on a feature where i have to provide a direct link to download certain files. all my files are in htdocs folder and i want to provide a direct link to download them like
webapp.com/files/file1.avi
could write a servlet and send the user a file.I know how to do it.
The other way is that if i directly go to webapp.com/files i should be able to see all of the files present in the directory. How do i do that?
do i have to make any server config changes to achieve it?
the webapp is running on Apache tomcat and jdk 1.4
You can directly serve your static content from tomcat(if it is your app server) root directory. I assume other app/web servers will have a static content directory as well.
I have a Windows service that executes a .bat file. This .bat file executes some Sava code that reads some files' information. The files I need to access are not in the same machine that the service is running. So I should access them using a mapping like G:\.
Even if the files exist on G:\ when I run the service, File exists() and File canRead() always return false.
If I execute the .bat manually, everything works great, but I need to execute it using a service.
The service is running with a user that has permissions to read all files on this G:\ mapping.
Does anyone have a clue as to what can be wrong? Why can't I access these remote files, when running as a Windows service?
The OS in question is Windows XP.
The problem usually is that the user running the service does not have the same G: drive as well as the same access.
I suggest you log in as the user running the service and see what that user sees.
Drive mappings aren't shared between sessions, and service sessions don't get drive mappings reestablished automatically the way interactive sessions do. You should put a net use command in the batch file to explicitly establish the drive mapping in the service session.
I have 2 application deployed on my server and first application is suppose to list the files in a folder in another application.
But the problem is these two application may be deployed on 2 different physical servers. So is it possible to fetch the files from the URL
i.e is there a way something like
List<file> getFileList(<URL>/folderName) ;
That's not possible by HTTP. Use FTP or let the server platform mount it on the local disk file system.
As #BalusC said, by HTTP it is not possible... unless you write a special script of your own returning a list of files in the folder you need (with permissions check, of course).
I'm working on a beta release of an application. This is a Java app that runs on Glassfish. Obviously we are getting bug reports from time to time. I would like to provide my users with a simple one-click button to get the server log from /domains/domain1/logs . I am not sure if the application is sandboxed in such a way that it can get to this log file.
Does glassfish sandbox the application in such a way that I would be prevented from getting the file? Is there a standard method or library I can use to get the logs?
If the file permissions on the server are correct, can I just have my application read the file using an absolute path?
You application can read the server.log file directly. Note that the logs are rotated, so your application would have to reload the log file and maybe even provide access to the rotated logs.
If you are using a web server front end, such as Apache, you could just serve the log directory. I think you could just create a symbolic link to that directory in your webroot.
Be careful you are not logging any sensitive information as exposing a log file could be a security risk.
If you are using GlassFish 2.1, you should look at AMX. The AMX class Logging seems to have the data that you want.
If you are using GlassFish 3.1, you should use the RESTful interface to the admin data. If you have an instance of GlassFish 3.1 running locally, right now, you can click this link to see the log data: http://localhost:4848/management/domain/view-log...
If you are using a WebKit based
browser, like Chrome or Safari, you
probably need to view the source of
the 'empty' page....
If you are using GlassFish 3.0, you will need to open the file directly.
I have a java application that, at some stage, select files from the local filesystem using JFileChooser.showOpenDialog().
Now I want it in a client-server setup. This means opening a GUI(file browser) for selecting files on the server. I have already tried several scenarios to keep using the JFileChooser, but I cant get the correct setup working.
Does anyone know how to construct a file browser on the remote server if i know the path the file browser needs to default to in advance?
So for eg: if the server address is "http://sand.int.group.com:9083" and on this address the directory that i want to default to is at "/home/myDir/". How can I display the file browser window so that it lists the files located in the directory on this server?
JFileChooser can't load a URL. You will need to map a network share on the machine that wants to browse to the files.
This will serve you purpose, I believe: http://vfsjfilechooser.sourceforge.net/index.html
A remote file chooser based on JFileChooser code...
AFAIK this is not working out of the box. The local JFileChooser has no idea about files located on server side.
Take WebSphere for example, with the Websphere admin tool you can deploy local EAR/WAR files to the server, IBM is doing this with a JFileChooser. But when you are going to deploy a file which is on the remote server you get a completely different UI. So it seems to be very tricky.
One possible way might be to implement your own FileSystemView, but I am not sure, this is just an idea.