Extending ProfileImages servlet in cq5

Tags: osgi cq5 sling

I am trying to extend ProfileImages servlet from /libs/foundation/src/impl/src/main/java/com/day/cq/wcm/foundation/pro file/impl/ProfileImages.java

and bundling as an OSGI service.

I have the following annotations

    resourceTypes = {"nt:file"},
    methods = {"GET"},
    selectors = {"adjust","adjust.small"},
    extensions = {"res", "jpg", "png", "gif"}

I see my service in bundles and Services in OSGI console. However it is not doing as ProfileImages servlet used to do

ProfileImages create the thumbnail if we invoke the following URL


If my servlet is invoke, I should get the same response


However I am getting is 404 which is from the DefaultGetServlet

It seems that Sling servet is not able to resolve my servlet

One thing I need to know is how to get my service updated in

Apache Sling Servlet Resolverorg.apache.sling.servlets.resolver

My servlet is doing the same thing as the following service in sling servlet resolver

Service ID 843 Types: org.apache.sling.api.resource.ResourceProvider

Description: ServletResourceProvider for Servlets at [/libs/foundation/components/primary/nt/file/prof/thumbnail.gif.servl et, /libs/foundation/components/primary/nt/file/prof.gif.servlet, /libs/foundation/components/primary/nt/file/prof/thumbnail.res.servle t, /libs/foundation/components/primary/nt/file/prof.jpg.servlet, /libs/foundation/components/primary/nt/file/prof.png.servlet, /libs/foundation/components/primary/nt/file/prof/thumbnail.png.servle t, /libs/foundation/components/primary/nt/file/prof/thumbnail.jpg.servle t, /libs/foundation/components/primary/nt/file/prof.res.servlet]

My service should be listed in sling resolver with id and something like

...../adjust.small.jpg.servlet, ..../adjust.res.servlet I am using CRXDE web version for development Is there any configurations I have to do to get my service in over resource resolver?


Your servlet can not be resolved because it is not registered with the Declarative Services Runtime. The @Component and @SlingServlet annotations are not evaluated at runtime, they are part of the Apache Felix SCR Plugin Project which provides a maven plugin and ant task to create "OSGi Declarative Services" descriptors. http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin.html

For registering your Servlet as an OSGi Service an OSGI-INF/serviceComponents.xml file is required.

So I'm afraid you won't get around using a build lifecycle tool to build your OSGi bundle before uploading to CQ5, if you are planning to use the scr annotations. Else you have to create your service component file manually.

By : Thomas

This video can help you solving your question :)
By: admin