karaf-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Baptiste Onofré ...@nanthrax.net>
Subject Re: Jackson Module Afterburner not working in Karaf 3.0.5
Date Sun, 08 May 2016 07:25:36 GMT
It's not a Karaf issue ;)

As you can see in bundle:headers, the package 
com.fasterxml.jackson.module.afterburner.ser is not imported, so not in 
the classloader: that's the issue.

Just add com.fasterxml.jackson.module.afterburner.ser in the Import-Package.

Regards
JB

On 05/08/2016 09:21 AM, Debraj Manna wrote:
> I updated to the latest Jackson:-
>
> |karaf@root>bundle:list | grep jackson 124 | Active | 50 | 2.6.2 |
> jackson-databind 239 | Active | 80 | 2.7.4 | jackson-databind
> karaf@root>bundle:list | grep Jackson 123 | Active | 50 | 2.6.2 |
> Jackson-core 125 | Active | 50 | 2.6.2 | Jackson-annotations 237 |
> Active | 80 | 2.7.4 | Jackson-core 238 | Active | 80 | 2.7.4 |
> Jackson-annotations 240 | Active | 80 | 2.7.1 | Jackson-module-Afterburner|
>
> The Hello World Bundle is active:-
>
> *karaf@root*>bundle:list | grep Hello
>
> 243 | Active |  80 | 0.0.1                              | HelloWorld
>
>
> So bundle:headers is also showing correct wiring:-
>
> *karaf@root*>bundle:headers 243
>
>
> Hello World (243)
>
> -----------------
>
> Created-By = Apache Maven Bundle Plugin
>
> Manifest-Version = 1.0
>
> Bnd-LastModified = 1462691114227
>
> Build-Jdk = 1.8.0_77
>
> Built-By = debraj
>
> Tool = Bnd-2.1.0.20130426-122213
>
>
> Bundle-ManifestVersion = 2
>
> Bundle-SymbolicName = world
>
> Bundle-Version = 0.0.1
>
> Bundle-Name = Hello World
>
> Bundle-Activator = com.hello.world.HelloWorldActivator
>
>
> Export-Package =
>
> com.hello;version=0.0.1,
>
> com.hello.world;uses:=org.osgi.framework;version=0.0.1
>
> Import-Package =
>
> com.fasterxml.jackson.databind;resolution:=optional;version="[2.7,3)",
>
> com.fasterxml.jackson.module.afterburner;
>
> resolution:=optional;
>
> version="[2.7,3)",
>
> org.osgi.framework;resolution:=optional;version="[1.6,2)"
>
>
> But now getting the below error. It seems Karaf is not able to load
> classes at run time.
>
> |com.fasterxml.jackson.databind.JsonMappingException: Failed to load
> class 'com.hello.world.JsonDataBlob$Access4JacksonDeserializerb9aaf44d':
> com.fasterxml.jackson.module.afterburner.ser.BeanPropertyAccessor at
> com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:312)
> at
> com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1172)
> at
> com.fasterxml.jackson.databind.SerializerProvider.findValueSerializer(SerializerProvider.java:490)
> at
> com.fasterxml.jackson.databind.SerializerProvider.findTypedValueSerializer(SerializerProvider.java:688)
> at
> com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:107)
> at
> com.fasterxml.jackson.databind.ObjectMapper._configAndWriteValue(ObjectMapper.java:3631)
> at
> com.fasterxml.jackson.databind.ObjectMapper.writeValueAsString(ObjectMapper.java:2998)
> at
> com.hello.world.HelloWorldActivator.getJsonDataAsString(HelloWorldActivator.java:26)
> at
> com.hello.world.HelloWorldActivator.start(HelloWorldActivator.java:13)
> at
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
> at org.apache.felix.framework.Felix.activateBundle(Felix.java:2146) at
> org.apache.felix.framework.Felix.startBundle(Felix.java:2064) at
> org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955) at
> org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942) at
> org.apache.karaf.bundle.command.Start.executeOnBundle(Start.java:27) at
> org.apache.karaf.bundle.command.BundlesCommandWithConfirmation.doExecute(BundlesCommandWithConfirmation.java:53)
> at
> org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:50)
> at
> org.apache.karaf.bundle.command.BundlesCommandWithConfirmation.doExecute(BundlesCommandWithConfirmation.java:41)
> at
> org.apache.karaf.shell.console.AbstractAction.execute(AbstractAction.java:33)
> at
> org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:39)
> at
> org.apache.karaf.shell.commands.basic.AbstractCommand.execute(AbstractCommand.java:33)
> at Proxy836eebee_bd0c_424a_b0d9_7fc71158b4ca.execute(Unknown Source) at
> Proxy836eebee_bd0c_424a_b0d9_7fc71158b4ca.execute(Unknown Source) at
> org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)
> at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480) at
> org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)
> at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108) at
> org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182) at
> org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119) at
> org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)
> at
> org.apache.karaf.shell.console.impl.jline.ConsoleImpl.run(ConsoleImpl.java:210)
> at
> org.apache.karaf.shell.console.impl.jline.LocalConsoleManager$2$1$1.run(LocalConsoleManager.java:109)
> at java.security.AccessController.doPrivileged(Native Method) at
> org.apache.karaf.jaas.modules.JaasHelper.doAs(JaasHelper.java:57) at
> org.apache.karaf.shell.console.impl.jline.LocalConsoleManager$2$1.run(LocalConsoleManager.java:102)
> Caused by: java.lang.IllegalArgumentException: Failed to load class
> 'com.hello.world.JsonDataBlob$Access4JacksonDeserializerb9aaf44d':
> com.fasterxml.jackson.module.afterburner.ser.BeanPropertyAccessor at
> com.fasterxml.jackson.module.afterburner.util.MyClassLoader.loadAndResolve(MyClassLoader.java:100)
> at
> com.fasterxml.jackson.module.afterburner.ser.PropertyAccessorCollector.generateAccessorClass(PropertyAccessorCollector.java:171)
> at
> com.fasterxml.jackson.module.afterburner.ser.PropertyAccessorCollector.findAccessor(PropertyAccessorCollector.java:97)
> at
> com.fasterxml.jackson.module.afterburner.ser.SerializerModifier.changeProperties(SerializerModifier.java:63)
> at
> com.fasterxml.jackson.databind.ser.BeanSerializerFactory.constructBeanSerializer(BeanSerializerFactory.java:401)
> at
> com.fasterxml.jackson.databind.ser.BeanSerializerFactory.findBeanSerializer(BeanSerializerFactory.java:271)
> at
> com.fasterxml.jackson.databind.ser.BeanSerializerFactory._createSerializer2(BeanSerializerFactory.java:223)
> at
> com.fasterxml.jackson.databind.ser.BeanSerializerFactory.createSerializer(BeanSerializerFactory.java:157)
> at
> com.fasterxml.jackson.databind.SerializerProvider._createUntypedSerializer(SerializerProvider.java:1215)
> at
> com.fasterxml.jackson.databind.SerializerProvider._createAndCacheUntypedSerializer(SerializerProvider.java:1167)
> ... 33 more Caused by: java.lang.ClassNotFoundException:
> com.fasterxml.jackson.module.afterburner.ser.BeanPropertyAccessor at
> java.lang.ClassLoader.findClass(ClassLoader.java:530) at
> java.lang.ClassLoader.loadClass(ClassLoader.java:424) at
> java.lang.ClassLoader.loadClass(ClassLoader.java:357) at
> java.lang.ClassLoader.defineClass1(Native Method) at
> java.lang.ClassLoader.defineClass(ClassLoader.java:763) at
> java.lang.ClassLoader.defineClass(ClassLoader.java:642) at
> com.fasterxml.jackson.module.afterburner.util.MyClassLoader.loadAndResolve(MyClassLoader.java:94)
> ... 42 more|
>
>
> On Sun, May 8, 2016 at 1:10 AM, Jean-Baptiste Onofré <jb@nanthrax.net
> <mailto:jb@nanthrax.net>> wrote:
>
>     Can you check with bundle:headers if it's correctly wired ?
>
>     Regards
>     JB
>
>     On 05/07/2016 07:14 PM, Debraj Manna wrote:
>
>         Below is the generated MANIFEST:-
>
>         Manifest-Version: 1.0
>         Bnd-LastModified: 1462615570323
>         Build-Jdk: 1.8.0_77
>         Built-By: debraj
>         Bundle-Activator: com.hello.world.HelloWorldActivator
>         Bundle-ManifestVersion: 2
>         Bundle-Name: Hello World
>         Bundle-SymbolicName: world
>         Bundle-Version: 0.0.1
>         Created-By: Apache Maven Bundle Plugin
>         Export-Package:
>         com.hello;version="0.0.1",com.hello.world;uses:="org.osg
>            i.framework";version="0.0.1"
>         Import-Package:
>         com.fasterxml.jackson.databind;resolution:=optional;vers
>
>         ion="[2.6,3)",com.fasterxml.jackson.module.afterburner;resolution:=opti
>
>         onal;version="[2.7,3)",org.osgi.framework;resolution:=optional;version=
>            "[1.6,2)"
>         Tool: Bnd-2.1.0.20130426-122213
>
>
>         I have installed afterburner  then only I installed my Hello
>         World bundle.
>
>
>
>
>         On Sat, May 7, 2016 at 10:40 PM, Jean-Baptiste Onofré
>         <jb@nanthrax.net <mailto:jb@nanthrax.net>
>         <mailto:jb@nanthrax.net <mailto:jb@nanthrax.net>>> wrote:
>
>              Hi,
>
>              1. Can you check that the generated MANIFEST contains the
>              afterburner import ?
>              2. If you install afterburner bundle after your bundle, you
>         have to
>              refresh your bundle as it's an optional import
>
>              Regards
>              JB
>
>
>              On 05/07/2016 05:27 PM, Debraj Manna wrote:
>
>                  Hi,
>
>                  I have a simple Hello World type Karaf Bundle. The
>         activator
>                  code looks
>                  like below:-
>
>                  |public class HelloWorldActivator implements
>         BundleActivator {
>                  @Override
>                  public void start(BundleContext bundleContext) throws
>         Exception {
>                  System.out.println("STARTING DEMO: hello, world\n");
>                  System.out.println(getJsonDataAsString()); } @Override
>         public void
>                  stop(BundleContext bundleContext) throws Exception {
>                  System.out.println("STOPPING DEMO"); } private String
>                  getJsonDataAsString() { JsonDataBlob jsonDataBlob = new
>                  JsonDataBlob();
>                  ObjectMapper objectMapper = new ObjectMapper();
>                  objectMapper.registerModule(new AfterburnerModule());
>         try { return
>                  objectMapper.writeValueAsString(jsonDataBlob); }
>         catch(Exception
>                  e) {
>                  e.printStackTrace(); } return ""; } } |
>
>                  |pom.xml| looks like below:-
>
>                  |<project xmlns="http://maven.apache.org/POM/4.0.0"
>                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>                  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
>         http://maven.apache.org/xsd/maven-4.0.0.xsd">
>                  <modelVersion>4.0.0</modelVersion>
>         <groupId>com.hello</groupId>
>                  <artifactId>world</artifactId> <version>0.0.1</version>
>                  <packaging>bundle</packaging> <name>Hello World</name>
>                  <dependencies>
>                  <!-- OSGi --> <dependency> <groupId>org.osgi</groupId>
>                  <artifactId>org.osgi.core</artifactId>
>         <version>4.3.1</version>
>                  </dependency> <dependency> <groupId>org.osgi</groupId>
>                  <artifactId>org.osgi.compendium</artifactId>
>                  <version>4.3.1</version>
>                  </dependency> <dependency> <groupId>org.json</groupId>
>                  <artifactId>json</artifactId> <version>20160212</version>
>                  </dependency>
>                  <dependency> <groupId>com.fasterxml.jackson.core</groupId>
>                  <artifactId>jackson-core</artifactId>
>         <version>2.6.2</version>
>                  </dependency> <dependency>
>                  <groupId>com.fasterxml.jackson.core</groupId>
>                  <artifactId>jackson-annotations</artifactId>
>                  <version>2.6.2</version>
>                  </dependency> <dependency>
>                  <groupId>com.fasterxml.jackson.core</groupId>
>                  <artifactId>jackson-databind</artifactId>
>         <version>2.6.2</version>
>                  </dependency> <dependency>
>                  <groupId>com.fasterxml.jackson.module</groupId>
>                  <artifactId>jackson-module-afterburner</artifactId>
>                  <version>2.7.1</version> </dependency> </dependencies>
>         <build>
>                  <sourceDirectory>src</sourceDirectory> <plugins> <plugin>
>                  <artifactId>maven-compiler-plugin</artifactId>
>                  <version>3.3</version>
>                  <configuration> <source>1.8</source>
>         <target>1.8</target> <excludes>
>                  <exclude>**/com/hello/main/*</exclude> </excludes>
>         </configuration>
>                  </plugin> <plugin> <groupId>org.apache.felix</groupId>
>                  <artifactId>maven-bundle-plugin</artifactId>
>                  <version>2.4.0</version>
>                  <inherited>true</inherited> <extensions>true</extensions>
>                  <configuration> <instructions>
>
>         <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
>                  <Bundle-Version>${project.version}</Bundle-Version>
>
>         <Bundle-Activator>com.hello.world.HelloWorldActivator</Bundle-Activator>
>                  <Import-Package>*;resolution:=optional</Import-Package>
>                  </instructions>
>                  </configuration> </plugin> </plugins> </build>
</project> |
>
>                  The java object which I am trying to convert to json is
>         a simple
>                  object
>                  as shown below:-
>
>                  |package com.hello.world; public class JsonDataBlob {
>         private
>                  String add1
>                  = "JP Naagar"; private String add2 = ""; private int
>                  shippartagent = 1;
>                  public String getAdd1() { return add1; } public void
>         setAdd1(String
>                  add1) { this.add1 = add1; } public String getAdd2() {
>         return add2; }
>                  public void setAdd2(String add2) { this.add2 = add2; }
>         public int
>                  getShippartagent() { return shippartagent; } public void
>                  setShippartagent(int shippartagent) { this.shippartagent =
>                  shippartagent; } } |
>
>                  Whenever I am trying to install the bundle I am getting
>         the below
>                  exception:-
>
>                  |2016-05-07 15:36:48,986 | WARN | x-6.1-2.0/deploy |
>         fileinstall
>                  | 7 -
>                  org.apache.felix.fileinstall - 3.5.0 | Error while
>         starting bundle:
>
>         file:/Users/debraj/Downloads/apache-servicemix-6.1-2.0/deploy/world-0.0.1.jar
>                  org.osgi.framework.BundleException: Activator start
>         error in bundle
>                  world [239]. at
>
>         org.apache.felix.framework.Felix.activateBundle(Felix.java:2196)[org.apache.felix.framework-4.2.1.jar:]
>                  at
>
>         org.apache.felix.framework.Felix.startBundle(Felix.java:2064)[org.apache.felix.framework-4.2.1.jar:]
>                  at
>
>         org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)[org.apache.felix.framework-4.2.1.jar:]
>                  at
>
>         org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1245)[7:org.apache.felix.fileinstall:3.5.0]
>                  at
>
>         org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1217)[7:org.apache.felix.fileinstall:3.5.0]
>                  at
>
>         org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:509)[7:org.apache.felix.fileinstall:3.5.0]
>                  at
>
>         org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:358)[7:org.apache.felix.fileinstall:3.5.0]
>                  at
>
>         org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:310)[7:org.apache.felix.fileinstall:3.5.0]
>                  Caused by: java.lang.NoClassDefFoundError:
>
>         com/fasterxml/jackson/module/afterburner/AfterburnerModule at
>                  java.lang.Class.getDeclaredConstructors0(Native
>                  Method)[:1.8.0_77] at
>
>         java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)[:1.8.0_77]
>                  at
>         java.lang.Class.getConstructor0(Class.java:3075)[:1.8.0_77] at
>                  java.lang.Class.newInstance(Class.java:412)[:1.8.0_77] at
>
>         org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4336)
>                  at
>
>         org.apache.felix.framework.Felix.activateBundle(Felix.java:2141) ...
>                  7 more Caused by: java.lang.ClassNotFoundException:
>
>         com.fasterxml.jackson.module.afterburner.AfterburnerModule not
>                  found by
>                  world [239] at
>
>         org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)[org.apache.felix.framework-4.2.1.jar:]
>                  at
>
>         org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)[org.apache.felix.framework-4.2.1.jar:]
>                  at
>
>         org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)
>                  at
>
>         java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_77] ...
>                  13 more |
>
>                  All the required Jackson bundles are installed in Karaf:-
>
>                  |karaf@root>bundle:list | grep Jackson 123 | Active |
>         50 | 2.6.2 |
>                  Jackson-core 125 | Active | 50 | 2.6.2 |
>         Jackson-annotations 238 |
>                  Installed | 80 | 2.7.1 | Jackson-module-Afterburner
>                  karaf@root>bundle:list | grep jackson 124 | Active | 50
>         | 2.6.2 |
>                  jackson-databind |
>
>                  Everything works fine if I just comment out the below
>         line:-
>
>                  |objectMapper.registerModule(new AfterburnerModule()); |
>
>                  I have placed the required code in github
>                  <https://github.com/debraj-manna/afterburner-issue>
>
>                  Has anyone able to execute the Jackson's Afterburner
>         module in
>                  Karaf 3.0.5?
>
>                  Thanks,
>
>                  Debraj
>
>
>              --
>              Jean-Baptiste Onofré
>         jbonofre@apache.org <mailto:jbonofre@apache.org>
>         <mailto:jbonofre@apache.org <mailto:jbonofre@apache.org>>
>         http://blog.nanthrax.net
>              Talend - http://www.talend.com
>
>
>
>     --
>     Jean-Baptiste Onofré
>     jbonofre@apache.org <mailto:jbonofre@apache.org>
>     http://blog.nanthrax.net
>     Talend - http://www.talend.com
>
>

-- 
Jean-Baptiste Onofré
jbonofre@apache.org
http://blog.nanthrax.net
Talend - http://www.talend.com

Mime
View raw message