stbischof commented on code in PR #303: URL: https://github.com/apache/felix-dev/pull/303#discussion_r1561367912
########## http/README.md: ########## @@ -58,48 +77,75 @@ of additional bundles to deploy [as described in the jetty documentation](https: The OSGi whiteboard implementation simplifies the task of registering servlets, filters, resources, listeners, and servlet contexts. For a complete introduction, please refer to the OSGi R7 Compendium or Enterprise specification. -For a short introduction: Such a whiteboard service can be registered by exporting it as a service, making it no longer necessary to track and use the `HttpService` directly. The -whiteboard implementation detects all `javax.servlet.Servlet` and `javax.servlet.Filter` services with the right service properties. Let us illustrate the usage by registering a servlet: +For a short introduction: Such a whiteboard service can be registered by exporting it as a service, making it no longer necessary to track and use the `HttpService` directly (or the `ExtHttpService` in legacy implementations, for registering filters). The +whiteboard implementation detects all `jakarta.servlet.Servlet` and `jakarta.servlet.Filter` services with the right service properties. Let us illustrate the usage by registering a servlet and a filter: ```java public class Activator implements BundleActivator { - private ServiceRegistration registration; + private ServiceRegistration<Servlet> servletRegistration; + private ServiceRegistration<Filter> filterRegistration; public void start(BundleContext context) throws Exception { - Hashtable props = new Hashtable(); - props.put("osgi.http.whiteboard.servlet.pattern", "/hello"); - props.put("servlet.init.message", "Hello World!"); + Hashtable propsServlet = new Hashtable(); + propsServlet.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/hello"); + propsServlet.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, true); + propsServlet.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_INIT_PARAM_PREFIX + "message", "Hello World servlet!"); + + this.servletRegistration = context.registerService(Servlet.class.getName(), new HelloWorldServlet(), propsServlet); + + Hashtable propsFilter = new Hashtable(); + propsFilter.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX, ".*"); + propsFilter.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED, true); + propsFilter.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_INIT_PARAM_PREFIX + "message", "Hello World filter!"); - this.registration = context.registerService(Servlet.class.getName(), new HelloWorldServlet(), props); + this.filterRegistration = context.registerService(Filter.class.getName(), new HelloWorldFilter(), propsFilter); } public void stop(BundleContext context) throws Exception { - this.registration.unregister(); + this.servletRegistration.unregister(); + this.filterRegistration.unregister(); } } ``` +An implementation note for when using the Felix HTTP Jetty 12 bundle: only registering a filter without a servlet, will not work. Make sure that there is a servlet registered (on the same path as the filter) when registering a filter, even when that servlet is not hit eventually. To ensure the HTTP whiteboard service picks up your servlet and filter correctly, your service registration *must* provide several service properties. ### Servlet service properties +See full reference in the [OSGi specification](https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#service.http.whiteboard-i21223311). Review Comment: https://docs.osgi.org/specification/osgi.cmpn/8.1.0/ we should look to 8.1 release ########## http/README.md: ########## @@ -58,48 +77,75 @@ of additional bundles to deploy [as described in the jetty documentation](https: The OSGi whiteboard implementation simplifies the task of registering servlets, filters, resources, listeners, and servlet contexts. For a complete introduction, please refer to the OSGi R7 Compendium or Enterprise specification. -For a short introduction: Such a whiteboard service can be registered by exporting it as a service, making it no longer necessary to track and use the `HttpService` directly. The -whiteboard implementation detects all `javax.servlet.Servlet` and `javax.servlet.Filter` services with the right service properties. Let us illustrate the usage by registering a servlet: +For a short introduction: Such a whiteboard service can be registered by exporting it as a service, making it no longer necessary to track and use the `HttpService` directly (or the `ExtHttpService` in legacy implementations, for registering filters). The +whiteboard implementation detects all `jakarta.servlet.Servlet` and `jakarta.servlet.Filter` services with the right service properties. Let us illustrate the usage by registering a servlet and a filter: ```java public class Activator implements BundleActivator { - private ServiceRegistration registration; + private ServiceRegistration<Servlet> servletRegistration; + private ServiceRegistration<Filter> filterRegistration; public void start(BundleContext context) throws Exception { - Hashtable props = new Hashtable(); - props.put("osgi.http.whiteboard.servlet.pattern", "/hello"); - props.put("servlet.init.message", "Hello World!"); + Hashtable propsServlet = new Hashtable(); + propsServlet.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/hello"); + propsServlet.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, true); + propsServlet.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_INIT_PARAM_PREFIX + "message", "Hello World servlet!"); + + this.servletRegistration = context.registerService(Servlet.class.getName(), new HelloWorldServlet(), propsServlet); + + Hashtable propsFilter = new Hashtable(); + propsFilter.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_REGEX, ".*"); + propsFilter.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_ASYNC_SUPPORTED, true); + propsFilter.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_FILTER_INIT_PARAM_PREFIX + "message", "Hello World filter!"); - this.registration = context.registerService(Servlet.class.getName(), new HelloWorldServlet(), props); + this.filterRegistration = context.registerService(Filter.class.getName(), new HelloWorldFilter(), propsFilter); } public void stop(BundleContext context) throws Exception { - this.registration.unregister(); + this.servletRegistration.unregister(); + this.filterRegistration.unregister(); } } ``` +An implementation note for when using the Felix HTTP Jetty 12 bundle: only registering a filter without a servlet, will not work. Make sure that there is a servlet registered (on the same path as the filter) when registering a filter, even when that servlet is not hit eventually. To ensure the HTTP whiteboard service picks up your servlet and filter correctly, your service registration *must* provide several service properties. ### Servlet service properties +See full reference in the [OSGi specification](https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#service.http.whiteboard-i21223311). +The most important properties are: + * `osgi.http.whiteboard.servlet.pattern` - defines the servlet pattern to register the servlet under, should be a path as defined in the Servlet specification. * `osgi.http.whiteboard.context.select` - Filter expression to select the servlet context (optional). + * `osgi.http.whiteboard.servlet.asyncSupported` - Declares whether the servlet supports the asynchronous operation mode. Allowed values are true and false independent of case. Defaults to false. (optional) + * `osgi.http.whiteboard.servlet.multipart.enable` - Enables support for multipart configuration on the servlet. Allowed values are true and false independent of case. Defaults to false. (optional) * `servlet.init.*` - these properties (sans the `servlet.init.` prefix) are made available throught the `ServletConfig` object of your servlet. This allows you to supply your servlet initialization parameters as you would normally do in the web descriptor (web.xml). ### Filter service properties +See full reference in the [OSGi specification](https://docs.osgi.org/specification/osgi.cmpn/7.0.0/service.http.whiteboard.html#d0e121055). Review Comment: https://docs.osgi.org/specification/osgi.cmpn/8.1.0/ we should look to 8.1 release -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@felix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org