9 Replies Latest reply on Jun 8, 2011 10:57 AM by rogelio_sevilla1

    Cannot instantiate my osgi  bundled Webservice  from another osgi bundle

    rogelio_sevilla1

      Hello everyone, i'm very sorry if this is a basic question :-S

       

      I Created a WService using the maven archtype  cxf osgi wsdl first  and I have already deployed it, my fuse esb admin gives me this info

       

      Endpoint address: http://localhost:8181/cxf/GreeterService

      WSDL : {mycompany.osgi_wsdl_first}SOAPService

      Target namespace: mycompany.osgi_wsdl_first

       

       

      After that, I created another osgi bundle to access that webservice, and I try to do this

       

      URL wsdlURL = new URL("http://localhost:8181/cxf/GreeterService?wsdl");

      SOAPService SERVICE_NAME new QName("mycompany.osgi_wsdl_first","SOAPService");

      SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);  //servicemix error

       

       

      However when i try to execute the last code line, I get a servicemix   error.  Servicemix logs this as a "Unable to start blueprint container for bla bla" error ,  because I'm executing this on the  init method of this small bean.  Am I missing something?? , why could be the cause of this??

       

      thanks a lot in advance for your time.

       

      Edited by: rogelio_sevilla1 on Jun 3, 2011 9:43 PM

       

      Edited by: rogelio_sevilla1 on Jun 7, 2011 3:23 PM

        • 1. Re: Cannot instantiate my osgi  bundled Webservice  from another osgi bundle
          rogelio_sevilla1

          just to add something, when I try the same code on a simple java application that is not intended to be an osgi bundle, it works great, but the same code intenteded to be on an osgi bundle fails.  Which leads me to another question:

           

          I have  2 osgi bundles,  one is a webservice and another is a simple pojo. Inside the pojo osgi bundle I try to access the webservice through a SOAP petition (that's when I get the error) . 

           

          however, when I try to run the same code that is on the osgi pojo  but from another java app outside the fuse esb, it works ok. 

           

          So my question is:

           

          Is trying to access an osgi bundled webservice  through a soap petition from another osgi bundle a mistake??? 

           

          Thanks a lot in advance :-D

          • 2. Re: Cannot instantiate my osgi  bundled Webservice  from another osgi bundle
            rogelio_sevilla1

            I think I've found the error (how foolish of me) ,  the problem is that I haven't registered my webservice on the servicemix service registry,  however, when I try to do that I get an error   .  My beans.xml of the webservice bundle has this code:

             

             

             

             

             

             

            The error I got on FUSE ESB is this

             

             

            Exception in thread "SpringOsgiExtenderThread-50" java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext

             

             

             

            Any advice would be appreciated :-D

             

             

             

            Thanks in advance

             

            Edited by: rogelio_sevilla1 on Jun 3, 2011 11:17 PM

            • 3. Re: Cannot instantiate my osgi  bundled Webservice  from another osgi bundle
              rogelio_sevilla1

              I have modified the jaxws:endpoint to this:

               

                tag because I just realized it is inccorrect,  however, when I try to access my webservice from another osgi bundle on fuse esb, the client bundle stays on "GracePeriod" for 5 minutes (more than enough, it is a small app) , and after that it changes to "Failure"   :-(. What am I missing??

               

              Edited by: rogelio_sevilla1 on Jun 3, 2011 11:54 PM

              • 4. Re: Cannot instantiate my osgi  bundled Webservice  from another osgi bundle
                ffang

                Hi,

                 

                I don't think you need register server side webservice as an OSGi service, you just publish it through http-osgi transport, that's ok, you should be able to access this webservice from any other bundle through http.

                 

                You need focus on the client side bundle, a couple of issues you need check

                 

                1. Does it import all necessay package?

                2. I saw in your client bundle you have code like

                URL wsdlURL = new URL("http://localhost:8181/cxf/GreeterService?wsdl");

                This means your client bundle need server bundle started first and publish webservice, this is not reliable in OSGi container, as you just depend on bundle start sequence which isn't a good practice in OSGi world, you may need keep a lock copy wsdl for client bundle.

                3. the error for client bundle have something about "Unable to start blueprint container", do you ever use blueprint configuration for client side?

                 

                 

                Freeman

                • 5. Re: Cannot instantiate my osgi  bundled Webservice  from another osgi bundle
                  rogelio_sevilla1

                  Thanks a lot for answering mr. Freeman, ok:

                   

                  1.- Yep i'm pretty sure I have added all the dependencies, as I said before, the same code works well outside the fuse esb enviroment :-S , the only difference is that the client app that works, is not an osgi container.

                   

                  2.- Thanks a lot for the advice mr. Freeman, I really appreciate that. By "lock copy wsdl" do you mean deploying the server wsdl also into the client?? .  By the way, this is the whole code for my client (it's just a test class, that's all):

                   

                   

                  package mycompany.cliente_wsdl_first;

                   

                   

                  import java.io.File;

                  import java.net.MalformedURLException;

                  import java.net.URL;

                  import java.util.logging.Level;

                  import java.util.logging.Logger;

                  import javax.xml.namespace.QName;

                  import javax.jws.Oneway;

                  import javax.jws.WebMethod;

                  import javax.jws.WebParam;

                  import javax.jws.WebResult;

                  import javax.jws.WebService;

                  import javax.xml.bind.annotation.XmlSeeAlso;

                  import javax.xml.ws.RequestWrapper;

                  import javax.xml.ws.ResponseWrapper;

                  import mycompany.cliente_wsdl_first.types.*;

                  //importing the service SEI , the service jar is in maven and I added the dependency

                  //in the pom file of the client

                  import mycompany.osgi_wsdl_first.Greeter;

                   

                   

                  public class MiPrueba {

                       

                       

                      public void init(){

                      System.out.println("empezo el cliente");

                      QName SERVICE_NAME = new  QName("mycompany.osgi_wsdl_first","SOAPService");

                      System.out.println("1");

                      URL wsdlURL = SOAPService.WSDL_LOCATION;

                      System.out.println("2");

                      System.out.println(wsdlURL.toString());

                      System.out.println(SERVICE_NAME.toString());

                      SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);  //here's the error!!

                      System.out.println("3");

                      Greeter port = ss.getSoapPort();

                      System.out.println("4");

                      String sayHi = port.sayHi("Seeee");

                      System.out.println("5");

                      System.out.println(sayHi);

                      }

                       

                  }

                   

                   

                  When I install or update this osgi on fuse esb,  the next messages get printed:

                   

                  empezo el cliente

                  1

                  2

                  http://localhost:8181/cxf/GreeterService?wsdl

                  {com.flytecomm.osgi_wsdl_first}SOAPService

                   

                   

                  which leads me to believe that the error is on this line

                   

                  SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);

                   

                   

                  SOAPService is one of the classes generated by the wsdl2java tool,  the code (it's very small don't worry) of this class is attached to this answer

                   

                   

                   

                  3.- Yeas i'm using the blueprint configuration too (sorry for ignoring his existence :-P) ,

                    it's very small, this is the code:

                   

                   

                   

                   

                   

                   

                  Any advice?? ,  thanks a lot in advance.

                   

                  P.S.  just in case you're wondering... yes, I have already endorsed the jaxws-api.jar and the jaxb-api.jar to run apps for JAX-WS 2.1

                   

                  Edited by: rogelio_sevilla1 on Jun 4, 2011 5:16 PM

                  • 6. Re: Cannot instantiate my osgi  bundled Webservice  from another osgi bundle
                    rogelio_sevilla1

                    just to add some more info :-S , this is the error i'm getting on the fuse esb log:

                     

                     

                     

                    ERROR | rint Extender: 2 | BlueprintContainerImpl           | ?                                   ? | 7 - org.apache.aries.blueprint - 0.2.0.incubating | Unable to start blueprint container for bundle cliente_wsdl_first

                    org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to intialize bean client

                         at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:635)[7:org.apache.aries.blueprint:0.2.0.incubating]

                         at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:744)[7:org.apache.aries.blueprint:0.2.0.incubating]

                         at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:64)[7:org.apache.aries.blueprint:0.2.0.incubating]

                         at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:219)[7:org.apache.aries.blueprint:0.2.0.incubating]

                         at org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:147)[7:org.apache.aries.blueprint:0.2.0.incubating]

                         at org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:624)[7:org.apache.aries.blueprint:0.2.0.incubating]

                         at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:315)[7:org.apache.aries.blueprint:0.2.0.incubating]

                         at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:213)[7:org.apache.aries.blueprint:0.2.0.incubating]

                         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)[:1.6.0_25]

                         at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)[:1.6.0_25]

                         at java.util.concurrent.FutureTask.run(FutureTask.java:138)[:1.6.0_25]

                         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:98)[:1.6.0_25]

                         at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:206)[:1.6.0_25]

                         at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)[:1.6.0_25]

                         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)[:1.6.0_25]

                         at java.lang.Thread.run(Thread.java:662)[:1.6.0_25]

                    Caused by: javax.xml.ws.spi.FactoryFinder$ConfigurationError: Provider org.apache.cxf.jaxws.spi.ProviderImpl not found

                         at javax.xml.ws.spi.FactoryFinder$2.run(FactoryFinder.java:130)[:1.0]

                         at javax.xml.ws.spi.FactoryFinder.doPrivileged(FactoryFinder.java:220)[:1.0]

                         at javax.xml.ws.spi.FactoryFinder.newInstance(FactoryFinder.java:124)[:1.0]

                         at javax.xml.ws.spi.FactoryFinder.access$200(FactoryFinder.java:44)[:1.0]

                         at javax.xml.ws.spi.FactoryFinder$3.run(FactoryFinder.java:211)[:1.0]

                         at javax.xml.ws.spi.FactoryFinder.doPrivileged(FactoryFinder.java:220)[:1.0]

                         at javax.xml.ws.spi.FactoryFinder.find(FactoryFinder.java:160)[:1.0]

                         at javax.xml.ws.spi.Provider.provider(Provider.java:43)[:1.0]

                         at javax.xml.ws.Service.(Service.java:35)[:1.0]

                    • 7. Re: Cannot instantiate my osgi  bundled Webservice  from another osgi bundle
                      njiang

                      Are you using ServiceMix or Fuse ESB ?

                      Or you just use Apache Karaf to load the bundles that you need?

                      Did you install the jaxws API bundle which was wrapped by ServiceMix?

                       

                      If not , please use it.

                       

                      Willem

                      • 8. Re: Cannot instantiate my osgi  bundled Webservice  from another osgi bundle
                        ffang

                        Hi,

                         

                        1.When I ask "Do you import all necessary package?" I mean the package import or OSGi metadata header, not the java code used package import, so your standalone client run successfully doesn't mean it can run successfully in OSGi container.

                        Could you use osgi:headers your_client_bundle_id and post the result here?

                         

                        2. yes, client side should also keep a wsdl copy, so it doesn't really on the server bundle start or not.

                         

                        3. this exception

                        Caused by: javax.xml.ws.spi.FactoryFinder$ConfigurationError: Provider org.apache.cxf.jaxws.spi.ProviderImpl not found

                        is very important, you shouldn't endorse jaxws api yourself, you should use jaxws api wrapper bundle from Servicemix as Willem already suggest you.

                         

                        Freeman

                        • 9. Re: Cannot instantiate my osgi  bundled Webservice  from another osgi bundle
                          rogelio_sevilla1

                          Thanks a LOT mr. Willem and mr. Freeman

                           

                          Your answers helped me find the right answer, my code was correct. As both of you suggested  the jaxws API was the wrong one. However, something strange happened.  The moment I switched to fuse esb apis, my internal bundles were able to communicate between each other, BUT,  my external app that I used to make the request to the wservice bundle started to throw the same exception the the internal bundle was throwing :-S .

                           

                          After that, I endorsed again the sun jaxws-api.jar and jaxb-api.jar  that are on this page

                          http://jax-ws.java.net/   (I downloaded the 2.2.3   version and i took both jaxws-api.jar and jaxb-api.jar from the lib folder.  ).  After that, everything seems to work pretty well. So, the problem is solved but a question remains... is there a bug on the fuse esb apis?? , is there something else i should have done to make the fuse esb apis work??

                           

                          Anyway, for now it works fine. thanks again mr. Willem and mr. Freeman