Search in sources :

Example 1 with PreprocessorInfo

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

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

the class WhiteboardManager method removeWhiteboardService.

/**
 * Remove whiteboard service from the registry.
 *
 * @param info The service id of the whiteboard service
 */
public void removeWhiteboardService(final WhiteboardServiceInfo<?> info) {
    synchronized (this.contextMap) {
        if (!failureStateHandler.remove(info)) {
            if (info instanceof PreprocessorInfo) {
                synchronized (this.preprocessorHandlers) {
                    final List<PreprocessorHandler> newList = new ArrayList<>(this.preprocessorHandlers);
                    final Iterator<PreprocessorHandler> iter = newList.iterator();
                    while (iter.hasNext()) {
                        final PreprocessorHandler handler = iter.next();
                        if (handler.getPreprocessorInfo().compareTo((PreprocessorInfo) info) == 0) {
                            iter.remove();
                            this.preprocessorHandlers = newList;
                            updateRuntimeChangeCount();
                            return;
                        }
                    }
                // not found, nothing to do
                }
                return;
            }
            final List<WhiteboardContextHandler> handlerList = this.servicesMap.remove(info);
            if (handlerList != null) {
                for (final WhiteboardContextHandler h : handlerList) {
                    if (!failureStateHandler.remove(info, h.getContextInfo().getServiceId())) {
                        if (info instanceof ListenerInfo && ((ListenerInfo) info).isListenerType(ServletContextListener.class.getName())) {
                            final ListenerHandler handler = h.getRegistry().getEventListenerRegistry().getServletContextListener((ListenerInfo) info);
                            if (handler != null) {
                                final ServletContextListener listener = (ServletContextListener) handler.getListener();
                                if (listener != null) {
                                    EventListenerRegistry.contextDestroyed(handler.getListenerInfo(), listener, new ServletContextEvent(handler.getContext()));
                                }
                            }
                        }
                        this.unregisterWhiteboardService(h, info);
                    }
                }
            }
        }
        this.failureStateHandler.removeAll(info);
    }
    updateRuntimeChangeCount();
}
Also used : ListenerInfo(org.apache.felix.http.base.internal.runtime.ListenerInfo) ServletContextListener(javax.servlet.ServletContextListener) PreprocessorHandler(org.apache.felix.http.base.internal.handler.PreprocessorHandler) ArrayList(java.util.ArrayList) PreprocessorInfo(org.apache.felix.http.base.internal.runtime.PreprocessorInfo) WhiteboardListenerHandler(org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler) ListenerHandler(org.apache.felix.http.base.internal.handler.ListenerHandler) ServletContextEvent(javax.servlet.ServletContextEvent)

Example 3 with PreprocessorInfo

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

the class WhiteboardManager method addWhiteboardService.

/**
 * Add new whiteboard service to the registry
 *
 * @param info Whiteboard service info
 * @return {@code true} if it matches this http service runtime
 */
public boolean addWhiteboardService(@Nonnull final WhiteboardServiceInfo<?> info) {
    // no logging and no DTO if other target service
    if (isMatchingService(info)) {
        if (info.isValid()) {
            if (info instanceof PreprocessorInfo) {
                final PreprocessorHandler handler = new PreprocessorHandler(this.httpBundleContext, this.webContext, ((PreprocessorInfo) info));
                final int result = handler.init();
                if (result == -1) {
                    synchronized (this.preprocessorHandlers) {
                        final List<PreprocessorHandler> newList = new ArrayList<>(this.preprocessorHandlers);
                        newList.add(handler);
                        Collections.sort(newList);
                        this.preprocessorHandlers = newList;
                    }
                } else {
                    this.failureStateHandler.addFailure(info, FAILURE_REASON_VALIDATION_FAILED);
                }
                updateRuntimeChangeCount();
                return true;
            }
            synchronized (this.contextMap) {
                final List<WhiteboardContextHandler> handlerList = this.getMatchingContexts(info);
                this.servicesMap.put(info, handlerList);
                if (handlerList.isEmpty()) {
                    this.failureStateHandler.addFailure(info, FAILURE_REASON_NO_SERVLET_CONTEXT_MATCHING);
                } else {
                    for (final WhiteboardContextHandler h : handlerList) {
                        final int result = this.checkForServletRegistrationInHttpServiceContext(h, info);
                        if (result == -1) {
                            this.registerWhiteboardService(h, info);
                            if (info instanceof ListenerInfo && ((ListenerInfo) info).isListenerType(ServletContextListener.class.getName())) {
                                final ListenerHandler handler = h.getRegistry().getEventListenerRegistry().getServletContextListener((ListenerInfo) info);
                                if (handler != null) {
                                    final ServletContextListener listener = (ServletContextListener) handler.getListener();
                                    if (listener != null) {
                                        EventListenerRegistry.contextInitialized(handler.getListenerInfo(), listener, new ServletContextEvent(handler.getContext()));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else {
            this.failureStateHandler.addFailure(info, FAILURE_REASON_VALIDATION_FAILED);
        }
        updateRuntimeChangeCount();
        return true;
    }
    return false;
}
Also used : ListenerInfo(org.apache.felix.http.base.internal.runtime.ListenerInfo) ServletContextListener(javax.servlet.ServletContextListener) PreprocessorHandler(org.apache.felix.http.base.internal.handler.PreprocessorHandler) ArrayList(java.util.ArrayList) PreprocessorInfo(org.apache.felix.http.base.internal.runtime.PreprocessorInfo) WhiteboardListenerHandler(org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler) ListenerHandler(org.apache.felix.http.base.internal.handler.ListenerHandler) ServletContextEvent(javax.servlet.ServletContextEvent)

Aggregations

ListenerInfo (org.apache.felix.http.base.internal.runtime.ListenerInfo)3 PreprocessorInfo (org.apache.felix.http.base.internal.runtime.PreprocessorInfo)3 ArrayList (java.util.ArrayList)2 ServletContextEvent (javax.servlet.ServletContextEvent)2 ServletContextListener (javax.servlet.ServletContextListener)2 ListenerHandler (org.apache.felix.http.base.internal.handler.ListenerHandler)2 PreprocessorHandler (org.apache.felix.http.base.internal.handler.PreprocessorHandler)2 WhiteboardListenerHandler (org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler)2 FilterInfo (org.apache.felix.http.base.internal.runtime.FilterInfo)1 ResourceInfo (org.apache.felix.http.base.internal.runtime.ResourceInfo)1 ServletContextHelperInfo (org.apache.felix.http.base.internal.runtime.ServletContextHelperInfo)1 ServletInfo (org.apache.felix.http.base.internal.runtime.ServletInfo)1 FailedErrorPageDTO (org.osgi.service.http.runtime.dto.FailedErrorPageDTO)1 FailedFilterDTO (org.osgi.service.http.runtime.dto.FailedFilterDTO)1 FailedListenerDTO (org.osgi.service.http.runtime.dto.FailedListenerDTO)1 FailedPreprocessorDTO (org.osgi.service.http.runtime.dto.FailedPreprocessorDTO)1 FailedResourceDTO (org.osgi.service.http.runtime.dto.FailedResourceDTO)1 FailedServletContextDTO (org.osgi.service.http.runtime.dto.FailedServletContextDTO)1 FailedServletDTO (org.osgi.service.http.runtime.dto.FailedServletDTO)1