Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events
SOLVED

Resolving script for JSON

Avatar

Former Community Member

I am trying to understand how the location of a rendering script is resolved when using a json extension. I am also interested in the same question but when also including a selector.

I have been puzzling over the statements in this article :-

http://dev.day.com/docs/en/cq/current/developing/the_basics.html#Sling%2520Request%2520Processing

It all seems to work fine when the URL uses a .html extension, but if I use .json instead, it all goes a bit pear-shaped ?

Under the title 'Locating the script' from the article, it states :-

URLs in other formats, not ending with .html For example ../content/corporate/jobs/developer.pdf The script will be /apps/hr/jobs/jobs.pdf.esp; the suffix is added to the script name. URLs with selectors Selectors can be used to display the same content in an alternative format. For example a printer friendly version, an rss feed or a summary. If we look at a printer friendly version where the selector could be print; as in ../content/corporate/jobs/developer.print.html The script will be /apps/hr/jobs/jobs.print.esp; the selector is added to the script name. If no sling:resourceType has been defined then: the content path will be used to search for an appropriate script (if the path based ResourceTypeProvider is active). For example, the script for ../content/corporate/jobs/developer.html would generate a search in /apps/content/corporate/jobs/. the primary node type will be used. If no script is found at all then the default script will be used. The default rendition is currently supported as plain text (.txt), HTML (.html) and JSON (.json), all of which will list the node's properties (suitably formatted). The default rendition for the extension .res, or requests without a request extension, is to spool the resource (where possible). For http error handling (codes 403 or 404) Sling will look for a script at either: the location /apps/sling/servlet/errorhandler for customized scripts or the location of the standard scripts /libs/sling/servlet/errorhandler/403.esp, or 404.esp respectively.

So ... taking the first statement, if I use .json as the extension as in :-

/content/corporate/jobs/developer.json

it would suggest that this script could be found :-

/apps/hr/jobs/jobs.json.jsp

or even just:

/apps/hr/jobs/json.jsp

but doing that just results in default json render being called.

WHY AREN'T EITHER OF THE ABOVE SCRIPTS USED IF THEY ARE AVAILABLE IN THE FOLDER /apps/hr/jobs ???

Any attempt to use a selector as well as the json extension :-

/content/corporate/jobs/developer.print.json

causes :-

Invalid recursion selector value 'print'

Thoroughly confused !

Regards

Fraser.

1 Accepted Solution

Avatar

Correct answer by
Level 6

I assume, resource type label is single-trip and sling:resourceType is /apps/myprj/components/test. Under test component I have test.jsp, and telephone.json.jsp. Now if I hit this url then it will give me json output in the browser :

http://localhost:4502/content/aviva/en_uk/general-insurance/travel/single-trip/_jcr_content.telephone.json

Sam

View solution in original post

4 Replies

Avatar

Former Community Member

It's great that the forum is back and working again. I'm re-posting this question since it got swallowed during the time this forum was experiencing problems

Regards

Fraser.

Avatar

Level 10

What are you trying to do? You want a resource to render JSON formatted data? 

Avatar

Former Community Member

Fundamentally, 'Yes', but I also want to better understand how a JSON rendering script is located since this *appears* to be different ?

Some details :-

If I use this URL :-

http://localhost:4502/content/aviva/en_uk/general-insurance/travel/single-trip.telephone.html

I can see that my telephone.jsp rendering script is successfully found and outputs some html

However, if I only change the extension to json : http://localhost:4502/content/aviva/en_uk/general-insurance/travel/single-trip.telephone.json

I get a nasty surprise :-

Invalid recursion selector value 'telephone'

Cannot serve request to /content/aviva/en_uk/general-insurance/travel/single-trip.telephone.json in org.apache.sling.servlets.get.DefaultGetServlet

...

I do have a json.jsp in the same location as my telephone.jsp and assumed that it would be found. But clearly not ??

Can anyone explain why this is ??

If I look at the request log info for telephone.html, I can see that the request is handled by the primary foundation component Page.jsp :-

single-trip.telephone.html handled by Servlet=/libs/foundation/components/primary/cq/Page/Page.jsp

 

 

