Expand my Community achievements bar.

SOLVED

How do I get my bundle to expose the implementation calss as a service. I am using @Component and @Service

Avatar

Level 6

If I place 

package StoreLocator.Shoprite.Onnet;

import java.util.ArrayList;

import Objects.Stores;

public interface StoreLocator {
    public ArrayList<Stores> getStores(Integer countryId); 
}


and then in my implementation class
@Component

@Service

 

public class StoreLocatorImpl implements StoreLocator {
    private ArrayList<Stores> storesArrayList = new ArrayList<Stores>();
    public ArrayList<Stores> getStores(Integer countryId)  {                 
            try {
                FetchStores fetchStores = new FetchStores(countryId);
                storesArrayList = fetchStores.getStoresArrayList();
            } catch (Exception e) {
                e.printStackTrace();
            }        
        return storesArrayList;        
    }        
}

I would expect to see  

 

     
Service ID 123456Types: StoreLocator.Shoprite.Onnet.StoreLocator

 

For example below

specialsandcoupons Bundlecom.shoprite.specialsandcoupons.specialsandcoupons-bundle
                                                 
Symbolic Namecom.shoprite.specialsandcoupons.specialsandcoupons-bundle
Version1.0.0.SNAPSHOT
Bundle Locationinputstream:specialsandcoupons-bundle-1.0-SNAPSHOT.jar
Last ModificationThu Oct 23 00:36:37 CAT 2014
DescriptionMaven Multimodule project for specialsandcoupons.
Start Level20
Exported PackagesObjects,version=1.0.0.SNAPSHOT
com.shoprite.specialsandcoupons,version=1.0.0
Imported Packagesjavax.net.ssl,version=0.0.0.1_007_JavaSE from org.apache.felix.framework (0)
javax.servlet,version=2.6.0 from org.apache.felix.http.servlet-api (29)
javax.servlet,version=3.0.0 from org.apache.felix.http.servlet-api (29)
javax.xml.parsers,version=0.0.0.fragment_xml from org.apache.felix.framework (0)
org.apache.sling.api,version=2.3.0 from org.apache.sling.api (184)
org.apache.sling.api.request,version=2.4.0 from org.apache.sling.api (184)
org.slf4j,version=1.7.6 from slf4j.api (14)
org.w3c.dom,version=0.0.0.fragment_xml from org.apache.felix.framework (0)
org.xml.sax,version=0.0.0.fragment_xml from org.apache.felix.framework (0)
Importing BundlesStoreLocator.Shoprite.Onnet.StoreLocator.Shoprite.Onnet-bundle (436)
Service ID 14934Types: com.shoprite.specialsandcoupons.ISpecialsAndCoupons
Service PID: com.shoprite.specialsandcoupons.impl.SpecialsAndCoupons
Component Name: com.shoprite.specialsandcoupons.impl.SpecialsAndCoupons
Component ID: 1840
Service ID 14935Types: javax.servlet.Filter
Service PID: com.shoprite.specialsandcoupons.impl.filters.LoggingFilter
Component Name: com.shoprite.specialsandcoupons.impl.filters.LoggingFilter
Component ID: 1841
Manifest HeadersBnd-LastModified: 1414017371564
Build-Jdk: 1.7.0_60
Built-By: clive
Bundle-Description: Maven Multimodule project for specialsandcoupons.
Bundle-ManifestVersion: 2
Bundle-Name: specialsandcoupons Bundle
Bundle-SymbolicName: com.shoprite.specialsandcoupons.specialsandcoupons-bundle
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: Objects; version="1.0.0.SNAPSHOT", com.shoprite.specialsandcoupons; uses:=Objects; version="1.0.0"
Import-Package: Objects; version="[1.0, 2)", com.shoprite.specialsandcoupons; version="[1.0, 2)", javax.net.ssl, javax.servlet, javax.xml.parsers, org.apache.sling.api; version="[2.1, 3)", org.apache.sling.api.request; version="[2.1, 3)", org.slf4j; version="[1.5, 2)", org.w3c.dom, org.xml.sax
Manifest-Version: 1.0
Service-Component: OSGI-INF/serviceComponents.xml
Tool: Bnd-1.50.0

 

