Message Boards

Null pointer exception while accessing service methods in Liferay 7.3

Sampada Karanjit, modified 3 Years ago.

Null pointer exception while accessing service methods in Liferay 7.3

New Member Post: 1 Join Date: 9/23/19 Recent Posts

Hi,

We are trying to migrate the existing portlets from Liferay 7.1 to Liferay 7.3(liferay/dxp:7.3.10-ga1 version).

After adding necessary Dependency Management related changes, building service and docker deploy, all portlets are shown in an Active State. However, we are not able to access any of the service methods inside our portlets. 

After conducting some research on this issue,  it seems that the default way of injecting services is now done by using Declarative Service approach.  Important Service Builder Changes points out that, we can still use old way of service injections, provided that we specify dependency-injector as "Spring" in the service.xml file. 

Steps we tried:

1) Modify existing Service.xml as following

<?xml version="1.0"?><!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 7.3.0//EN"
        "http://www.liferay.com/dtd/liferay-service-builder_7_3_0.dtd">

<service-builder package-path="sample.liferay" dependency-injector="spring">
    <entity local-service="true" name="Foo" remote-service="true" uuid="true"></entity>
</service>

2) Build Service

3) Access the service in our portlet as:


FooLocalServiceUtil.createFoo(1);
FooLocaServiceUtil.getFoosCount();

4) Docker Deploy

After the respective Bundle Started message is displayed, we tried to deploy the portlet in our web page and then we  always encounter "Portlet is temporarily not available".

Upon checking on logs, we see a Null Pointer Exception at getService() of FooLocalServiceUtil methods . 

We also tried to use @Reference annotation

@Reference
private FooLocalService fooLocalService;

fooLocalService.getFoosCount();

Result: Same exception

Further, we also tried by creating a sample module and generating service builder in Liferay 7.3. By default the service.xml contain the dependency injector as DS and necessary annotations in bnd.bnd file. After building the service, we tried to access one of the methods from the portlet using @Reference annotation.

@Reference
private FooNewLocalService fooNewLocalService;
    
fooNewLocalService.createFooNew(1);
      

However, we face the same null pointer exception while accessing service methods from the portlet.

Initially it seemed that the problem might be the dependency injection technique probably not being backward compatible. But now as, the new approach also results in the same exception, we think that probably the problem might reside somewhere else. It could be that we are missing a small but critical step here. 

Please let us know, if you have any ideas or hints regarding the issue.    

Thank you very much