1 Reply Latest reply on Dec 4, 2015 9:56 AM by tcunning

    Null pointer exception in CDI Bean inject Switchyard

    ramandeep

      Hi Guys,

       

      I am working on a SwitchYard project where I am trying to consume a Rest Service. Its running on Jboss EAP 6.3 though I have tried on Wildfly but error remains the same.

      The application gets deployed on the server successfully. But when I hit the URL, it gives a NullPointerException in the bean class where I am injecting a interface reference.

       

      For the past week I am struggling to find the solution for this NullPointerException, tried everything on Google but its not ready to move.

       

      I am pasting few of code snippets, which may help you get more understanding.

       

      Below is code snippet from my Bean class

      InvoiceGetBean .java

      @Service(InvoiceGet.class)
      
      public class InvoiceGetBean implements InvoiceGet {
        
          private static final Logger LOGGER = Logger.getLogger(InvoiceGetBean.class);
      
        
          @Inject
            @Reference("FXReference")
            private FXReference restService;
      
            public JSONObject getUserList(String searchInfo) throws Exception {
                LOGGER.info("value of restService : -------------------------------->" +restService);
      
      
      

       

      Here the value of restService is null for me . Below is the Interface reference which I am trying to inject .

       

      public interface FXReference {
        
          String getInvoice(InvoiceRequestDetails inv);
      
      
      

       

      My beans.xml is an empty file

       

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="
            http://java.sun.com/xml/ns/javaee 
            http://java.sun.com/xml/ns/javaee/beans_1_0.xsd" >
         
      </beans>
      
      
      
      
      

       

      below is the snippet from switchyard.xml

       

        <sca:component name="InvoiceGetBeanFX">
            <bean:implementation.bean class="com.example.switchyard.switchyard_example1.InvoiceGetBean"/>
            <sca:service name="InvoiceGet">
              <sca:interface.java interface="com.example.switchyard.switchyard_example1.InvoiceGet"/>
            </sca:service>
            <sca:reference name="FXReference">
              <sca:interface.java interface="com.example.switchyard.switchyard_example1.FXReference"/>
            </sca:reference>
          </sca:component>
          <sca:reference name="FXReference" multiplicity="0..1" promote="InvoiceGetBeanFX/FXReference">
            <sca:interface.java interface="com.example.switchyard.switchyard_example1.FXReference"/>
            <resteasy:binding.rest name="InvoiceGet">
            <sy:operationSelector operationName="getInvoice"/>
              <resteasy:messageComposer class="com.example.switchyard.switchyard_example1.CustomComposer"/>
              <resteasy:interfaces>com.example.switchyard.switchyard_example1.KC1UserInterface</resteasy:interfaces>
              <resteasy:address>http://${restHost}:${restPort}/${restPath}</resteasy:address>
            </resteasy:binding.rest>
          </sca:reference>
      
      
      

       

      The logger prints Null in console when I run the application as the reference has not been injected.

       

      Could you please help me in pointing the mistake ? I will attach my project if there is someone who wants to have look .