Error while running plugin where I included CXF and JAXRS

Hi,

I have built a plugin for Elastic and I also included CXF and JAXRS so that I could use the org.apache.cxf.jaxrs.client.WebClient like this:

try {
    String responseString = AccessController.doPrivileged((PrivilegedAction<String>) ()
    -> {
        Response response = WebClient.create(url).
                accept(MediaType.APPLICATION_JSON).
                type(MediaType.APPLICATION_JSON).
                post(new Gson().toJson(request));
        return response.readEntity(String.class);
    });
 } catch (Exception e) { }

now, when plugin is running and I make a request I get the following stack trace:

[2019-01-03T11:08:11,816][ERROR][o.e.t.n.Netty4Utils      ] fatal error on the network layer
        at org.elasticsearch.transport.netty4.Netty4Utils.maybeDie(Netty4Utils.java:182)
        at org.elasticsearch.http.netty4.Netty4HttpRequestHandler.exceptionCaught(Netty4HttpRequestHandler.java:176)
        at io.netty.channel.AbstractChannelHandlerContext.invokeExceptionCaught(AbstractChannelHandlerContext.java:285)
        at io.netty.channel.AbstractChannelHandlerContext.notifyHandlerException(AbstractChannelHandlerContext.java:850)
...
[ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [docker-single-node] fatal error in thread [Thread-4], exiting
java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
        at org.apache.cxf.service.model.EndpointInfo.setAddress(EndpointInfo.java:97) ~[?:?]
        at org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.createEndpointInfo(AbstractJAXRSFactoryBean.java:150) ~[?:?]
        at org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean.createEndpoint(AbstractJAXRSFactoryBean.java:219) ~[?:?]
        at org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean.createWebClient(JAXRSClientFactoryBean.java:220) ~[?:?]
        at org.apache.cxf.jaxrs.client.WebClient.create(WebClient.java:115) ~[?:?]
...
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
        at java.net.URLClassLoader.findClass(URLClassLoader.java:466) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:566) ~[?:?]
        at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:890) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:499) ~[?:?]

Here are some dependencies I used:

<dependency>
  <groupId>javax.ws.rs</groupId>
  <artifactId>javax.ws.rs-api</artifactId>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-databind</artifactId>
  <exclusions>
    <exclusion>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>com.fasterxml.jackson.core</groupId>
  <artifactId>jackson-annotations</artifactId>
</dependency>

Any idea about the source of the issue?

Thanks a lot!

Ok I solved it by adding:

<dependency>
  <groupId>javax.xml.bind</groupId>
  <artifactId>jaxb-api</artifactId>
  <version>2.2.11</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-core</artifactId>
  <version>2.2.11</version>
</dependency>
<dependency>
  <groupId>com.sun.xml.bind</groupId>
  <artifactId>jaxb-impl</artifactId>
  <version>2.2.11</version>
</dependency>
<dependency>
  <groupId>javax.activation</groupId>
  <artifactId>activation</artifactId>
  <version>1.1.1</version>
</dependency>

and removing:

<dependency>
  <groupId>javax.ws.rs</groupId>
  <artifactId>javax.ws.rs-api</artifactId>
</dependency>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.