sebastiandaschner blog


Released JAX-RS Analyzer

sunday, march 01, 2015

As part of my bachelor thesis in computer science I developed a bytecode analysis approach, which gathers information about objects returned by methods. I used this approach to get information about JAX-RS resource methods. The JAX-RS Analyzer tool came as the result of this. It analyzes JAX-RS projects and generates an overview of all REST resources.

Doing the JAX-RS analysis via bytecode inspection rather than Java reflection has the advantage of seeing the statements in method bodies. This can be helpful when REST meta information is defined programmatically like:

@POST
public Response post(Model model) {
    // do something
    return Response.accepted().build();
}

The status code 202 Accepted can only be collected by analyzing the method body.

The tool outputs the information either as plain text or in the Swagger API format (as Swagger JSON).

To include the JAX-RS Analyzer in the Maven build process of a project, simply add these lines to your pom.xml in the <plugins> section.

<plugin>
    <groupId>com.sebastian-daschner</groupId>
    <artifactId>jaxrs-analyzer-maven-plugin</artifactId>
    <version>0.2</version>
    <executions>
        <execution>
            <goals>
                <goal>analyze-jaxrs</goal>
            </goals>
            <configuration>
                <!-- Available backends, defaults to plaintext -->
                <!-- <backend>plaintext</backend> -->
                <!-- <backend>swagger</backend> -->
            </configuration>
        </execution>
    </executions>
</plugin>

After building your project, the documentation resides under target/jaxrs-analyzer/.

 

Found the post useful? Subscribe to my newsletter for more free content, tips and tricks on IT & Java: