<commit_before>= JAX-RS Health Endpoints

See also the userguide section for monitoring and security realms:
https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/advanced/monitoring.html

This example uses the `monitor` and `management` fractions
so that the JAX-RS endpoints can securely expose health checks to service registries.

> Please raise any issues found with this example in our JIRA:
> https://issues.jboss.org/browse/SWARM

== Project `pom.xml`

The project is a normal maven project with `jar` packaging, not `war`.

[source,xml]
----
<packaging>jar</packaging>
----

The project adds a `<plugin>` to configure `wildfly-swarm-plugin` to
create the runnable `.jar`.

[source,xml]
----
<plugin>
  <groupId>org.wildfly.swarm</groupId>
  <artifactId>wildfly-swarm-plugin</artifactId>
  <version>${version.wildfly-swarm}</version>
  <configuration>
    <mainClass>org.wildfly.swarm.examples.jaxrs.health.Main</mainClass>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>package</goal>
      </goals>
    </execution>
  </executions>
</plugin>
----

To define the needed parts of WildFly Swarm, dependencies are added

[source,xml]
----
<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>jaxrs</artifactId>
    <version>${version.wildfly-swarm}</version>
</dependency>

<dependency>
       <groupId>org.wildfly.swarm</groupId>
       <artifactId>monitor</artifactId>
       <version>${version.wildfly-swarm}</version>
</dependency>
----

== Project `main()`

Since this project deploys JAX-RS resources without a `.war` being constructed, it
provides its own `main()` method (specified above via the `wildfly-swarm-plugin`) to
configure the container and deploy the resources programatically.

[source,java]
----
include::src/main/java/org/wildfly/swarm/examples/jaxrs/health/Main.java[lines=15..42]
----

This method constructs a new default Container, and
adds the monitoring and management fractions that provide the /health endpoints and security to them.

== @Health Annotations

In our example, we annotate the JAX-RS resource to be exposed as a health endpoint:

[source,java]
----
include::src/main/java/org/wildfly/swarm/examples/jaxrs/health/HealthCheckResource.java[lines=14..22]
----

By pointing your browser at http://localhost:8080/health you should be prompted for credentials (see security domain setup) and
be able to retrieve the health response.

== Run

You can run it many ways:

* mvn package && java -jar ./target/example-jaxrs-health-swarm.jar
* mvn wildfly-swarm:run
* In your IDE run the `org.wildfly.swarm.examples.jaxrs.health.Main` class

== Use

To `GET` the health response

    http://localhost:8080/health
<commit_msg>Update README as GH doesn't like include<commit_after>= JAX-RS Health Endpoints

See also the userguide section for monitoring and security realms:
https://wildfly-swarm.gitbooks.io/wildfly-swarm-users-guide/content/advanced/monitoring.html

This example uses the `monitor` and `management` fractions
so that the JAX-RS endpoints can securely expose health checks to service registries.

> Please raise any issues found with this example in our JIRA:
> https://issues.jboss.org/browse/SWARM

== Project `pom.xml`

The project is a normal maven project with `jar` packaging, not `war`.

[source,xml]
----
<packaging>jar</packaging>
----

The project adds a `<plugin>` to configure `wildfly-swarm-plugin` to
create the runnable `.jar`.

[source,xml]
----
<plugin>
  <groupId>org.wildfly.swarm</groupId>
  <artifactId>wildfly-swarm-plugin</artifactId>
  <version>${version.wildfly-swarm}</version>
  <configuration>
    <mainClass>org.wildfly.swarm.examples.jaxrs.health.Main</mainClass>
  </configuration>
  <executions>
    <execution>
      <goals>
        <goal>package</goal>
      </goals>
    </execution>
  </executions>
</plugin>
----

To define the needed parts of WildFly Swarm, dependencies are added

[source,xml]
----
<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>jaxrs</artifactId>
    <version>${version.wildfly-swarm}</version>
</dependency>

<dependency>
       <groupId>org.wildfly.swarm</groupId>
       <artifactId>monitor</artifactId>
       <version>${version.wildfly-swarm}</version>
</dependency>
----

== Project `main()`

Since this project deploys JAX-RS resources without a `.war` being constructed, it
provides its own `main()` method (specified above via the `wildfly-swarm-plugin`) to
configure the container and deploy the resources programatically.

[source,java]
----
include::src/main/java/org/wildfly/swarm/examples/jaxrs/health/Main.java[lines=15..42]
----

See: link:src/main/java/org/wildfly/swarm/examples/jaxrs/health/Main.java#L15[Main.java]

This method constructs a new default Container, and
adds the monitoring and management fractions that provide the /health endpoints and security to them.

== @Health Annotations

In our example, we annotate the JAX-RS resource to be exposed as a health endpoint:

[source,java]
----
include::src/main/java/org/wildfly/swarm/examples/jaxrs/health/HealthCheckResource.java[lines=14..22]
----

See: link:src/main/java/org/wildfly/swarm/examples/jaxrs/health/HealthCheckResource.java#L14[HealthCheckResource.java]

By pointing your browser at http://localhost:8080/health you should be prompted for credentials (see security domain setup) and
be able to retrieve the health response.

== Run

You can run it many ways:

* mvn package && java -jar ./target/example-jaxrs-health-swarm.jar
* mvn wildfly-swarm:run
* In your IDE run the `org.wildfly.swarm.examples.jaxrs.health.Main` class

== Use

To `GET` the health response

    http://localhost:8080/health

{'fraction_non_alphanumeric': 0.12788038698328935, 'fraction_numerical': 0.0063324538258575196, 'mean_word_length': 4.155031731640979, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 85, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6477525', 'n_tokens_mistral': 1915, 'n_tokens_neox': 1750, 'n_words': 498}