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).
Related
I use AWS EC2 Linux instance, where my tomcat Java based web server is deployed.
My server need to frequently read and write a group of "text files". And these files shouldn't be over written each time I deploy a new version of WAR file. ( Means , even after new war file deployed, the existing text files should be kept as it is )
Please suggest the suitable file location in EC instance, from where the web server can frequently access at the same time, the folder data is untouched with restart or with the deployment of new version of war.
Assuming that there is a different user running Tomcat (i.e. a tomcat user) I would put the files in that users home directory. It should be as easy as accessing the files with something like:
File file = new File( System.getProperty("user.home") + "/somedir/file.txt" );
The directory should already exist and be owned by the same user as Tomcat is running as.
One caveat is that, depending on your EC2 file system, it may be harder to recreate your environment in the event of a machine crash. You'll need to make sure that the directory in which you store your files is somehow backed up. Storing on EFS will help but may not be enough. Longer term you might want to think about a database of some sort.
I have deployed a .war file with the following command:
java -jar myfile.war
what is the command to check if the file is deployed and running?
WARs are not deployed like this by default. They are intended originally to be put into some kind of servers (like Tomcat). This means physically putting the file into some predefined folders.
Since you obviously don't work like this, its kind of not-enough information to provide a server specific answer.
So I'll provide only general ways:
Option 1
Run an HTTP request (you can even create a special "/health" endpoint). Then just call this request and if it responds with something that you expect to receive, then the war is deployed.
Option 2
When the War is deployed programmatically create some kind of listener where you can LOG something on console / create a file on filesystem that will denote that the service is up and running.
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 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.
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.