Expand my Community achievements bar.

SOLVED

Imported Services give StoreLocator.Shoprite.Onnet.HelloService

Avatar

Level 6

My bundle is active 

                                                         
Symbolic NameStoreLocator.Shoprite.Onnet.IStoreLocator.Shoprite.Onnet-bundle
Version1.0.0.SNAPSHOT
Bundle Locationinputstream:StoreLocator.Shoprite.Onnet-bundle-1.0-SNAPSHOT.jar
Last ModificationWed Oct 29 22:54:44 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)
Service ID 2927Types: StoreLocator.Shoprite.Onnet.HelloService
Service PID: StoreLocator.Shoprite.Onnet.impl.HelloServiceImpl
Component Name: StoreLocator.Shoprite.Onnet.impl.HelloServiceImpl
Component ID: 2030
Service ID 2928Types: StoreLocator.Shoprite.Onnet.IStoreLocator
Service PID: StoreLocator.Shoprite.Onnet.impl.StoreLocatorImpl
Component Name: StoreLocator.Shoprite.Onnet.impl.StoreLocatorImpl
Component ID: 2031
Service ID 2929Types: javax.servlet.Filter
Service PID: StoreLocator.Shoprite.Onnet.impl.filters.LoggingFilter
Component Name: StoreLocator.Shoprite.Onnet.impl.filters.LoggingFilter
Component ID: 2032
Service ID 2930Types: StoreLocator.Shoprite.Onnet.IStores
Service PID: Objects.Stores
Component Name: Objects.Stores
Component ID: 2033
Manifest HeadersBnd-LastModified: 1414616066053
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.IStoreLocator.Shoprite.Onnet-bundle
Bundle-Version: 1.0.0.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: Objects; uses:="StoreLocator.Shoprite.Onnet"; version="1.0.0.SNAPSHOT", StoreLocator.Shoprite.Onnet; uses:=Objects; version="1.0.0"
Import-Package: Objects; version="[1.0, 2)", 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
Originally-Created-By: Apache Maven Bundle Plugin
Service-Component: OSGI-INF/StoreLocator.Shoprite.Onnet.impl.HelloServiceImpl.xml, OSGI-INF/StoreLocator.Shoprite.Onnet.impl.StoreLocatorImpl.xml, OSGI-INF/StoreLocator.Shoprite.Onnet.impl.filters.LoggingFilter.xml, OSGI-INF/Objects.Stores.xml
Tool: Bnd-1.50.0
Used Services

In my jsp I use 

StoreLocator.Shoprite.Onnet.HelloService storeLocator = sling.getService(StoreLocator.Shoprite.Onnet.HelloService.class);

 

org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 13 in the jsp file: /apps/storelocators/StoreLocatorAfrica/StoreLocatorAfrica.jsp StoreLocator.Shoprite.Onnet.HelloService cannot be resolved to a type 10: 11:     <% 12:     /// 13: StoreLocator.Shoprite.Onnet.HelloService storeLocator = sling.getService(StoreLocator.Shoprite.Onnet.HelloService.class);

 

in eclipse 

 

public interface HelloService {
    
    /**
     * @return the name of the underlying JCR repository implementation
     */
    public String getRepositoryName();

}

@Service
@Component(metatype = false)
public class HelloServiceImpl implements HelloService {
    
    @Reference
    private SlingRepository repository;

    public String getRepositoryName() {
        return repository.getDescriptor(Repository.REP_NAME_DESC);
    }

}

 

I have the same problem on using any other service 

     
Service ID 2928Types: StoreLocator.Shoprite.Onnet.IStoreLocator
     
Service ID 2930Types: StoreLocator.Shoprite.Onnet.IStores

 

Regards

 

Clive

1 Accepted Solution

Avatar

Correct answer by
Level 10

Can you bundle up your Java and send to me at scottm@adobe.com. I want to deploy your code and see what is happening. It looks fine and AEM should be locating the service. In your email - tell me what version of CQ you are using and a URL to this thread. 

View solution in original post

4 Replies

Avatar

Level 6

I have managed to get 

StoreLocator.Shoprite.Onnet.IStoreLocator storeLocator = sling.getService(StoreLocator.Shoprite.Onnet.IStoreLocator.class);
 StoreLocator.Shoprite.Onnet.IStores stores = sling.getService(StoreLocator.Shoprite.Onnet.IStores.class);

 

to work,

 

but I have 2  problems.

 

Any call to the object stores results in a null pointer exception

 

eg 

stores.setCountryID("7"); < 

 

Also if I call a method from below as 

ArrayList<StoreLocator.Shoprite.Onnet.IStores> = storeLocator.getStores("198"); The type object stores cannot be resolved. It is indirectly referenced from required .class files

public class StoreLocatorImpl implements IStoreLocator {
    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;        
    }        
}

Avatar

Level 6

I see in the console that I have 

     
Exported PackagesStoreLocator.Shoprite.Onnet,version=1.0.0

 

 

However the Class Store is in package Objects

and my implementations are in package StoreLocator.Shoprite.Onnet.impl.

I do not know if this could effect things. If I try use <%@ page import="StoreLocator.Shoprite.Onnet.*"%> no error.

How do i import a type in from the osgi bundle??

Avatar

Level 6

I made an error above 

 

ArrayList<StoreLocator.Shoprite.Onnet.IStores> = storeLocator.getStores("198"); 

ArrayList<StoreLocator.Shoprite.Onnet.IStores> storesList= storeLocator.getStores("198"); 

Avatar

Correct answer by
Level 10

Can you bundle up your Java and send to me at scottm@adobe.com. I want to deploy your code and see what is happening. It looks fine and AEM should be locating the service. In your email - tell me what version of CQ you are using and a URL to this thread.