SystemTests with Apache CXF, JAX-RS, JSON-P on Java 11

To use Apache CXF JAX-RS 2.X client with JSON-P on Java 11 you will have to include the following dependencies first:


<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
</dependency> 
<!-- Java 11 comes without the "enterprise" dependencies -->
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
    <scope>test</scope>
</dependency>   
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
    <scope>test</scope>
</dependency>   
<!-- cxf / JAX-RS client dependencies dependencies -->        
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-rs-client</artifactId>
    <version>3.1.4</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-rt-rs-extension-providers</artifactId>
    <version>3.2.7</version>
    <scope>test</scope>
</dependency>   
<!-- JSON-P -->             
<dependency>
    <groupId>org.glassfish</groupId>
    <artifactId>javax.json</artifactId>
    <version>1.1.4</version>
    <scope>test</scope>
</dependency>

The Java release version has to be set to 11 and the maven compiler to the most recent version:


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>11</release>
                    <source>11</source>
                </configuration>                
            </plugin>
        </plugins>        
    </build>    

You will have to register the JsrJsonpProvider to get automatic serialization into JSON-P objects:


public class HealthCheckIT {

    private Client client;
    private WebTarget tut;

    @Before
    public void init() {
        this.client = ClientBuilder.newClient().register(JsrJsonpProvider.class);
        this.tut = this.client.target("http://localhost:9080/health");
    }

    @Test
    public void health() {
        Response response = this.tut.request().get();
        assertThat(response.getStatus(), is(200));
        JsonObject health = response.readEntity(JsonObject.class);
        JsonArray checks = health.getJsonArray("checks");
        //...
    }
}
See you at Web, MicroProfile and Java EE Workshops at MUC Airport, particularly at the Java EE CI/CD, Testing and Quality workshop


Web Apps, SPA, PWA with vanilla Java Script (ES 6+), CSS 3 and WebStandards only. As simple as possible, but not simpler. See you at: (Progressive) Web apps, Single Page Apps and WebStandards airhacks workshops at MUC airport, Winter Edition

airhacks.fm the podcast:

Stay in touch: airhacks.news.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
Online Workshops
realworldpatterns.com
...the last 150 posts
...the last 10 comments
License