Consul Java Api NoClassDefFoundError

344 views
Skip to first unread message

Lorenz Reinhart

unread,
Apr 19, 2016, 7:28:35 AM4/19/16
to ONOS Discuss
 Hi,

i'm trying to use the service discovery tool Consul in my onos application. There is also a Java Api and client provided on their webpage.
My intention is to get the services registered in consul. Therefore i import the maven dependencies into IntelliJ and use them as any other dependency.
The following is happening with both, the api and the client. The jar files of the dependency are provided in the .m2 folder of the machine onos is running on.
I can compile my app and provide it into onos via "onos-app" without a problem, but as soon as the code is calling something out of the
consul library, onos gives me following error:

2016-04-19 10:45:30,617 | ERROR | qtp2105435835-67 | ContainerResponse                | 135 - com.sun.jersey.jersey-server - 1.19.0 | The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java
.lang.NoClassDefFoundError: com/ecwid/consul/v1/ConsulClient
    at uni
.wue.app.consul.ConsulServiceApi.connectConsul(ConsulServiceApi.java:51)[182:uni.wue.onos-byod:1.0.0.SNAPSHOT]
    at uni
.wue.app.rest.AppWebConsul.postConsul(AppWebConsul.java:71)[182:uni.wue.onos-byod:1.0.0.SNAPSHOT]
    at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_72]
    at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_72]
    at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_72]
    at java
.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_72]
    at com
.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
    at com
.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
    at com
.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
    at com
.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
    at com
.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com
.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
    at com
.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
    at com
.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
    at com
.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)[135:com.sun.jersey.jersey-server:1.19.0]
    at com
.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)[135:com.sun.jersey.jersey-server:1.19.0]
    at com
.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)[135:com.sun.jersey.jersey-server:1.19.0]
    at com
.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)[135:com.sun.jersey.jersey-server:1.19.0]
    at com
.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)[136:com.sun.jersey.servlet:1.19.0]
    at com
.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)[136:com.sun.jersey.servlet:1.19.0]
    at com
.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)[136:com.sun.jersey.servlet:1.19.0]
    at javax
.servlet.http.HttpServlet.service(HttpServlet.java:668)[102:org.apache.geronimo.specs.geronimo-servlet_3.0_spec:1.0.0]
    at org
.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:684)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:69)[117:org.ops4j.pax.web.pax-web-jetty:3.1.4]
    at org
.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:522)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1086)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:240)[117:org.ops4j.pax.web.pax-web-jetty:3.1.4]
    at org
.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:429)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1020)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:75)[117:org.ops4j.pax.web.pax-web-jetty:3.1.4]
    at org
.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.server.Server.handle(Server.java:370)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:494)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:971)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:1033)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:644)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:696)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:53)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at org
.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543)[108:org.eclipse.jetty.aggregate.jetty-all-server:8.1.15.v20140411]
    at java
.lang.Thread.run(Thread.java:745)[:1.8.0_72]
Caused by: java.lang.ClassNotFoundException: com.ecwid.consul.v1.ConsulClient not found by uni.wue.onos-byod [182]
    at org
.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)
    at org
.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)
    at org
.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
    at java
.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_72]
   
... 48 more

The java code is as following:

package uni.wue.app.consul;

import com.ecwid.consul.v1.ConsulClient;
import com.ecwid.consul.v1.QueryParams;
import com.ecwid.consul.v1.Response;
import org.apache.felix.scr.annotations.Component;
import org.onlab.packet.IpAddress;
import org.onlab.packet.TpPort;
import org.slf4j.Logger;

import java.util.List;
import java.util.Map;

import static org.slf4j.LoggerFactory.getLogger;

/**
 * Created by lorry on 19.04.16.
 */
@Component(immediate = true)
@org.apache.felix.scr.annotations.Service
public class ConsulServiceApi implements ConsulService {

   
private static final Logger log = getLogger(uni.wue.app.PortalManager.class);

   
/**
     * Connect to a running consul agent.
     *
     * @param ipAddress Ip address to connect to
     * @param tpPort    transport protocol port
     */
    @Override
    public void connectConsul(IpAddress ipAddress, TpPort tpPort) {

       
ConsulClient consulClient = new ConsulClient("127.0.0.1");

       
QueryParams params = new QueryParams("dc1");
       
Response<Map<String, List<String>>> response = consulClient.getCatalogServices(params);

       
log.info("Services: " + response.getValue());

   
}
}


I hope someone has an idea how i can get this to work with onos.
Thanks for your help in advance.

Kind regards
Lorenz

Thomas Vachuska

unread,
Apr 19, 2016, 12:29:56 PM4/19/16
to Lorenz Reinhart, ONOS Discuss
In order to make the consul jar available to your application at run-time, you need to include it in your features.xml file. Simple, single-bundle apps, don’t need to have this file as it will be automatically generated by the onos-maven-plugin, but if you need to include other bundles, you need to create your own features.xml file (located at the top directory, next to the pom.xml file). Note that in this case, you may also have to make sure that app.xml file includes the consul jar artifact if such artifact is not available on Maven central and/or if you want to assure that offline installation of your application is possible.

