10 Replies Latest reply on Dec 1, 2015 6:14 AM by Raman kalra

    Injecting web service problem

    vic neiman Newbie

      Hi all,

       

      I've got an issue with injecting a web service into a bean, the web service is never intialised so when it's method are called I get NullPointerException. The code for injecting the web service looks like this:

       

      @Service(Base24.class)

      public class Base24Bean implements Base24 {

          @Inject @Reference

          private WsBICISOPortType wsBICISOPortType; // web service

       

           // ... methods that call web service

      }

       

      The web service name as specified in the wsdl is 'wsBICISO'.

       

      the portion of switchyard.xml that relates to this looks like this (ip and port for soap endpoint not shown here):

      <sca:component name="Base24Bean">

            <bean:implementation.bean class="za.co.fnb.ms.bean.Base24Bean"/>

            <sca:service name="Base24">

              <sca:interface.java interface="za.co.fnb.ms.b24.interfaces.Base24"/>

            </sca:service>

            <sca:reference name="wsBICISOPortType" >

              <sca:interface.wsdl interface="BICISOWSDL.wsdl#wsdl.porttype(wsBICISOPortType)"/>

            </sca:reference>

          </sca:component>

          <sca:reference name="Base24ServiceConsumer" promote="Base24Bean/wsBICISOPortType" multiplicity="0..1">

        <sca:interface.wsdl interface="BICISOWSDL.wsdl#wsdl.porttype(wsBICISOPortType)"/>

         <soap:binding.soap>

              <soap:contextMapper/>

              <soap:wsdl>BICISOWSDL.wsdl</soap:wsdl>

              <soap:endpointAddress>http://<ip>:<port></soap:endpointAddress>

            </soap:binding.soap>

          </sca:reference>

       

      I'm relatively new to Switchyard (been working with it for about a month) so any suggestions/pointers would be much appreciated.

       

      Regards

      Vic

        • 1. Re: Injecting web service problem
          Keith Babo Master

          The component service and reference interfaces for bean component must be Java interfaces.  I would expect to see an error in the log notifying you of this during deployment, so there may be a gap in the deployment validation logic in Bean component.  Did you create this app using the tooling?  That should only allow you to use Java interfaces.  Which version of SY are you using?

          • 2. Re: Injecting web service problem
            Gerhard Visagie Newbie

            Hi Keith;

             

            Me and Vic are working on the same team here.

             

            We had our service configured like this:

            REST binding --> SaleBean -->Base24Bean --> SOAP reference

            We were using the Base24Bean in SaleBean using @reference. However what we found was that the @inject @reference to the SOAP reference in the base24bean did not initialize  (we constantly got a nullpointer exception when we tried to  used it). We then wrote a small app separate form our main project to test that the soap webservice we were trying to call actually worked in switchyard (which it did).

             

            Over the weekend I had a brainwave. The main difference from our test app and the main app was that we had one bean using the soap reference in test app, but in the main app we accessed it through a reference. So we changed it so that we accessed the soap reference directly from the first bean...wouldn't you know it that worked!

             

            So it seems like switchyard is not initializing the references in the second bean, when the second bean has a soap webservice as reference. Its either that, or we are not configuring it right.

             

             

            • 3. Re: Injecting web service problem
              Gerhard Visagie Newbie

              Hi Keith;

               

              I realise my ramblings above might not have made any sense. I have a project that could help explain our problem. Its built on the order service example you posted a while back.

               

              See attached zip file

              • 4. Re: Re: Injecting web service problem
                synclpz Novice

                You got error in your OrderServiceProxyBean.java:

                 

                @Reference
                  private OrderServiceBean orderServiceBean;
                

                 

                should be

                 

                @Reference @Inject
                  private OrderService orderServiceBean;
                

                 

                Notice @Inject and OrderService instead of OrderServiceBean.

                 

                Try it, may be it helps.

                • 5. Re: Injecting web service problem
                  Keith Babo Master

                  Yep, @Inject is required.

                  • 6. Re: Injecting web service problem
                    Gerhard Visagie Newbie

                    Yep, that did the trick! Thanks guys (Crucially, we also had to use the interface as the reference, and not the bean itself)

                    • 7. Re: Injecting web service problem
                      Raman kalra Newbie

                      Hi All , I am facing a similar Issue . I am getting NPE while injecting reference to bean .Detail are on below thread

                      Could you please help me resolve it .

                       

                      https://developer.jboss.org/message/946689#946689

                       

                      Any help would be highly appreciated .

                       

                      Thanks

                      Raman

                      • 8. Re: Injecting web service problem
                        Tomohisa igarashi Master

                        Do you have beans.xml in META-INF? Starting from our rest-binding quickstart would help you - modify the bean impl in that quickstart as you like, then compare with your application.

                        • 9. Re: Injecting web service problem
                          Raman kalra Newbie

                          I have beans.xml in META-INF folder it is empty xml file . I compared it with the REST binding quick start and it was same.

                          Do you think is there something else which I am missing

                          • 10. Re: Injecting web service problem
                            Raman kalra Newbie

                            Also II have below warning messages when I deploy the project

                             

                            16:31:48,974 WARN  [org.jboss.weld.Validator] (weld-worker-2) WELD-001473: javax.enterprise.inject.spi.Bean implementation org.switchyard.component.bean.internal.message.MessageBean@51940b8d declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.

                            16:31:48,975 WARN  [org.jboss.weld.Validator] (weld-worker-2) WELD-001473: javax.enterprise.inject.spi.Bean implementation org.switchyard.component.bean.internal.exchange.ExchangeBean@15c43dd9 declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.

                            16:31:48,974 WARN  [org.jboss.weld.Validator] (weld-worker-1) WELD-001473: javax.enterprise.inject.spi.Bean implementation org.switchyard.component.bean.internal.context.ContextBean@77690521 declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.

                            16:31:49,355 WARN  [org.jboss.weld.Validator] (weld-worker-2) WELD-001473: javax.enterprise.inject.spi.Bean implementation org.switchyard.component.bean.ClientProxyBean@18d4c3db declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.

                            16:31:49,371 WARN  [org.jboss.weld.Validator] (weld-worker-1) WELD-001473: javax.enterprise.inject.spi.Bean implementation org.switchyard.component.bean.deploy.BeanDeploymentMetaDataCDIBean@28b4b11b declared a normal scope but does not implement javax.enterprise.inject.spi.PassivationCapable. It won't be possible to inject this bean into a bean with passivating scope (@SessionScoped, @ConversationScoped). This can be fixed by assigning the Bean implementation a unique id by implementing the PassivationCapable interface.