But for StoreLocator.Shoprite.Onnet.StoreLocator.Shoprite.Onnet-bundle I only get

 

 

                                     
Symbolic NameStoreLocator.Shoprite.Onnet.StoreLocator.Shoprite.Onnet-bundle
Version1.0.0.SNAPSHOT
Bundle Locationinputstream:StoreLocator.Shoprite.Onnet-bundle-1.0-SNAPSHOT.jar
Last ModificationWed Oct 29 01:53:17 CAT 2014
DescriptionMaven Multimodule project for StoreLocator.Shoprite.Onnet.
Start Level20
Exported PackagesStoreLocator.Shoprite.Onnet,version=1.0.0
Imported PackagesObjects,version=1.0.0.SNAPSHOT from com.shoprite.specialsandcoupons.specialsandcoupons-bundle (403)
javax.json,version=1.0.0 from JSon.Javax (428)
javax.json.stream,version=1.0.0 from JSon.Javax (428)
javax.servlet,version=2.6.0 from org.apache.felix.http.servlet-api (29)
javax.servlet,version=3.0.0 from org.apache.felix.http.servlet-api (29)
org.apache.http,version=1.0.0 from osgi.httpclient.apache (431)
org.apache.http.client,version=4.3.0 from client.http (430)
org.apache.http.client.methods,version=4.3.0 from client.http (430)
org.apache.http.impl.client,version=4.3.0 from client.http (430)
org.apache.http.util,version=1.0.0 from osgi.httpclient.apache (431)
org.apache.log4j,version=1.2.17 from log4j.over.slf4j (3)
org.apache.sling.api,version=2.3.0 from org.apache.sling.api (184)
org.apache.sling.api.request,version=2.4.0 from org.apache.sling.api (184)
org.apache.sling.jcr.api,version=2.2.0 from org.apache.sling.jcr.api (104)
org.slf4j,version=1.7.6 from slf4j.api (14)
Manifest HeadersBnd-LastModified: 1414540345037
Build-Jdk: 1.7.0_60
Built-By: clive
Bundle-Description: Maven Multimodule project for StoreLocator.Shoprite.Onnet.
Bundle-ManifestVersion: 2
Bundle-Name: StoreLocator.Shoprite.Onnet Bundle
Bundle-SymbolicName: StoreLocator.Shoprite.Onnet.StoreLocator.Shoprite.Onnet-bundle
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: Objects; version="1.0.0.SNAPSHOT", StoreLocator.Shoprite.Onnet; uses:=Objects; version="1.0.0"
Import-Package: Objects, StoreLocator.Shoprite.Onnet; version="[1.0, 2)", javax.json; version="[1.0, 2)", javax.json.stream; version="[1.0, 2)", javax.servlet, org.apache.http, org.apache.http.client; version="[4.3, 5)", org.apache.http.client.methods; version="[4.3, 5)", org.apache.http.impl.client; version="[4.3, 5)", org.apache.http.util, org.apache.log4j, org.apache.sling.api; version="[2.1, 3)", org.apache.sling.api.request; version="[2.1, 3)", org.apache.sling.jcr.api; version="[2.1, 3)", org.slf4j; version="[1.5, 2)"
Manifest-Version: 1.0
Tool: Bnd-1.50.0
1 Accepted Solution

Avatar

Correct answer by
Level 10

From your other thread - looks like you are trying to build your bundle using CRXDE lite - use Maven as specified in the article -- not CRXDE Lite. If you follow every step - you will get it working. 

View solution in original post

4 Replies

Avatar

Employee

My guess - your Maven project is missing the configuration of the scr plugin, which takes those @Component and @Service annotations and generates the Declarative Services XML files from them.

Avatar

Level 10

Can you invoke your Service?

In this case - you should be able to invoke the service by :

StoreLocator.Shoprite.Onnet.StoreLocator storeLocator = sling.getService(StoreLocator.Shoprite.Onnet.StoreLocator.class);
storeLocator .getStores("code") ; 

For others reading this thread and wanting to know how to create an AEM Service - see:

Creating your first AEM Service using an Adobe Maven Archetype project

Avatar

Correct answer by
Level 10

From your other thread - looks like you are trying to build your bundle using CRXDE lite - use Maven as specified in the article -- not CRXDE Lite. If you follow every step - you will get it working. 

Avatar

Level 10

I tested this article against AEM 6 - it works fine. Here is the output in AEM 6 and Touch UI:

[img]Key6.png[/img]