Marc Meister
Marc Meister

Reputation: 197

Check if Wildfly Server is running with my app?

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.

Upvotes: 5

Views: 7523

Answers (3)

hestellezg
hestellezg

Reputation: 3711

I aws looking for something to check if wildfly is running, here I saw:

systemctl status wildfly

And also were so useful:

systemctl stop wildfly
systemctl restart wildfly
systemctl start wildfly

Upvotes: 0

Aparna Chaudhary
Aparna Chaudhary

Reputation: 1335

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

Upvotes: 2

stdunbar
stdunbar

Reputation: 17455

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.

Upvotes: 3

Related Questions