Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Sling Exporter with custom selector

Avatar

Level 1

Hi,

I'm trying to use sling exporter framework (Adobe Experience Manager Help | Developing Sling Model Exporters in AEM  , Apache Sling :: Sling Models to export sling model data. This is for Content As A Service.

My requirement is that, in CaaS REST api url, I should be able to pass query parameter so that we can return/export data accordingly based on the parameter value.

For that i added custom sling selector option in  Sling Model exporter to expose JSON accordingly.

Here is a snapshot of the class. If you look at it, i'm setting the "selector" attribute with "mobile"

The url i'm hitting:

http://localhost:6502/content/wcms/api/v1/as/devicedata.mobile.json

This give me error "

Invalid recursion selector value 'mobile'

It seems that the request is getting resolved by DefaultGetServlet instead of the dynamically generated Sling Models Exporter Servlets.

I can see the exporter servlets class here :http://localhost:6502/system/console/status-slingmodels

Any guidance is greatly appreciated.

Thanks

Ved

1 Accepted Solution

Avatar

Correct answer by
Level 1

So this combination is working.

Url:

http://localhost:6502/content/wcms/api/v1/as/devicedata/jcr:content.mobile.json

Dependency:

<dependency>

   <groupId>com.fasterxml.jackson.core</groupId>

   <artifactId>jackson-core</artifactId>

   <version>${fasterxml.jackson.version}</version>

</dependency>

<dependency>

   <groupId>com.fasterxml.jackson.core</groupId>

   <artifactId>jackson-databind</artifactId>

   <version>${fasterxml.jackson.version}</version>

</dependency>

<dependency>

   <groupId>com.fasterxml.jackson.core</groupId>

   <artifactId>jackson-annotations</artifactId>

   <version>${fasterxml.jackson.version}</version>

</dependency>

<fasterxml.jackson.version>2.5.2</fasterxml.jackson.version>

View solution in original post

5 Replies

Avatar

Community Advisor

Hi,

Try below if helps:

@Model(adaptables = Resource.class, resourceType="/apps/myApps/components/myComponent", defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL)

@Exporter(name = "jackson", selector="mobile", extensions = "json", options = { @ExporterOption(name = "SerializationFeature.WRITE_DATES_AS_TIMESTAMPS", value = "true") })

Please check AEM Developer Learning : Sling Model Exporter in AEM 6.3 for more info

Avatar

Level 1

Hi Arun,

I already tried that. No success. I get the same error.

Invalid recursion selector value 'mobile'

Cannot serve request to /content/wcms/api/v1/as/devicedata.mobile.json in org.apache.sling.servlets.get.DefaultGetServlet

Not sure if i need to install any feature pack. I have these installed.

Service Pack 2AEM-6.3.2.0-6.3.2.zip
Cumulative Fix Pack 2aem-6.3.2-cfp-2.0.zip
Updated FP for content service on SP2cq-6.3.0-featurepack-24425-1.0.2.zip
WCM Core Component 2.0.8core.wcm.components.all-2.0.8.zip
WCM Core component extension 1.0.4core.wcm.components.extension-1.0.4.zip

Thanks

Ved

Avatar

Community Advisor

Hi,

I tried in AEM 6.3 works for me.

Except below dependancy, I didn't do anything.

I am accessing resource like http://localhost:4502/content/AEM63App/language-masters/en/jcr:content/mainContent/hero_banner.mobil...

where hero_banner is my component node which I specified at in model annotation resourceType="/apps/myApps/components/myComponent

<dependency>

  <groupId>com.fasterxml.jackson.core</groupId>

  <artifactId>jackson-annotations</artifactId>

</dependency>

<dependency>

  <groupId>org.apache.sling</groupId>

  <artifactId>org.apache.sling.models.jacksonexporter</artifactId>

  <version>1.0.0</version>

</dependency>

Avatar

Correct answer by
Level 1

So this combination is working.

Url:

http://localhost:6502/content/wcms/api/v1/as/devicedata/jcr:content.mobile.json

Dependency:

<dependency>

   <groupId>com.fasterxml.jackson.core</groupId>

   <artifactId>jackson-core</artifactId>

   <version>${fasterxml.jackson.version}</version>

</dependency>

<dependency>

   <groupId>com.fasterxml.jackson.core</groupId>

   <artifactId>jackson-databind</artifactId>

   <version>${fasterxml.jackson.version}</version>

</dependency>

<dependency>

   <groupId>com.fasterxml.jackson.core</groupId>

   <artifactId>jackson-annotations</artifactId>

   <version>${fasterxml.jackson.version}</version>

</dependency>

<fasterxml.jackson.version>2.5.2</fasterxml.jackson.version>