Secondly, you have to make sure that the consul jar is in fact an OSGi bundle. If not, you can use the “wrap:” syntax in the features.xml file to have karaf import the JAR file and wrap/treat it as an OSGi bundle. There are examples of multi-bundle features.xml files as well as the wrap syntax in ONOS code-base; apps/cpman/app/features.xml is one such example.

 
--
You received this message because you are subscribed to the Google Groups "ONOS Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to onos-discuss...@onosproject.org.
To post to this group, send email to onos-d...@onosproject.org.
Visit this group at https://groups.google.com/a/onosproject.org/group/onos-discuss/.
To view this discussion on the web visit https://groups.google.com/a/onosproject.org/d/msgid/onos-discuss/219ebf2c-4278-41a0-b0d5-ee03127d275a%40onosproject.org.

Lorenz Reinhart

unread,
Apr 21, 2016, 10:36:43 AM4/21/16
to ONOS Discuss, lor...@googlemail.com
Hi,

thanks for your quick response.
I've did like you said, and included the maven dependency to the features and app xml files:

<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="onos-byod-1.0-SNAPSHOT">
<feature name="onos-byod" version="1.0-SNAPSHOT"
description="ONOS OSGi bundle archetype">
<feature>onos-api</feature>
<bundle>mvn:uni.wue/onos-byod/1.0-SNAPSHOT</bundle>
<bundle>wrap:mvn:com.orbitz.consul/consul-client/0.10.1$Bundle-SymbolicName=consul-client&amp;Bundle-Version=0.10.1;</bundle>
</feature>
</features>

<app name="uni.wue.app" origin="Uni Wuerzburg" version="1.0-SNAPSHOT"
featuresRepo="mvn:uni.wue/onos-byod/1.0-SNAPSHOT/xml/features"
features="onos-byod" apps="">
<description>ONOS OSGi bundle archetype</description>
<artifact>mvn:uni.wue/onos-byod/1.0-SNAPSHOT</artifact>
<artifact>mvn:com.orbitz.consul/consul-client/0.10.1</artifact>
</app>

The maven dependency in the pom file is like this:

<dependency>
<groupId>com.orbitz.consul</groupId>
<artifactId>consul-client</artifactId>
<version>0.10.1</version>
</dependency>

Maven is now including the consul.jar file into the oar file of the application as i wished. But when i use my application in Onos, the same NoClassDefFoundError as described above is produced.
I don't know if the dependency is wraped correct, and if the features are installed the way they should. How can i check this?

The feature:repo-list command gives me following output for my app:
onos-byod-1.0-SNAPSHOT                | mvn:uni.wue/onos-byod/1.0-SNAPSHOT/xml/features

And the feature:list command this:
onos-byod                       | 1.0-SNAPSHOT     | x         | onos-byod-1.0-SNAPSHOT                | ONOS OSGi bundle archetype

This is the feature:info:
Feature onos-byod 1.0-SNAPSHOT
Description:
  ONOS OSGi bundle archetype
Feature has no configuration
Feature has no configuration files
Feature depends on:
  onos-api 0.0.0
Feature contains followed bundles:
  mvn:uni.wue/onos-byod/1.0-SNAPSHOT
  wrap:mvn:com.orbitz.consul/consul-client/0.10.1$Bundle-SymbolicName=consul-client&Bundle-Version=0.10.1
Feature has no conditionals.

Thanks for your help

Best regards
Lorenz
...

Lorenz Reinhart

unread,
May 3, 2016, 11:07:57 AM5/3/16
to ONOS Discuss, lor...@googlemail.com
I think my problem was, not defining the "onos-api" version in the "features.xml" file.
Thus Onos didn't know on what feature my bundles depend.
Sometimes it is also very wise to restart Onos.

The following is working for me:

<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="onos-byod-1.0-SNAPSHOT">
<feature name="onos-byod" version="1.0-SNAPSHOT"
description="ONOS OSGi bundle archetype">
        <feature version="1.5.1">onos-api</feature>

<bundle>mvn:uni.wue/onos-byod/1.0-SNAPSHOT</bundle>
<bundle>wrap:mvn:com.orbitz.consul/consul-client/0.10.1$Bundle-SymbolicName=consul-client&amp;Bundle-Version=0.10.1</bundle>
        <bundle>mvn:com.fasterxml.jackson.datatype/jackson-datatype-guava/2.6.3</bundle>
<bundle>mvn:javax.ws.rs/javax.ws.rs-api/2.0.1</bundle>
</feature>
</features>

But now i have another problem, with including the javax.ws.rs-api.
I'll ask this in a new thread, as it has not much to do with this question.

Best regards
Lorenz


Reply all
Reply to author
Forward
0 new messages