Search code examples
restclientjax-rswildfly-swarm

Wildfly-Swarm Jax-RS Client


I have a Wildfly-Swarm server running, but it needs to send a request to another rest-server. I tried using JAX-RS-Client, but failed.

The Code-Snipped executing the Request is

Client client = ClientBuilder.newClient();
Invocation.Builder request = client.target(automatonUri)
    .path("/self/isAlive")
    .request(MediaType.APPLICATION_JSON);
boolean isAlive = request.get(Boolean.class);

When running this, I always get the java.lang.ClassNotFoundException: org.glassfish.jersey.client.JerseyClientBuilder Exception.

I'm using the following fractions:

<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>jaxrs</artifactId>
</dependency>
<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>ejb</artifactId>
</dependency>
<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>cdi</artifactId>
</dependency>
<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>microprofile</artifactId>
</dependency>
<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>logging</artifactId>
</dependency>

I tried adding

<dependency>
    <groupId>org.wildfly.swarm</groupId>
    <artifactId>jaxrs-client-api</artifactId>
</dependency>

But then I just get com.sun.jersey.api.container.ContainerException: No WebApplication provider is present when running any junit test.

Any idea? Or any example I could look at? Thank you.


Solution

  • I think you need to add an explicit dependency on RESTEasy Client, something like

            <dependency>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>resteasy-client</artifactId>
                <version>${version.org.jboss.resteasy}</version>
            </dependency>