Search in sources :

Example 1 with ServletContextHelperInfo

use of org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo in project felix by apache.

the class FailedDTOHolder method add.

public void add(final AbstractInfo<?> info, final long contextId, final int failureCode) {
    if (info instanceof ServletContextHelperInfo) {
        final FailedServletContextDTO dto = (FailedServletContextDTO) ServletContextDTOBuilder.build((ServletContextHelperInfo) info, null, failureCode);
        this.failedServletContextDTOs.add(dto);
    } else if (info instanceof ServletInfo) {
        boolean isError = false;
        if (((ServletInfo) info).getErrorPage() != null) {
            isError = true;
            final FailedErrorPageDTO dto = (FailedErrorPageDTO) ErrorPageDTOBuilder.build((ServletInfo) info, true);
            dto.failureReason = failureCode;
            final ErrorPageRegistry.ErrorRegistration reg = ErrorPageRegistry.getErrorRegistration((ServletInfo) info);
            dto.errorCodes = reg.errorCodes;
            dto.exceptions = reg.exceptions;
            dto.servletContextId = contextId;
            this.failedErrorPageDTOs.add(dto);
        }
        if (((ServletInfo) info).getPatterns() != null || ((ServletInfo) info).getName() != null || !isError) {
            final FailedServletDTO dto = (FailedServletDTO) ServletDTOBuilder.build((ServletInfo) info, failureCode);
            if (((ServletInfo) info).getPatterns() != null) {
                dto.patterns = ((ServletInfo) info).getPatterns();
            } else {
                dto.patterns = BuilderConstants.EMPTY_STRING_ARRAY;
            }
            dto.name = ((ServletInfo) info).getName();
            dto.servletContextId = contextId;
            this.failedServletDTOs.add(dto);
        }
    } else if (info instanceof FilterInfo) {
        final FailedFilterDTO dto = (FailedFilterDTO) FilterDTOBuilder.build((FilterInfo) info, failureCode);
        dto.failureReason = failureCode;
        dto.servletContextId = contextId;
        this.failedFilterDTOs.add(dto);
    } else if (info instanceof ResourceInfo) {
        final FailedResourceDTO dto = (FailedResourceDTO) ResourceDTOBuilder.build((ResourceInfo) info, true);
        dto.failureReason = failureCode;
        dto.servletContextId = contextId;
        this.failedResourceDTOs.add(dto);
    } else if (info instanceof ListenerInfo) {
        final FailedListenerDTO dto = (FailedListenerDTO) ListenerDTOBuilder.build((ListenerInfo) info, failureCode);
        dto.servletContextId = contextId;
        this.failedListenerDTOs.add(dto);
    } else if (info instanceof PreprocessorInfo) {
        final FailedPreprocessorDTO dto = (FailedPreprocessorDTO) PreprocessorDTOBuilder.build((PreprocessorInfo) info, failureCode);
        this.failedPreprocessorDTOs.add(dto);
    } else {
        SystemLogger.error("Unsupported info type: " + info.getClass(), null);
    }
}
Also used : FailedFilterDTO(org.osgi.service.http.runtime.dto.FailedFilterDTO) ResourceInfo(org.apache.felix.http.base.internal.runtime.ResourceInfo) FailedErrorPageDTO(org.osgi.service.http.runtime.dto.FailedErrorPageDTO) FailedServletDTO(org.osgi.service.http.runtime.dto.FailedServletDTO) FailedResourceDTO(org.osgi.service.http.runtime.dto.FailedResourceDTO) PreprocessorInfo(org.apache.felix.http.base.internal.runtime.PreprocessorInfo) ServletInfo(org.apache.felix.http.base.internal.runtime.ServletInfo) ListenerInfo(org.apache.felix.http.base.internal.runtime.ListenerInfo) ServletContextHelperInfo(org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo) FailedListenerDTO(org.osgi.service.http.runtime.dto.FailedListenerDTO) FailedPreprocessorDTO(org.osgi.service.http.runtime.dto.FailedPreprocessorDTO) FailedServletContextDTO(org.osgi.service.http.runtime.dto.FailedServletContextDTO) FilterInfo(org.apache.felix.http.base.internal.runtime.FilterInfo)

Example 2 with ServletContextHelperInfo

use of org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo 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

ServletContextHelperInfo (org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo)2 ArrayList (java.util.ArrayList)1 Hashtable (java.util.Hashtable)1 FilterInfo (org.apache.felix.http.base.internal.runtime.FilterInfo)1 ListenerInfo (org.apache.felix.http.base.internal.runtime.ListenerInfo)1 PreprocessorInfo (org.apache.felix.http.base.internal.runtime.PreprocessorInfo)1 ResourceInfo (org.apache.felix.http.base.internal.runtime.ResourceInfo)1 ServletInfo (org.apache.felix.http.base.internal.runtime.ServletInfo)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