How can I check if a .war is deployed - java

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.

Related

Microservices and Rest services deployed as jar file?

Let's take the simple example, where I have multiplication service as part of single monolithic MathService(deployed as war).
Now I need to deploy multiplication service as separate service(rest service) which MathService can call. The concept of dividing the single monolithic
in to small maintainable service is microservice.
But I am not sure is it mandatory to deploy Multiplication service as war file? Can it be still deployed as jar file on the web server?
My understanding is that it should be war file as rest calls(HTTP call) needs to be handled by the servlet. Including servlet means it has to be war file.
Is that correct?
No, it's not mandatory to deployed war file, microservices can also be deployed as jar or war file on the server.
you can also run your microservices as the jar file in external tomcat server
Read this.
No.
Indeed, to work with web server, you would need a war file. But Web server just for receiving and responding network connections. You absolutely can manage connections by your self, with jdk or 3rd party libraries like netty. So you can just build a standalone java application, which actually can be called as a web server.
If you mean "can I deploy service without WAR?", then the answer is no, because the service should be a part of some WAR. If you mean "should every microservice be put to a separate WAR", the answer is not so simple. WAR should contain a single microservice. And dont think of microservice as a technically single end point, single REST or SOAP service, it can consist of several such services/endpoints.

Run a file locally in java (reach with 'localhost')

I've been requested at work to run a file (server app) locally (so I will have it in localhost) and then send http get requests as I desire.
(I'm using get requests in the form "wget ..... http://localhost:4567/XXXX"
XXXX contains the name of the item I'm trying to receive.
I'm not familiar with the term 'run a file locally'. Can anyone explain / direct me to a website that explains about it?
Suppose my server file name is 'server'. How do I run the file (locally) in java? (so I'll be able to send HTTP get requests as I've mentioned above)
Are you asking for running html files locally so that they can be accessed through a port? If this is the case you need to have a http server on your desktop/laptop and configure it to enable your html files. If it is complete J2EE/.Net/any other platform applications, we need to install appropriate web/application server and run the same.
You have to create webservices and define its path. Suppose if you create a method give it a #Path('someName'). Define what it should consume and what it should produce using #Consumes(MEDIA_TYPE.xxx) #Produces(MEDIA_TYPE.xxx). The whole project will have a base path like restApi. Run it using apache tomcat i desired port. Access the rest api with the url http://localhost:8080/restApi/someName. Refer java webservices for more details. Its very simple. Starting configuration may take some time. So start with a maven artifact for java webservises to have a head start.
If you only want to send some GET requests to check the responses I would use a simple REST client like Postman. Just enter your URL, choose the GET method and send the request.
To run something locally means that the server is installed locally. You would deploy your file/s (.war or .ear in the case of java) to this local server. After that you can access the deployed services via http://localhost:port/...

Can't locate the file on local file system from Servlet

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.

Preventing multiple downloads for Java Web Start/JNLP

We have a Swing application which initiated from the Web application by clicking a link. The link is nothing but a JNLP url. There is a jar file hosted on our four servers under Apache. These are under a load balancer. Even though the same jar is hosted with the same time stamp but more or less every request to the JNLP the jar is gettign downloaded. Generally if there is no change in the jar the java Web start downloads only once and subsequent requests are works without downloading. What else the info it checks to compare with server version and local copy of jar?
Jar is hosted in Apache and by default apache looks at three things (timestamp+size+ETAG)
Since it is hosted in four apache servers the ETAG for each server is different and that is why it downloads whenever the request goes to one of these four servers. The fix is to remove the ETAG by overriding the apache configuration.

show files at a URL

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).

Categories

Resources