Search in sources :

Example 1 with ServletTracker

use of org.apache.felix.http.base.internal.whiteboard.tracker.ServletTracker in project felix by apache.

the class WhiteboardManager method start.

/**
 * Start the whiteboard manager
 * @param containerContext The servlet context
 */
public void start(final ServletContext containerContext, @Nonnull final Dictionary<String, Object> httpServiceProps) {
    // runtime service gets the same props for now
    this.serviceRuntime.setAllAttributes(httpServiceProps);
    this.serviceRuntime.setAttribute(HttpServiceRuntimeConstants.HTTP_SERVICE_ID, Collections.singletonList(this.httpServiceFactory.getHttpServiceServiceId()));
    this.runtimeServiceReg = this.httpBundleContext.registerService(HttpServiceRuntime.class, serviceRuntime, this.serviceRuntime.getAttributes());
    this.serviceRuntime.setServiceReference(this.runtimeServiceReg.getReference());
    this.webContext = containerContext;
    // add context for http service
    final List<WhiteboardContextHandler> list = new ArrayList<>();
    final ServletContextHelperInfo info = new ServletContextHelperInfo(Integer.MAX_VALUE, HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID, HttpServiceFactory.HTTP_SERVICE_CONTEXT_NAME, "/", null);
    list.add(new HttpServiceContextHandler(info, registry.getRegistry(HttpServiceFactory.HTTP_SERVICE_CONTEXT_SERVICE_ID), httpServiceFactory, webContext, this.httpBundleContext.getBundle()));
    this.contextMap.put(HttpServiceFactory.HTTP_SERVICE_CONTEXT_NAME, list);
    // add default context
    final Dictionary<String, Object> props = new Hashtable<>();
    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME, HttpWhiteboardConstants.HTTP_WHITEBOARD_DEFAULT_CONTEXT_NAME);
    props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH, "/");
    props.put(Constants.SERVICE_RANKING, Integer.MIN_VALUE);
    this.defaultContextRegistration = httpBundleContext.registerService(ServletContextHelper.class, new ServiceFactory<ServletContextHelper>() {

        @Override
        public ServletContextHelper getService(final Bundle bundle, final ServiceRegistration<ServletContextHelper> registration) {
            return new ServletContextHelper(bundle) {
            };
        }

        @Override
        public void ungetService(final Bundle bundle, final ServiceRegistration<ServletContextHelper> registration, final ServletContextHelper service) {
        // nothing to do
        }
    }, props);
    addTracker(new FilterTracker(this.httpBundleContext, this));
    addTracker(new ListenersTracker(this.httpBundleContext, this));
    addTracker(new PreprocessorTracker(this.httpBundleContext, this));
    addTracker(new ResourceTracker(this.httpBundleContext, this));
    addTracker(new ServletContextHelperTracker(this.httpBundleContext, this));
    addTracker(new ServletTracker(this.httpBundleContext, this));
    this.plugin.register();
}
Also used : ListenersTracker(org.apache.felix.http.base.internal.whiteboard.tracker.ListenersTracker) HttpServiceRuntime(org.osgi.service.http.runtime.HttpServiceRuntime) HttpServiceFactory(org.apache.felix.http.base.internal.service.HttpServiceFactory) ServiceFactory(org.osgi.framework.ServiceFactory) Hashtable(java.util.Hashtable) Bundle(org.osgi.framework.Bundle) ResourceTracker(org.apache.felix.http.base.internal.whiteboard.tracker.ResourceTracker) ArrayList(java.util.ArrayList) ServletTracker(org.apache.felix.http.base.internal.whiteboard.tracker.ServletTracker) ServletContextHelper(org.osgi.service.http.context.ServletContextHelper) FilterTracker(org.apache.felix.http.base.internal.whiteboard.tracker.FilterTracker) ServletContextHelperTracker(org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextHelperTracker) ServletContextHelperInfo(org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo) PreprocessorTracker(org.apache.felix.http.base.internal.whiteboard.tracker.PreprocessorTracker) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 ServletContextHelperInfo (org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo)1 HttpServiceFactory (org.apache.felix.http.base.internal.service.HttpServiceFactory)1 FilterTracker (org.apache.felix.http.base.internal.whiteboard.tracker.FilterTracker)1 ListenersTracker (org.apache.felix.http.base.internal.whiteboard.tracker.ListenersTracker)1 PreprocessorTracker (org.apache.felix.http.base.internal.whiteboard.tracker.PreprocessorTracker)1 ResourceTracker (org.apache.felix.http.base.internal.whiteboard.tracker.ResourceTracker)1 ServletContextHelperTracker (org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextHelperTracker)1 ServletTracker (org.apache.felix.http.base.internal.whiteboard.tracker.ServletTracker)1 Bundle (org.osgi.framework.Bundle)1 ServiceFactory (org.osgi.framework.ServiceFactory)1 ServiceRegistration (org.osgi.framework.ServiceRegistration)1 ServletContextHelper (org.osgi.service.http.context.ServletContextHelper)1 HttpServiceRuntime (org.osgi.service.http.runtime.HttpServiceRuntime)1