0 (2014-03-19 22:23:30) LOG Method=GET, PathInfo=/content/aviva/en_uk/general-insurance/travel/single-trip.telephone.html 0 (2014-03-19 22:23:30) TIMER_START{ResourceResolution} 0 (2014-03-19 22:23:30) TIMER_END{0,ResourceResolution} URI=/content/aviva/en_uk/general-insurance/travel/single-trip.telephone.html resolves to Resource=JcrNodeResource, type=cq:Page, superType=null, path=/content/aviva/en_uk/general-insurance/travel/single-trip 1 (2014-03-19 22:23:30) LOG Resource Path Info: SlingRequestPathInfo: path='/content/aviva/en_uk/general-insurance/travel/single-trip', selectorString='telephone', extension='html', suffix='null' 1 (2014-03-19 22:23:30) TIMER_START{ServletResolution} 1 (2014-03-19 22:23:30) TIMER_START{resolveServlet(JcrNodeResource, type=cq:Page, superType=null, path=/content/aviva/en_uk/general-insurance/travel/single-trip)} 1 (2014-03-19 22:23:30) TIMER_END{0,resolveServlet(JcrNodeResource, type=cq:Page, superType=null, path=/content/aviva/en_uk/general-insurance/travel/single-trip)} Using servlet /libs/foundation/components/primary/cq/Page/Page.jsp 1 (2014-03-19 22:23:30) TIMER_END{0,ServletResolution} URI=/content/aviva/en_uk/general-insurance/travel/single-trip.telephone.html handled by Servlet=/libs/foundation/components/primary/cq/Page/Page.jsp

and then eventually the telephone.jsp :-

 

36 (2014-03-19 22:23:30) LOG Including resource Paragraph, path=/content/aviva/en_uk/general-insurance/travel/single-trip/jcr:content/par/telephone, type=avivapocs/components/telephone, cssClass=default, column=0/0, diffInfo=[null], resource=[JcrNodeResource, type=avivapocs/components/telephone, superType=null, path=/content/aviva/en_uk/general-insurance/travel/single-trip/jcr:content/par/telephone] (SlingRequestPathInfo: path='/content/aviva/en_uk/general-insurance/travel/single-trip/jcr:content/par/telephone', selectorString='telephone', extension='html', suffix='null') 36 (2014-03-19 22:23:30) TIMER_START{resolveServlet(Paragraph, path=/content/aviva/en_uk/general-insurance/travel/single-trip/jcr:content/par/telephone, type=avivapocs/components/telephone, cssClass=default, column=0/0, diffInfo=[null], resource=[JcrNodeResource, type=avivapocs/components/telephone, superType=null, path=/content/aviva/en_uk/general-insurance/travel/single-trip/jcr:content/par/telephone])} 36 (2014-03-19 22:23:30) TIMER_END{0,resolveServlet(Paragraph, path=/content/aviva/en_uk/general-insurance/travel/single-trip/jcr:content/par/telephone, type=avivapocs/components/telephone, cssClass=default, column=0/0, diffInfo=[null], resource=[JcrNodeResource, type=avivapocs/components/telephone, superType=null, path=/content/aviva/en_uk/general-insurance/travel/single-trip/jcr:content/par/telephone])} Using servlet /apps/avivapocs/components/telephone/telephone.jsp

 

Looking at the same log for telephone.json, it appears that it uses an entirely different resolution process (Using servlet org.apache.sling.servlets.get.DefaultGetServlet) :-

 

 

0 (2014-03-19 22:25:04) LOG Method=GET, PathInfo=/content/aviva/en_uk/general-insurance/travel/single-trip.telephone.json 0 (2014-03-19 22:25:04) TIMER_START{ResourceResolution} 0 (2014-03-19 22:25:04) TIMER_END{0,ResourceResolution} URI=/content/aviva/en_uk/general-insurance/travel/single-trip.telephone.json resolves to Resource=JcrNodeResource, type=cq:Page, superType=null, path=/content/aviva/en_uk/general-insurance/travel/single-trip 0 (2014-03-19 22:25:04) LOG Resource Path Info: SlingRequestPathInfo: path='/content/aviva/en_uk/general-insurance/travel/single-trip', selectorString='telephone', extension='json', suffix='null' 0 (2014-03-19 22:25:04) TIMER_START{ServletResolution} 0 (2014-03-19 22:25:04) TIMER_START{resolveServlet(JcrNodeResource, type=cq:Page, superType=null, path=/content/aviva/en_uk/general-insurance/travel/single-trip)} 0 (2014-03-19 22:25:04) TIMER_END{0,resolveServlet(JcrNodeResource, type=cq:Page, superType=null, path=/content/aviva/en_uk/general-insurance/travel/single-trip)} Using servlet org.apache.sling.servlets.get.DefaultGetServlet 0 (2014-03-19 22:25:04) TIMER_END{0,ServletResolution} URI=/content/aviva/en_uk/general-insurance/travel/single-trip.telephone.json handled by Servlet=org.apache.sling.servlets.get.DefaultGetServlet

and eventually to : /libs/sling/servlet/errorhandler/default.jsp !!

 

