0 Replies Latest reply on Nov 30, 2015 7:49 AM by Raman kalra

    Null Pointer exception for a reference while consuming Rest service in Bean - Switchyard Project

    Raman kalra Newbie

      Hi Guys ,

       

      I need some help I am facing  a Null pointer exception in the bean class where I am consuming a Rest Service . Below is my Bean class .

       

       

      import javax.inject.Inject;

       

      import org.switchyard.component.bean.Reference;

      import org.switchyard.component.bean.Service;

      import org.apache.log4j.Logger;

      import org.codehaus.jettison.json.JSONObject;

       

      @Service(InvoiceGet.class)

      public class InvoiceGetBean implements InvoiceGet {

       

      private static final Logger LOGGER = Logger.getLogger(InvoiceGetBean.class);

       

       

      @Inject

      @Reference

      private FXReference restService;

       

      public JSONObject InvoiceDetailGet(String searchInfo) throws Exception {

      LOGGER.info("Getting Invoice details: ");

                 String BillRefNo = HelperUtil.getXpathValue(searchInfo, "/InvoiceDetails/BillRefNo");

              String BillRefResets = HelperUtil.getXpathValue(searchInfo, "/InvoiceDetails/BillRefResets");

              String BillInvoiceRow = HelperUtil.getXpathValue(searchInfo, "/InvoiceDetails/BillInvoiceRow");

              String LanguageCode = HelperUtil.getXpathValue(searchInfo, "/InvoiceDetails/LanguageCode");

       

              LOGGER.info("BillRefNo is: "+BillRefNo +"BillRefResets is: "+BillRefResets + "BillInvoiceRow is:  "+BillInvoiceRow + "LanguageCode is:  "+LanguageCode);

       

                 String token = null;

                 JSONObject jsonObj = null;

       

                 token="Basic YXJib3JzdjprZW5hbmZ4";

       

                 InvoiceRequestDetails invoicedet = new InvoiceRequestDetails(BillRefNo, BillRefResets, BillInvoiceRow, LanguageCode,token);

                 String DetailInvoice = restService.InvoiceDetailGet(invoicedet);

       

       

       

      and here is the interface declaration :-

       

      While Consuming  Rest service the reference restService is NULL in below line.

       

        String DetailInvoice = restService.InvoiceDetailGet(invoicedet);

       

       

       

      please find my Switchyard.xml below

       

      <?xml version="1.0" encoding="UTF-8"?>
      <sy:switchyard xmlns:bean="urn:switchyard-component-bean:config:2.0" xmlns:camel="urn:switchyard-component-camel:config:2.0"        
          xmlns:resteasy="urn:switchyard-component-resteasy:config:2.0" xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" xmlns:sy="urn:switchyard-config:switchyard:2.0" name="switchyard-example1" targetNamespace="urn:com.example.switchyard:switchyard-example1:1.0">
        <sca:composite name="KC1_Rest" targetNamespace="urn:com.example.switchyard:switchyard-example1:1.0">
          <sca:component name="KC1Route">
            <camel:implementation.camel>
              <camel:java class="com.example.switchyard.KC1_Rest.CamelServiceRoute"/>
            </camel:implementation.camel>
      
            <sca:service name="InvoiceService">
              <sca:interface.java interface="com.example.switchyard.KC1_Rest.InvoiceService"/>
            </sca:service>
      
            <sca:reference name="InvoiceGet">
              <sca:interface.java interface="com.example.switchyard.KC1_Rest.InvoiceGet"/>
            </sca:reference>
          </sca:component>
      
          <sca:service name="InvoiceService" promote="KC1Route/InvoiceService">
            <sca:interface.java interface="com.example.switchyard.KC1_Rest.InvoiceService"/>
            <resteasy:binding.rest name="rest1">
              <sy:operationSelector operationName="getInvoiceDetails"/>
              <resteasy:messageComposer class="com.example.switchyard.gc1_Rest.CustomComposer"/>
              <resteasy:interfaces>com.example.switchyard.KC1_Rest.KC1UserInterface</resteasy:interfaces>
              <resteasy:contextPath>fx_rest</resteasy:contextPath>
            </resteasy:binding.rest>
          </sca:service>
      
          <sca:component name="InvoiceGetBean">
            <bean:implementation.bean class="com.example.switchyard.KC1_Rest.InvoiceGetBean"/>
            <sca:service name="InvoiceGet">
              <sca:interface.java interface="com.example.switchyard.KC1_Rest.InvoiceGet"/>
            </sca:service>
            <sca:reference name="FXReference">
              <sca:interface.java interface="com.example.switchyard.KC1_Rest.FXReference"/>
            </sca:reference>
          </sca:component>
      
          <sca:reference name="FXReference" multiplicity="0..1" promote="InvoiceGetBean/FXReference">
            <sca:interface.java interface="com.example.switchyard.KC1_Rest.FXReference"/>
            <resteasy:binding.rest name="rest2">
              <sy:operationSelector operationName="InvoiceDetailGet"/>
              <resteasy:messageComposer class="com.example.switchyard.KC1_Rest.CustomComposer"/>
              <resteasy:interfaces>com.example.switchyard.KC1_Rest.FXRestServiceResource</resteasy:interfaces>
              <resteasy:address>http://${restHost}:${restPort}/${restPath}</resteasy:address>
              <resteasy:contextParams>
                  <resteasy:contextParam name="resteasy.providers" value="com.KC1Integration.MyClientExecutionInterceptor"/>
                  <resteasy:contextParam name="resteasy.client.error.interceptors" value="com.Integration.MyClientErrorInterceptor"/>
              </resteasy:contextParams>
           </resteasy:binding.rest>
      
      ....
      
      
      

       

      Could someone please let me know what am I missing here ? Why the restService object is coming as NULL. ?

       

      Thanks

      Raman