First of all you probably want this dependency:
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.http.whiteboard</artifactId>
<version>1.0.0</version>
</dependency>
The lastest Apache Felix http and also the latest Equinox Http.Servlet both support this specification.
With this dependency will come:
org.osgi.service.http.context.ServletContextHelper
which you can publish an instance of with the context init params that you need like so (just using DS for simplicity):
import java.net.URL;
import java.util.Set;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.http.context.ServletContextHelper;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
@Component(
property = {
Constants.SERVICE_RANKING + ":Integer=10",
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME + "=default",
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH + "=/",
HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_INIT_PARAM_PREFIX + "someInitParam=value"
},
service = ServletContextHelper.class
)
public class MyContext extends ServletContextHelper {
public URL getResource(String name) {
return delegate.getResource(name);
}
public Set<String> getResourcePaths(String path) {
return delegate.getResourcePaths(path);
}
@Activate
private void activate(BundleContext bundleContext) {
delegate = new ServletContextHelper(bundleContext.getBundle()) {};
}
private ServletContextHelper delegate;
}
Keep adding more init params if you like.