0 (2014-03-19 22:25:04) LOG Applying Requestfilters 0 (2014-03-19 22:25:04) LOG Calling filter: org.apache.sling.bgservlets.impl.BackgroundServletStarterFilter 0 (2014-03-19 22:25:04) LOG Calling filter: org.apache.sling.i18n.impl.I18NFilter 0 (2014-03-19 22:25:04) LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter 0 (2014-03-19 22:25:04) LOG Calling filter: com.day.cq.wcm.designimporter.CanvasPageDeleteRequestFilter 0 (2014-03-19 22:25:04) LOG Calling filter: com.adobe.cq.history.impl.HistoryRequestFilter 0 (2014-03-19 22:25:04) LOG Calling filter: com.day.cq.wcm.core.impl.WCMRequestFilter 0 (2014-03-19 22:25:04) LOG Calling filter: com.adobe.granite.optout.impl.OptOutFilter 0 (2014-03-19 22:25:04) LOG Calling filter: com.day.cq.theme.impl.ThemeResolverFilter 0 (2014-03-19 22:25:04) LOG Calling filter: com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet 0 (2014-03-19 22:25:04) LOG Calling filter: org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter 0 (2014-03-19 22:25:04) LOG Calling filter: com.day.cq.wcm.mobile.core.impl.redirect.RedirectFilter 0 (2014-03-19 22:25:04) LOG RedirectFilter did not redirect (request extension does not match) 0 (2014-03-19 22:25:04) LOG Calling filter: com.day.cq.wcm.core.impl.warp.TimeWarpFilter 0 (2014-03-19 22:25:04) LOG Calling filter: com.day.cq.wcm.core.impl.AuthoringUIModeServiceImpl 0 (2014-03-19 22:25:04) LOG Applying Componentfilters 0 (2014-03-19 22:25:04) LOG Calling filter: com.day.cq.personalization.impl.TargetComponentFilter 0 (2014-03-19 22:25:04) LOG Calling filter: com.day.cq.wcm.core.impl.WCMComponentFilter 0 (2014-03-19 22:25:04) LOG Calling filter: com.day.cq.wcm.core.impl.WCMDebugFilter 0 (2014-03-19 22:25:04) TIMER_START{org.apache.sling.servlets.get.DefaultGetServlet#0} 0 (2014-03-19 22:25:04) LOG Using org.apache.sling.servlets.get.impl.helpers.JsonRendererServlet to render for extension=json 0 (2014-03-19 22:25:04) LOG Applying Error filters 0 (2014-03-19 22:25:04) LOG Calling filter: org.apache.sling.rewriter.impl.RewriterFilter 0 (2014-03-19 22:25:04) TIMER_START{handleError:status=400} 15 (2014-03-19 22:25:04) TIMER_END{15,handleError:status=400} Using handler /libs/sling/servlet/errorhandler/default.jsp 15 (2014-03-19 22:25:04) LOG Found processor for post processing ProcessorConfiguration: {contentTypes=[text/html],order=-1, active=true, valid=true, processErrorResponse=true, pipeline=(generator=Config(type=htmlparser, config={}), transformers=(Config(type=linkchecker, config={}), Config(type=mobile, config=JcrPropertyMap [node=node /libs/cq/config/rewriter/default/transformer-mobile, values={component-optional=true, jcr:primaryType=nt:unstructured}]), Config(type=mobiledebug, config=JcrPropertyMap [node=node /libs/cq/config/rewriter/default/transformer-mobiledebug, values={component-optional=true, jcr:primaryType=nt:unstructured}]), Config(type=contentsync, config=JcrPropertyMap [node=node /libs/cq/config/rewriter/default/transformer-contentsync, values={component-optional=true, jcr:primaryType=nt:unstructured}]), serializer=Config(type=htmlwriter, config={}))} 15 (2014-03-19 22:25:04) TIMER_END{15,Request Processing} Dumping SlingRequestProgressTracker Entries 15 (2014-03-19 22:25:04) TIMER_END{15,handleError:status=400} Error handler finished 15 (2014-03-19 22:25:04) TIMER_END{15,org.apache.sling.servlets.get.DefaultGetServlet#0} 15 (2014-03-19 22:25:04) TIMER_END{15,Request Processing} Request Processing

If I add apps/foundation/primary/cq/Page/Page.jsp and proxy.jsp then everything works, but I just can't figure out why Sling resolution doesn't find my custom json.jsp without needing to do this ??

Regards

Fraser

Avatar

Correct answer by
Level 6

I assume, resource type label is single-trip and sling:resourceType is /apps/myprj/components/test. Under test component I have test.jsp, and telephone.json.jsp. Now if I hit this url then it will give me json output in the browser :

http://localhost:4502/content/aviva/en_uk/general-insurance/travel/single-trip/_jcr_content.telephone.json

Sam