Sling Exporter with custom selector

Avatar

Avatar

veds89382868

Avatar

veds89382868

veds89382868

29-08-2018

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

veds89382868

Avatar

veds89382868

veds89382868

05-09-2018

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>

Answers (4)

Answers (4)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883
Arun_Patidar
MVP

30-08-2018

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

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K

Avatar

smacdonald2008

Total Posts

12.7K

Likes

1.4K

Correct Reply

2.3K
smacdonald2008

30-08-2018

See this Adobe doc for information on this subject - see if this helps...

Adobe Experience Manager Help | Developing Sling Model Exporters in AEM

Avatar

Avatar

veds89382868

Avatar

veds89382868

veds89382868

30-08-2018

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

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883
Arun_Patidar
MVP

29-08-2018

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