AEM 6.3 introduces a new, required approached for registering OSGi HTTP Servlets and Filters, and deprecates the old, "alias" method.

Updated Java Servlet annotations

Prior to AEM 6.3, OSGi HTTP Servlets were registered with only the "alias" Property to define the path the servlet responds to.

@Component
@Property(
        name = "alias",
        value = "/bin/my/servlet"
)
@Service(value = Servlet.class)
public class FelixServlet extends HttpServlet { ... }

Starting with AEM 6.3, OSGi HTTP Servlets must provide the osgi.http.whiteboard.servlet.pattern and osgi.http.whiteboard.context.select Properties to be properly registered.

import org.osgi.service.http.whiteboard.HttpWhiteboardConstants
...
@Component
@Properties({
        @Property( name = HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN,
                value = "/bin/my/servlet"
        ),
        @Property( name = HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
                value = ("(" +HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=org.osgi.service.http)")
        )
})
@Service(value = Servlet.class)
public class FelixServlet extends HttpServlet { ... }

Updated Servlet Filter annotations

Prior to AEM 6.3, OSGi HTTP Filters were registered with only the "pattern" Property to define the path patterns the filter responds to.

@Component(immediate=true)
@Property(
    name = "pattern",
    value = ".*"
)
@Service
public class LegacyFilter implements Filter { .. }

Starting with AEM 6.3, OSGi HTTP Filter must provide the osgi.http.whiteboard.filter.regex and osgi.http.whiteboard.context.select properties to be properly registered.

import org.osgi.service.http.whiteboard.HttpWhiteboardConstants
...
@Component
@Properties({
        @Property( name = HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX,
                value = "/"
        ),
        @Property( name = HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT,
                value = ("(" + HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=org.osgi.service.http)")
        )
})
@Service
public class FelixFilter extends Filter { ... }

Maven dependencies

The following dependencies are required to the updated annotations to be processed properly.

Note that a minimum version of 6.0.0 is required. Please use the latest 6.x version available.

<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>osgi.core</artifactId>
    <version>6.0.0</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.osgi</groupId>
    <artifactId>osgi.cmpn</artifactId>
    <version>6.0.0</version>
    <scope>provided</scope>
</dependency>

View the code

Supporting materials

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy