I would like to know how can I check if my Wildfly Server is running and the WebApp has been deployed?
Currently I check only if the server is running.
public static boolean checkServerAvailable() {
try {
String url = Constants.URL_APP + ":" + Constants.APPSERVER_PORT;
HttpURLConnection.setFollowRedirects(false);
// note : you may also need
// HttpURLConnection.setInstanceFollowRedirects(false)
HttpURLConnection con = (HttpURLConnection) new URL(url)
.openConnection();
con.setRequestMethod("HEAD");
if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
return true;
}
else
return false;
} catch (Exception e) {
return false;
}
}
But I need to know if the Wildfly server also my web app deployed successull.
To start with you could add your webapp url to the url you're creating above. Instead of connecting to, for example, http://localhost:8080/ and looking for a HTTP 200 response, you could connect to http://localhost:8080/yourApp and do the same. That implies that you have something at the root context to respond.
An arguably better solution would be to have a "heartbeat" or "status" service in your web application. This would be something like http://localhost:8080/yourApp/status. The method or service could just return a 200 implying that the service is up. But it could also really check that your application is healthy. For example, it could check available memory or make sure that the database is up or a multitude of other things. The code you show would just use the full URL of the status service.
You can use the management API provided by WildFly. The API is described here for different versions of WildFly.
For WildFly9 - See https://wildscribe.github.io/Wildfly/9.0.0.Final/deployment/index.html
You could use following URL to check the status of deployment. You do need a management user for authentication.
Standalone Mode:
http://localhost:9990/management/deployment/<deployment_name>
For domain mode:
http://localhost:9990/management/host/<host_name>/server/<serer_name>/deployment/<deployment_name>
Sample JSON response (assuming you deployed an EAR file with some sub-deployments):
{
"content": [{
"hash": {
"BYTES_VALUE": "2gH7ddtUxsbzBJEJ/z4T1jYERRU="
}
}],
"enabled": true,
"enabled-time": 1468861076770,
"enabled-timestamp": "2016-07-18 18:57:56,770 CEST",
"name": "myapplication.ear",
"owner": null,
"persistent": true,
"runtime-name": "myapplication.app.ear",
"subdeployment": {
"myapplication.impl.jar": null,
"myapplication.web.war": null
},
"subsystem": null
}
Sample request using curl:
curl --digest -D - http://localhost:9990/management --header "Content-Type: application/json" -d '{"operation":"read-resource", "include-runtime":"true", "address":["deployment","myapplication.app.ear"] }' -u user:password
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With