Expand my Community achievements bar.

SOLVED

Customized Rendition Servlet

Avatar

Level 7

Hi All,

 

We have a customized rendition servlet running fine on 6.0, but fails to run on 6.5 due to the Sling servlet spec changes. According to Apache Sling(https://sling.apache.org/documentation/the-sling-engine/servlets.html), either servlet's paths or resourceTypes must be defined in order for the servlet to take effect. I just define the resourceTypes in the servlet.

 

AEM 6.0 code:

// SCR annotations

@SlingServlet(selectors = {"preset", "precrop"}, extensions = {"xjpeg", "jpeg", "png"}, methods = {"GET"}, resourceTypes = {"sling/servlet/default"})

public class ImagePresetRenderingServlet extends SlingSafeMethodsServlet {

@Activate

protected void activate() throws Exception {

log.info("ImagePresetRendering--> activating!");

}

 

@Override

protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {

log.trace(some resource info here);

}

}// end clas

 

AEM 6.5 code:

// OSGI annotations

@Component(service=Servlet.class,

       property={

               "sling.servlet.methods=" + HttpConstants.METHOD_GET,

               "sling.servlet.extensions=xjpeg",

               "sling.servlet.extension=jpeg",

               "sling.servlet.extension=png",

               "sling.servlet.selectors=preset",

               "sling.servlet.selectors=precrop",

               "sling.servlet.resourceTypes="+"sling/servlet/default"

       }

)

 

public class ImagePresetRenderingServlet extends SlingSafeMethodsServlet {

@Activate

protected void activate() throws Exception {

log.info("ImagePresetRendering--> activating!");

}

 

@Override

protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {

log.trace(some resource info here);

}

}// end class

 

There is implmentation code in both, just simplying it. When I try to get the preset kanbar-thumb_sml.jpg.preset.three-two.jpeg, it has been working in 6.0, but in 6.5 I am getting an error:

....

....
5854 TIMER_END{5836,handleSecurity} authenticator org.apache.sling.auth.core.impl.SlingAuthenticator@119b1d86 returns true 6394 TIMER_START{ResourceResolution} 6730 TIMER_END{333,ResourceResolution} URI=/content/dam/tisch/Homepage/kanbar-thumb_sml.jpg.preset.three-two.jpeg resolves to Resource=JcrNodeResource, type=dam:Asset, superType=null, path=/content/dam/tisch/Homepage/kanbar-thumb_sml.jpg 6753 LOG Resource Path Info: SlingRequestPathInfo: path='/content/dam/tisch/Homepage/kanbar-thumb_sml.jpg', selectorString='preset.three-two', extension='jpeg', suffix='null' 6754 TIMER_START{ServletResolution} 6762 TIMER_START{resolveServlet(/content/dam/tisch/Homepage/kanbar-thumb_sml.jpg)} 9371 TIMER_END{2606,resolveServlet(/content/dam/tisch/Homepage/kanbar-thumb_sml.jpg)} Using servlet com.day.cq.dam.core.impl.servlet.BinaryProviderServlet 9382 TIMER_END{2626,ServletResolution} URI=/content/dam/tisch/Homepage/kanbar-thumb_sml.jpg.preset.three-two.jpeg handled by Servlet=com.day.cq.dam.core.impl.servlet.BinaryProviderServlet 9389 LOG Applying Requestfilters 9399 LOG Calling filter: com.adobe.granite.resourceresolverhelper.impl.ResourceResolverHelperImpl 9413 LOG Calling filter: org.apache.sling.security.impl.ContentDispositionFilter
....
12608 TIMER_END{34,resolveServlet(/content/dam/tisch/Homepage/kanbar-thumb_sml.jpg/jcr:content/renditions/original)} Using servlet org.apache.sling.servlets.get.DefaultGetServlet
12617 LOG Applying Forwardfilters

 

It always goes to BinaryProviderServlet first, then get.DefaultGetServlet in 6.5. In the log file, I can see the activate() method is called, not the doGet(...). My customized servlet is ignored. Am I missing any configuration in /system/console? Any help will be appreciated!

 

-kt

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @kevingtan, it looks that there is a typo in your OSGi annotations. For jpeg and png you have sling.servlet.extension instead of sling.servlet.extensions. This could be the reason why your servlet is not used for jpeg extension. Your code should looks like this:

@Component(service=Servlet.class,
       property={
               "sling.servlet.methods=" + HttpConstants.METHOD_GET,
               "sling.servlet.extensions=xjpeg",
               "sling.servlet.extensions=jpeg",
               "sling.servlet.extensions=png",
               "sling.servlet.selectors=preset",
               "sling.servlet.selectors=precrop",
               "sling.servlet.resourceTypes="+"sling/servlet/default"
       }
)

 

View solution in original post

4 Replies

Avatar

Level 4

Hi @kevingtan ,

 

You can try with giving service.ranking:Integer=<any-int-value> in component annotation. The higher the number the earlier in the filter chain. You can provide extension, selector as an array. Please refer this document on how to use attributes in component annotation.

http://www.sgaemsolutions.com/2017/07/migration-of-scr-annotations-to-osgi-r6.html

 

Thanks!

Avatar

Correct answer by
Community Advisor

Hi @kevingtan, it looks that there is a typo in your OSGi annotations. For jpeg and png you have sling.servlet.extension instead of sling.servlet.extensions. This could be the reason why your servlet is not used for jpeg extension. Your code should looks like this:

@Component(service=Servlet.class,
       property={
               "sling.servlet.methods=" + HttpConstants.METHOD_GET,
               "sling.servlet.extensions=xjpeg",
               "sling.servlet.extensions=jpeg",
               "sling.servlet.extensions=png",
               "sling.servlet.selectors=preset",
               "sling.servlet.selectors=precrop",
               "sling.servlet.resourceTypes="+"sling/servlet/default"
       }
)