13 Replies Latest reply on Nov 10, 2011 9:03 AM by sandy2011

    Camel Deployment as OSGi bundle issue with ...unable to resolve org.springf

    sandy2011

      Hi, I am new to Fuse ESB.

      I have a Camel Route which works fine when run using mvn Camel:run.

      The Route takes consumes HL7 message , processes it and inserts the values to the database.

       

      I am trying to deploy it to OSGI (FUSE ESB 4.4) and the POM.XML is as below and have issues.

      I could build the bundle using mvn,  but when deployed in osgi I get the following exception 'unable to resolve org.springframework.jdbc.datasource'.

      I am not sure what is missing in the POM and I feel the OSGI could not locate the external packages.

      Can you please advice!

       

      pom.xml

      -


       

      -


      CamelContext

      -


       

       

      -


      JAVA DSL Route

      -


       

      package camelhl7;

       

      import org.apache.camel.Exchange;

      import org.apache.camel.Message;

      import org.apache.camel.Processor;

      import org.apache.camel.builder.RouteBuilder;

      import org.apache.camel.model.dataformat.HL7DataFormat;

      import org.apache.camel.model.dataformat.XStreamDataFormat;

      import org.apache.camel.spring.Main;

       

      import ca.uhn.hl7v2.model.v23.message.ADT_A01;

      import ca.uhn.hl7v2.model.v23.segment.MSH;

       

      /**

       

      • A Camel Router

      */

      public class MyRouteBuilder extends RouteBuilder {

       

          /**

            

      • A main() so we can easily run these routing rules in our IDE

           */

          public static void main(String... args) throws Exception {

              Main.main(args);

          }

       

          /**

            

      • Lets configure the Camel routing rules using Java code...

           */

          public void configure() {

       

              // TODO create Camel routes here.

       

              HL7DataFormat hl7 = new HL7DataFormat();

               hl7.setValidate(false);

               XStreamDataFormat xstream = new XStreamDataFormat();

           

          from("mina:tcp://xxx.xxx.xxx.xxx:61610?sync=true&codec=#hl7codec")

          .unmarshal(hl7)

          .choice()

                  .when(header("CamelHL7TriggerEvent").isEqualTo("A31"))

              .process(new Processor() {

                   public void process(Exchange exchange) throws Exception {

                   System.out.println("We just downloaded: "

                   + exchange.getIn().getHeader("CamelFileName"));             

                   Message msg = exchange.getIn();

                   ADT_A01 adta01=(ADT_A01)msg.getBody();

                   MSH msh = adta01.getMSH();

                   String Sending_Application = msh.getMsh3_SendingApplication().getNamespaceID().getValue();

                      

                  StringBuffer ColumnNames = new StringBuffer();

                  ColumnNames.append("'");

                  ColumnNames.append(Sending_Application);           

                   

                   String InsertStmt = "Insert into HL7_MSH_Ver23 values (" ColumnNames.toString()")";

                    

                   exchange.getIn().setBody(constant(InsertStmt));

                   }

              })   

                   .to("jdbc:testdb")

                   .setBody(constant("select top 10 * from HL7_MSH_Ver23"))

                   .to("jdbc:testdb")

                   .marshal(xstream)     

                   .to("file:target/dboutput?fileName=dbout-$.xml")

               .otherwise()

                    .marshal(hl7)

                    .to("file:target/messages/others")

                    .end()

                    .setBody(constant("MSA|AA|"))

                  .convertBodyTo(String.class)

                   .marshal();

                

           

               

       

          }

      }

      -


       

        • 1. Re: Camel Deployment as OSGi bundle issue with ...unable to resolve org.springf
          ffang

          Hi,

           

          You need install spring-jdbc bundle, just do

          osgi:install -s mvn:org.springframework/spring-jdbc/3.0.5.RELEASE

           

          Freeman

          • 2. jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
            sandy2011

            Thanks Freeman, It seems Spring framework issue is resolved but there is another exception related to sqljdbc4-4.0.jar

             

            The jdbc driver fails to load even though it is active in OSGI container.

             

            -


            sqljdbc4 (4.0)

            Spring JDBC (3.0.5.RELEASE)

            -


             

             

            karaf@root> Exception in thread "SpringOsgiExtenderThread-4" org.springframework.beans.factory.BeanCreationException: Error

            creating bean with name 'testdb' defined in URL bundle://132.0:0/META-INF/spring/camel-context.xml: Error setting proper

            ty values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1)

            are:

            PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'driverClassName' threw exception;

            nested exception is java.lang.IllegalStateException: Could not load JDBC driver class [com.microsoft.sqlserver.jdbc.SQLSer

            verDriver]

                    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowir

            eCapableBeanFactory.java:1361)

                    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapabl

            eBeanFactory.java:1086)

                    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapabl

            eBeanFactory.java:517)

                    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableB

            eanFactory.java:456)

                    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)

                    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry

            .java:222)

                    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)

                    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)

                    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBea

            nFactory.java:580)

                    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicati

            onContext.java:895)

                    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelega

            tedExecutionApplicationContext.java:69)

                    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExe

            cutionApplicationContext.java:355)

                    at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)

                    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDe

            legatedExecutionApplicationContext.java:320)

                    at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$Compl

            eteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:132)

                    at java.lang.Thread.run(Thread.java:662)

            Caused by: org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:

            • 3. Re: jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
              sandy2011

              FYI: I just placed the sqljdbc4-4.0.jar in the \deploy folder of servicemix.

              • 4. Re: jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
                ffang

                Hi,

                 

                This is actually a common issue when use JDBC driver in OSGi container,  in your case, it's because spring-jdbc bundle didn't import sqlserver drive package beforehand but try to use class.forname() method to init it, hence you see such this exception.

                Please see my explaination and the solution from

                 

                http://fusesource.com/forums/thread.jspa?messageID=9780&#9780

                 

                Freeman

                • 5. Re: jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
                  sandy2011

                  Do I need to create a fragment bundle for the SQLDriver and include it in the Bundle that defines Route

                   

                  or

                  I have to include the fragment bundle in spring-jdbc.

                  • 6. Re: jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
                    ffang

                    Hi,

                     

                    You need create fragment bundle for sqlserver driver and attach it to spring-jdbc, here spring-jdbc play the role as host bundle.

                     

                    Freeman

                    • 7. Re: jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
                      sandy2011

                      I have created a fragment bundle and deployed it to OSGi successfully.

                      Still i get the same error.

                       

                      -


                      A Camel Route (1.0.0.SNAPSHOT)

                      sqljdbc4 (4.0)

                      Spring JDBC (3.0.5.RELEASE)

                      xxx :: MSSQL Fragment :: SQL Driver (1.0.0)

                      karaf@root> osgi:start 132

                      Error executing command: Unresolved constraint in bundle com.ghg.camelhl7.app1.hl7_jdbc : Unable to resolve 132.8: mis

                      sing requirement package; (package=com.microsoft.sqlserver.jdbc.SQLServerDriver)

                      karaf@root>

                      -


                       

                       

                                               <Fragment-Host>org.springframework.spring-jdbc.3.0.5.RELEASE</Fragment-Host>

                      *                         <Import-Package>com.microsoft.sqlserver.jdbc</Import-Package>*

                                           

                      • 8. Re: jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
                        ffang

                        Hi,

                         

                        Look at

                        139 Installed 60 xxx :: MSSQL Fragment :: SQL Driver (1.0.0)

                         

                        The Installed status here indicate there's something wrong with this fragment bundle, it can't be picked up by it's host bundle, you can try to refresh spring-jdbc bundle to see if it helps.

                         

                        Like

                        osgi:refresh 134.

                         

                        FYI, the correct fragment/host bundle pair should be looks like

                        activemq-core (5.5.1.fuse-00-08)

                                                               Fragments: 62

                        activemq-blueprint (5.5.1.fuse-00-08)

                                                               Hosts: 48

                        The host bundle should be "Active", the fragment bundle should be "Resolved", and there should be connection to link each other.

                        From my first glance,  the Fragment-Host in pom.xml isn't correct, it should be Bundle-SymbolicName of the host, which should be org.springframework.jdbc.

                        You may need google to get more details how fragment bundle should be.

                         

                        OR another totally different solution is enable dynamic import for spring-jdbc bundle, like

                        dynamic-import 134

                        and then you just need wrap sqlserver jdbc driver as a normal bundle.

                        This can make all package is available for spring-jdbc. But I recommend the fragment

                        bundle way as it's good practice in OSGi world IMO.

                         

                        Freeman

                        • 9. Re: jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
                          sandy2011

                          Thanks Freeman, that seems to have resolved the fragment dependency

                          but still the Camel Route Bundle could not recognize the MS SQL Driver

                           

                           

                          -


                          A Camel Route (1.0.0.SNAPSHOT)

                          sqljdbc4 (4.0)

                          XXX:: MSSQL Fragment :: SQL Driver (1.0.0)

                                                                 Hosts: 140

                          Spring JDBC (3.0.5.RELEASE)

                                                                 Fragments: 139

                          karaf@root> osgi:start 132

                          Error executing command: Unresolved constraint in bundle com.ghg.camelhl7.app1.hl7_jdbc : Unable to resolve 132.8: mis

                          sing requirement package; (package=com.microsoft.sqlserver.jdbc.SQLServerDriver)

                          -


                          karaf@root> ERROR: Bundle com.ghg.camelhl7.app1.hl7_jdbc Error starting file:/D:/apache-servicemix-4.4.0-fuse-00-43/d

                          eploy/hl7_jdbc-1.0-SNAPSHOT.jar (org.osgi.framework.BundleException: Unresolved constraint in bundle com.ghg.camelhl7.app1.

                          hl7_jdbc : Unable to resolve 132.8: missing requirement package; (package=com.microsoft.sqlserver.jdbc.SQLServ

                          erDriver))

                          org.osgi.framework.BundleException: Unresolved constraint in bundle com.ghg.camelhl7.app1.hl7_jdbc : Unable to resolve

                          132.8: missing requirement package; (package=com.microsoft.sqlserver.jdbc.SQLServerDriver)

                                  at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3436)

                                  at org.apache.felix.framework.Felix.startBundle(Felix.java:1728)

                                  at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1157)

                          -


                          Manifest-Version: 1.0

                          Export-Package: camelhl7;uses:="org.apache.camel.builder,ca.uhn.hl7v2.

                          model.v23.datatype,ca.uhn.hl7v2.model.v23.segment,org.apache.camel,ca

                          .uhn.hl7v2.model.v23.message,org.apache.camel.model,org.apache.camel.

                          spring,org.apache.camel.model.dataformat"

                          Bundle-Version: 1.0.0.SNAPSHOT

                          Build-Jdk: 1.6.0_27

                          Built-By: srv_s

                          Tool: Bnd-0.0.357

                          Bnd-LastModified: 1320835748636

                          Bundle-Name: A Camel Route

                          Bundle-ManifestVersion: 2

                          Created-By: Apache Maven Bundle Plugin

                          Import-Package: ca.uhn.hl7v2.model.v23.datatype,ca.uhn.hl7v2.model.v23

                          .message,ca.uhn.hl7v2.model.v23.segment,com.microsoft.sqlserver.jdbc.

                          SQLServerDriver,org.apache.camel;version="2.7",org.apache.camel.build

                          er;version="2.7",org.apache.camel.component.hl7;version="2.7",org.apa

                          che.camel.model;version="2.7",org.apache.camel.model.dataformat;versi

                          on="2.7",org.apache.camel.spring;version="2.7",org.springframework.jd

                          bc.datasource;version="3.0"

                          Bundle-SymbolicName: com.ghg.camelhl7.app1.hl7_jdbc

                          • 10. Re: jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
                            sandy2011

                            Hi,

                            As a last resort, I tried placing the sqljdbc4-4.0.jar under \lib\ext of fuseesb and still the JDBC driver is not loaded!

                             

                            And ideas ... ?

                            • 11. Re: jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
                              ffang

                              Hi,

                               

                              Don't put it in \lib\ext folder, you should always install it as bundle.

                               

                              Freeman

                              • 12. Re: jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
                                ffang

                                Hi,

                                 

                                com.microsoft.sqlserver.jdbc.SQLServerDriver isn't a package, it's class, you should only import package, but not class.

                                 

                                So change to com.microsoft.sqlserver.jdbc in your pom.xml

                                 

                                Freeman

                                • 13. Re: jdbc driver fails to load! Camel Deployment as OSGi bundle issue with .
                                  sandy2011

                                  Thanks very much Freeman