Message Boards

Liferay 7.3 Spring MVC accessing service builder generated services issue

Aniket Pathare, modified 2 Years ago.

Liferay 7.3 Spring MVC accessing service builder generated services issue

New Member Posts: 4 Join Date: 2/3/21 Recent Posts

Hello,

I am facing following issue while accessing services (generated through service builder) from Spring MVC, I read through forums link and tried to use Service Tracker to access service in my Controller. I am using Liferay DXP 7.3.10.1 sp1 bundle.

Service tracker code snippet:

Bundle bundle = FrameworkUtil.getBundle(SearchKeywordHistoryLocalService.class);
    BundleContext bundleContext = bundle.getBundleContext();
    ServiceTracker<SearchKeywordHistoryLocalService, SearchKeywordHistoryLocalService> serviceTracker =
        new ServiceTracker<SearchKeywordHistoryLocalService, SearchKeywordHistoryLocalService>(bundleContext, SearchKeywordHistoryLocalService.class, null);    
    
 Code snippet where am getting exception(sysout statement):
try{
    serviceTracker.open();
    SearchKeywordHistoryLocalService _searchKeywordHistoryLocalService = serviceTracker.waitForService(500);
    if (searchKeyword != null && !searchKeyword.isEmpty()) {
        System.out.println("++++++++++++++++Test service => "+ _searchKeywordHistoryLocalService.getSearchKeywordHistoriesCount());
        savedSearch = _searchKeywordHistoryLocalService.addSearchKeywordHistory(...some arguments);
    }
    
} catch (Exception e) {
    logger.error("Exception occured while querying SOLR", e);
}

 

In logs I am getting below exception:

2021-08-09 10:18:54 ERROR AddSearchKeywordHistoryCommand:161 - Exception occured while querying SOLR
java.lang.NullPointerException
        at com.se.genericsearch.core.command.AddSearchKeywordHistoryCommand.doAction(AddSearchKeywordHistoryCommand.java:144)
        at com.se.genericsearch.core.command.AbstractCommand.execute(AbstractCommand.java:23)
        at com.se.genericsearch.core.command.DefaultCommandExecutor.executeCommand(DefaultCommandExecutor.java:39)
        at com.se.genericsearch.controller.SearchDispatcherPortlet.doResourceService(SearchDispatcherPortlet.java:64)
        at com.liferay.portletmvc4spring.FrameworkPortlet.processRequest(FrameworkPortlet.java:698)
        at com.liferay.portletmvc4spring.FrameworkPortlet.serveResource(FrameworkPortlet.java:260)
        at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:146)
        at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:88)
        at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:140)
        at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:78)
        ...

I tried creating new Spring MVC portlet and adding service builder in it. But there aslo I am getting some other exception as below:

2021-08-09 10:25:44.320 ERROR [http-nio-8080-exec-6][render_portlet_jsp:131] null
java.lang.ClassCastException: com.sun.proxy.$Proxy781 cannot be cast to test.service.FooLocalService
        at com.se.test.controller.UserController.showGreeting(UserController.java:66)
        at com.liferay.portletmvc4spring.mvc.method.annotation.PortletInvocableHandlerMethod.invokeAndHandle(PortletInvocableHandlerMethod.java:100)
        at com.liferay.portletmvc4spring.mvc.method.annotation.PortletRequestMappingHandlerAdapter.invokeHandlerMethod(PortletRequestMappingHandlerAdapter.java:1042)
        at com.liferay.portletmvc4spring.mvc.method.annotation.PortletRequestMappingHandlerAdapter.doHandle(PortletRequestMappingHandlerAdapter.java:586)
        at com.liferay.portletmvc4spring.mvc.method.annotation.PortletRequestMappingHandlerAdapter.doHandle(PortletRequestMappingHandlerAdapter.java:535)
        at com.liferay.portletmvc4spring.mvc.method.annotation.PortletRequestMappingHandlerAdapter.handleRenderInternal(PortletRequestMappingHandlerAdapter.java:621)
        at com.liferay.portletmvc4spring.mvc.method.AbstractPortletHandlerMethodAdapter.handleRender(AbstractPortletHandlerMethodAdapter.java:65)
        at com.liferay.portletmvc4spring.DispatcherPortlet.doRenderService(DispatcherPortlet.java:720)
        at com.liferay.portletmvc4spring.FrameworkPortlet.processRequest(FrameworkPortlet.java:695)
        at com.liferay.portletmvc4spring.FrameworkPortlet.doDispatch(FrameworkPortlet.java:484)
        at javax.portlet.GenericPortlet.render(GenericPortlet.java:291)
        at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:127)
        at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:58)
        at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:124)
        at com.liferay.portletmvc4spring.security.SpringSecurityPortletFilter.doFilter(SpringSecurityPortletFilter.java:186)
        at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:124)
        at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:71)
        at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:115)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
        at com.liferay.portal.osgi.web.wab.extender.internal.adapter.AsyncAttributeAdapterServlet.service(AsyncAttributeAdapterServlet.java:85)

Aniket Pathare, modified 2 Years ago.

RE: Liferay 7.3 Spring MVC accessing service builder generated services is

New Member Posts: 4 Join Date: 2/3/21 Recent Posts

Thid blog solved my problem. added below line in my portal-ext.

module.framework.web.generator.excluded.paths=<CURRENT EXCLUSIONS>,\
  WEB-INF/lib/com.liferay.school.api-1.0.0.jar