RE: Service-builder mod stop working when adding @ServiceReference to Custo

thumbnail
Fernando Fernandez, modified 7 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts

Hi all,

 

I'm trying to add custom SQL to a service-builder module managing a sample customer entity. The service is working  well without custom-sql and I'm following this tutorial plus some other sources.  The problem is that, as soon as I add this lines of code to CustomerFinderImpl.java...

@ServiceReference(type=CustomSQL.class)<br> private CustomSQL _customSQL;

... the service stops working (meaning it's no longer available to a portlet using it and is no longer available on the JSONWS API page). 

 

It's strange because both modules  (-api and -service) are shown as starting on the server log (I have to force "refresh of the -api bundle on gogo shell) and are also listed as Active on the gogo shell console.

554|Active &nbsp; &nbsp; | &nbsp; &nbsp;1|Example13service-api (1.0.0)<br> 555|Active &nbsp; &nbsp; | &nbsp; &nbsp;1|Example13service-service (1.0.0)<br> 559|Active &nbsp; &nbsp; | &nbsp; &nbsp;1|Example13 (1.0.0)

 

 

Even the portlet using the service starts, but if I do a scr:info on it's class it will show an unsatisfied reference:

*** Bundle: com.test.example13 (559)<br> Component Description:<br> &nbsp; Name: com.test.example13.portlet.Example13Portlet<br> &nbsp; Implementation Class: com.test.example13.portlet.Example13Portlet<br> &nbsp; Default State: enabled<br> &nbsp; Activation: immediate<br> &nbsp; Configuration Policy: optional<br> &nbsp; Activate Method: insertDummyData<br> &nbsp; Deactivate Method: deactivate<br> &nbsp; Modified Method: -<br> &nbsp; Configuration Pid: [com.test.example13.portlet.Example13Portlet]<br> &nbsp; Services:&nbsp;<br> &nbsp; &nbsp; javax.portlet.Portlet<br> &nbsp; Service Scope: singleton<br> &nbsp; Reference: customerService<br> &nbsp; &nbsp; Interface Name: com.test.example13.sb.service.CustomerService<br> &nbsp; &nbsp; Cardinality: 1..1<br> &nbsp; &nbsp; Policy: static<br> &nbsp; &nbsp; Policy option: reluctant<br> &nbsp; &nbsp; Reference Scope: bundle<br> &nbsp; Component Description Properties:<br> &nbsp; &nbsp; &nbsp; com.liferay.portlet.display-category = category.sample<br> &nbsp; &nbsp; &nbsp; com.liferay.portlet.instanceable = true<br> &nbsp; &nbsp; &nbsp; javax.portlet.init-param.template-path = /<br> &nbsp; &nbsp; &nbsp; javax.portlet.init-param.view-template = /view.jsp<br> &nbsp; &nbsp; &nbsp; javax.portlet.name = example13<br> &nbsp; &nbsp; &nbsp; javax.portlet.resource-bundle = content.Language<br> &nbsp; &nbsp; &nbsp; javax.portlet.security-role-ref = power-user,user<br> &nbsp; Component Configuration:<br> &nbsp; &nbsp; ComponentId: 2571<br> &nbsp; &nbsp; State: unsatisfied reference<br> &nbsp; &nbsp; UnsatisfiedReference: customerService<br> &nbsp; &nbsp; &nbsp; Target: null<br> &nbsp; &nbsp; &nbsp; (no target services)<br> &nbsp; &nbsp; Component Configuration Properties:<br> &nbsp; &nbsp; &nbsp; &nbsp; com.liferay.portlet.display-category = category.sample<br> &nbsp; &nbsp; &nbsp; &nbsp; com.liferay.portlet.instanceable = true<br> &nbsp; &nbsp; &nbsp; &nbsp; component.id = 2571<br> &nbsp; &nbsp; &nbsp; &nbsp; component.name = com.test.example13.portlet.Example13Portlet<br> &nbsp; &nbsp; &nbsp; &nbsp; javax.portlet.init-param.template-path = /<br> &nbsp; &nbsp; &nbsp; &nbsp; javax.portlet.init-param.view-template = /view.jsp<br> &nbsp; &nbsp; &nbsp; &nbsp; javax.portlet.name = example13<br> &nbsp; &nbsp; &nbsp; &nbsp; javax.portlet.resource-bundle = content.Language<br> &nbsp; &nbsp; &nbsp; &nbsp; javax.portlet.security-role-ref = power-user,user

 

Previuosly it didn't compile, but adding "compile "com.liferay:com.liferay.portal.dao.orm.custom.sql:1.0.3" to build.gradle solved the building problem. 

 

I'm doing this with Liferay 7.0 CE GA7 and IDE 3.4 (with blade and Liferay Workspace up-to-date).

 

Any ideas?

 

TIA

 

Fernando

thumbnail
David H Nebinger, modified 7 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
If that service is claiming an unsatisfied reference on CustomerService, then you have to check the scr:info on that instance...
thumbnail
Fernando Fernandez, modified 7 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts

Hi David,

 

Sorry, I'm not sure I'm following... I tried three ways:

g! scr:info com.test.example13.sb.service.CustomerService<br> No Component with name or configuration with ID matching com.test.example13.sb.service.CustomerService<br> g! scr:info com.test.example13.sb.service &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br> No Component with name or configuration with ID matching com.test.example13.sb.service<br> g! scr:info Example13service-service<br> No Component with name or configuration with ID matching Example13service-service

 

Still, I have both modules of the service  as STARTED...

g! lb 13service<br> START LEVEL 20<br> &nbsp; &nbsp;ID|State &nbsp; &nbsp; &nbsp;|Level|Name<br> &nbsp; 554|Active &nbsp; &nbsp; | &nbsp; &nbsp;1|Example13service-api (1.0.0)<br> &nbsp; 555|Active &nbsp; &nbsp; | &nbsp; &nbsp;1|Example13service-service (1.0.0)

 

... and the *-service module is declaring:

 

g! headers 555

Example13service-service (555)<br> ------------------------------<br> Manifest-Version = 1.0<br> Bnd-LastModified = 1541758479786<br> Bundle-ManifestVersion = 2<br> Bundle-Name = Example13service-service<br> Bundle-SymbolicName = com.test.example13.sb.service<br> Bundle-Version = 1.0.0<br> Created-By = 1.8.0_191 (Oracle Corporation)<br> Export-Package = com.test.example13.sb.exception;version="1.0.0";uses:="com.liferay.portal.kernel.exception",com.test.example13.sb.model;version="1.0.0";uses:="com.liferay.expando.kernel.model,com.liferay.exportimport.kernel.lar,com.liferay.portal.kernel.annotation,com.liferay.portal.kernel.bean,com.liferay.portal.kernel.model,com.liferay.portal.kernel.service,com.liferay.portal.kernel.util",com.test.example13.sb.model.impl;uses:="com.liferay.expando.kernel.model,com.liferay.exportimport.kernel.lar,com.liferay.portal.kernel.json,com.liferay.portal.kernel.model,com.liferay.portal.kernel.model.impl,com.liferay.portal.kernel.service,com.test.example13.sb.model";version="1.0.0",com.test.example13.sb.service;version="1.0.0";uses:="com.liferay.exportimport.kernel.lar,com.liferay.portal.kernel.dao.orm,com.liferay.portal.kernel.exception,com.liferay.portal.kernel.jsonwebservice,com.liferay.portal.kernel.model,com.liferay.portal.kernel.search,com.liferay.portal.kernel.security.access.control,com.liferay.portal.kernel.service,com.liferay.portal.kernel.spring.osgi,com.liferay.portal.kernel.transaction,com.liferay.portal.kernel.util,com.test.example13.sb.model",com.test.example13.sb.service.base;uses:="com.liferay.counter.kernel.service,com.liferay.exportimport.kernel.lar,com.liferay.portal.kernel.bean,com.liferay.portal.kernel.dao.orm,com.liferay.portal.kernel.exception,com.liferay.portal.kernel.model,com.liferay.portal.kernel.module.framework.service,com.liferay.portal.kernel.search,com.liferay.portal.kernel.service,com.liferay.portal.kernel.service.persistence,com.liferay.portal.kernel.transaction,com.liferay.portal.kernel.util,com.liferay.portal.spring.extender.service,com.test.example13.sb.model,com.test.example13.sb.service,com.test.example13.sb.service.persistence";version="1.0.0",com.test.example13.sb.service.http;uses:="com.liferay.portal.kernel.exception,com.liferay.portal.kernel.security.auth,com.test.example13.sb.model";version="1.0.0",com.test.example13.sb.service.impl;uses:="com.liferay.portal.kernel.exception,com.test.example13.sb.model,com.test.example13.sb.service.base";version="1.0.0",com.test.example13.sb.service.persistence;version="1.0.0";uses:="com.liferay.portal.kernel.dao.orm,com.liferay.portal.kernel.service,com.liferay.portal.kernel.service.persistence,com.liferay.portal.kernel.util,com.test.example13.sb.exception,com.test.example13.sb.model",com.test.example13.sb.service.persistence.impl;uses:="com.liferay.portal.kernel.bean,com.liferay.portal.kernel.dao.orm,com.liferay.portal.kernel.exception,com.liferay.portal.kernel.model,com.liferay.portal.kernel.service.persistence,com.liferay.portal.kernel.service.persistence.impl,com.liferay.portal.kernel.util,com.liferay.portal.spring.extender.service,com.test.example13.sb.exception,com.test.example13.sb.model,com.test.example13.sb.model.impl,com.test.example13.sb.service.persistence";version="1.0.0",com.test.example13.sb.service.util;uses:="com.liferay.portal.kernel.configuration";version="1.0.0"<br> Import-Package = com.liferay.counter.kernel.service;version="[1.0,2)",com.liferay.expando.kernel.model;version="[1.0,2)",com.liferay.expando.kernel.util;version="[1.0,2)",com.liferay.exportimport.kernel.lar;version="[1.1,2)",com.liferay.portal.dao.orm.custom.sql;version="[1.0,2)",com.liferay.portal.kernel.annotation;version="[6.3,7)",com.liferay.portal.kernel.bean;version="[7.0,8)",com.liferay.portal.kernel.configuration;version="[6.2,7)",com.liferay.portal.kernel.dao.db;version="[7.1,8)",com.liferay.portal.kernel.dao.jdbc;version="[7.1,8)",com.liferay.portal.kernel.dao.orm;version="[7.0,8)",com.liferay.portal.kernel.exception;version="[7.0,8)",com.liferay.portal.kernel.json;version="[7.0,8)",com.liferay.portal.kernel.jsonwebservice;version="[7.0,8)",com.liferay.portal.kernel.log;version="[7.0,8)",com.liferay.portal.kernel.model;version="[1.0,1.1)",com.liferay.portal.kernel.model.impl;version="[1.0,2)",com.liferay.portal.kernel.module.framework.service;version="[1.0,2)",com.liferay.portal.kernel.search;version="[7.2,8)",com.liferay.portal.kernel.security.access.control;version="[1.0,2)",com.liferay.portal.kernel.security.auth;version="[1.0,2)",com.liferay.portal.kernel.service;version="[1.3,2)",com.liferay.portal.kernel.service.http;version="[1.0,2)",com.liferay.portal.kernel.service.persistence;version="[1.1,2)",com.liferay.portal.kernel.service.persistence.impl;version="[1.2,2)",com.liferay.portal.kernel.spring.osgi;version="[1.0,2)",com.liferay.portal.kernel.transaction;version="[7.0,8)",com.liferay.portal.kernel.util;version="[7.3,8)",com.liferay.portal.kernel.uuid;version="[6.2,7)",com.liferay.portal.spring.extender.service;version="[1.0,2)",com.test.example13.sb.exception;version="[1.0,2)",com.test.example13.sb.model;version="[1.0,1.1)",com.test.example13.sb.model.impl,com.test.example13.sb.service;version="[1.0,1.1)",com.test.example13.sb.service.base,com.test.example13.sb.service.persistence;version="[1.0,1.1)",com.test.example13.sb.service.util,javax.sql,org.osgi.framework,org.osgi.util.tracker<br> Javac-Debug = on<br> Javac-Deprecation = off<br> Javac-Encoding = Cp1252<br> Liferay-Require-SchemaVersion = 1.0.0<br> Liferay-Service = true<br> Liferay-Spring-Context = META-INF/spring<br> Provide-Capability = osgi.service;objectClass:List&lt;String&gt;="com.test.example13.sb.service.CustomerLocalService",osgi.service;objectClass:List&lt;String&gt;="com.test.example13.sb.service.CustomerService"<br> Require-Capability = liferay.extender;filter:="(&amp;(liferay.extender=spring.extender)(version&gt;=2.0)(!(version&gt;=3.0)))",osgi.ee;filter:="(&amp;(osgi.ee=JavaSE)(version=1.8))"<br> Tool = Bnd-3.5.0.201709291849

 

Any ideas?

 

TIA

 

Fernando

thumbnail
David H Nebinger, modified 7 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts

So from your lb output command above, normally I get the list of components like:

 

scr:list 555

 

That gives the list of components in a bundle and should show general state for them.  Each one will be listed with a component id, so I use that with the scr:info command argument to get the details on each component.

 

I've never been successful w/ the search by name option; I'm sure there's a trick for it, but since I have a working path I haven't looked into it further.

thumbnail
Fernando Fernandez, modified 7 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts

Hi David,

 

In this situation, the scr:list 555 comes up empty.  Also, the ds:unsatisfied command only lists the portlet as missing one dependency: the service itself.

 

I found out that I just need to comment  the @ServiceReference(type=CustomSQL.class) line and use CustomSQLUtil instead of the @referenced variable so that it starts working.

 

I'd really like to understand what's happening but now that it's working I think I'll move forward.

 

Thanks

 

Fernando

thumbnail
David H Nebinger, modified 7 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
Well, CustomSQLUtil will be using a ServiceTracker to get the instance to the CustomSQL class.  So maybe it is not a @ServiceReference you need, and just a regular @Reference...
thumbnail
Fernando Fernandez, modified 7 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts

Hi David,

 

I used ServiceReference since it's mentioned on this tutorial.  

 

Just tried @Reference (all 3 of them) and none worked (2 were disallowed on that location). 

 

Unless you tell me that using CustomSQLUtil has a very bad side effect, I'll stick to it, since it's working. :-)

 

Thanks

 

Fernando