4 Replies Latest reply on Jun 28, 2017 7:56 AM by John Gabriel

    OnException error type class not found in FUSE but works in Studio IDE

    Rob Mueller Newbie

      Setting up an OnException to recognize bad JSON messages.

      Windows 7 64bit, RedHat Fuse 6.1 , RH Studio w/jboss tools, blueprint frame, plain container w/no fabrics

      the good:

      <onException useOriginalMessage="true">

              <exception>net.sf.json.JSONException</exception>

              <handled>

                  <constant>true</constant>

              </handled>

              <pipeline>

                  <setHeader headerName="goingToJMSQ">

                      <simple>${header.JMSDestination}</simple>

                  </setHeader>

                  <log message="exception handled ${header.goingToJMSQ}" loggingLevel="ERROR"/>

                  <to uri="activemq:queue:dlqQ"/>

              </pipeline>

          </onException>

       

      The Bad (the error:)

      • Caused by: java.lang.ClassNotFoundException: net.sf.json.JSONException:

       

      The Ugly (the class is found in maven but not in the fuse/system/)

       

      Fuse uses org.apache.servicemix.bundles.json-lib and the class is found in it. But my little app Fuse can't find the class.

      In the IDE the class is resolved in the xmljson lib and it works fine.

       

      I ran the app in fuse w/o the OnException and indeed I get the net.sf.json.JSONException for the bad message.


      Steps used to deploy the bundle

      1) karaf> features:install camel-stream

      2) karaf> features:install camel-xmljson

      3) karaf> install -s mvn:com.mycompany/camel-json-unmarshal/1.0

      4) features:install camel-xstream


      Rob

        • 1. Re: OnException error type class not found in FUSE but works in Studio IDE
          Claus Ibsen Master

          You need to add OSGi import in your custom bundle, for this package net.sf.json so your application can load classes from this package, eg the exception.

           

          Usually you can do this in the pom.xml for the felix bundle plugin

          • 2. Re: OnException error type class not found in FUSE but works in Studio IDE
            Rob Mueller Newbie

            Thank you Claus. Hopefully you are referring to org.apache.felix

            here is the pom snippet where I added net.sf.json-lib.json.lib...

            <plugin>

                    <groupId>org.apache.felix</groupId>

                    <artifactId>maven-bundle-plugin</artifactId>

                    <version>2.3.7</version>

                    <extensions>true</extensions>

                    <configuration>

                      <instructions>

                        <Bundle-SymbolicName>camel-blueprint-unmarshal</Bundle-SymbolicName>

                        <Private-Package>com.mycompany.camel.blueprint.unmarshal.*</Private-Package>

                        <Import-Package>*,

                           net.sf.json-lib.json.lib</Import-Package>

                      </instructions>

                    </configuration>

                  </plugin>

               <plugin>

             

            I had the bundle plugin w '*'.

             

            Why would you have to add individual packages when the ' * '  refers to all?

             

            Rob

            • 3. Re: OnException error type class not found in FUSE but works in Studio IDE
              Claus Ibsen Master

              There is a dynamic import package you can give a try

               

              <DynamicImport-Package>*</DynamicImport-Package>

              • 4. Re: OnException error type class not found in FUSE but works in Studio IDE
                John Gabriel Newbie

                Could you please clarify below issue...

                 

                Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "net.sf.json.JSONSerializer.toJSON(Ljava/lang/Object;)Lnet/sf/json/JSON;" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the current class, org/apache/camel/dataformat/xmljson/XmlJsonDataFormat, and the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for the method's defining class, net/sf/json/JSONSerializer, have different Class objects for the type net/sf/json/JSON used in the signature

                 

                Server: Fuse 6.3

                 

                while deploying it loads the class...and no issues... if we restart the server or update the bundle  above issue is coming...