Search in sources :

Example 1 with WhiteboardServletHandler

use of org.apache.felix.http.base.internal.handler.WhiteboardServletHandler in project felix by apache.

the class WhiteboardManager method registerWhiteboardService.

/**
 * Register whiteboard service in the http service
 * @param handler Context handler
 * @param info Whiteboard service info
 */
private void registerWhiteboardService(final WhiteboardContextHandler handler, final WhiteboardServiceInfo<?> info) {
    try {
        int failureCode = -1;
        if (info instanceof ServletInfo) {
            final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
            if (servletContext == null) {
                failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
            } else {
                final ServletHandler servletHandler = new WhiteboardServletHandler(handler.getContextInfo().getServiceId(), servletContext, (ServletInfo) info, handler.getBundleContext(), info.getServiceReference().getBundle(), this.httpBundleContext.getBundle());
                handler.getRegistry().registerServlet(servletHandler);
            }
        } else if (info instanceof FilterInfo) {
            final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
            if (servletContext == null) {
                failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
            } else {
                final FilterHandler filterHandler = new WhiteboardFilterHandler(handler.getContextInfo().getServiceId(), servletContext, (FilterInfo) info, handler.getBundleContext());
                handler.getRegistry().registerFilter(filterHandler);
            }
        } else if (info instanceof ResourceInfo) {
            final ServletInfo servletInfo = ((ResourceInfo) info).getServletInfo();
            final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
            if (servletContext == null) {
                failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
            } else {
                final ServletHandler servleHandler = new HttpServiceServletHandler(handler.getContextInfo().getServiceId(), servletContext, servletInfo, new ResourceServlet(servletInfo.getPrefix()));
                handler.getRegistry().registerServlet(servleHandler);
            }
        } else if (info instanceof ListenerInfo) {
            final ExtServletContext servletContext = handler.getServletContext(info.getServiceReference().getBundle());
            if (servletContext == null) {
                failureCode = DTOConstants.FAILURE_REASON_SERVLET_CONTEXT_FAILURE;
            } else {
                final ListenerHandler listenerHandler = new WhiteboardListenerHandler(handler.getContextInfo().getServiceId(), servletContext, (ListenerInfo) info, handler.getBundleContext());
                handler.getRegistry().registerListeners(listenerHandler);
            }
        } else {
            // This should never happen, but we log anyway
            SystemLogger.error("Unknown whiteboard service " + info.getServiceReference(), null);
        }
        if (failureCode != -1) {
            this.failureStateHandler.addFailure(info, handler.getContextInfo().getServiceId(), failureCode);
        }
    } catch (final Exception e) {
        this.failureStateHandler.addFailure(info, handler.getContextInfo().getServiceId(), FAILURE_REASON_UNKNOWN, e);
    }
}
Also used : WhiteboardListenerHandler(org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler) ResourceInfo(org.apache.felix.http.base.internal.runtime.ResourceInfo) WhiteboardServletHandler(org.apache.felix.http.base.internal.handler.WhiteboardServletHandler) ServletHandler(org.apache.felix.http.base.internal.handler.ServletHandler) HttpServiceServletHandler(org.apache.felix.http.base.internal.handler.HttpServiceServletHandler) ExtServletContext(org.apache.felix.http.base.internal.context.ExtServletContext) WhiteboardFilterHandler(org.apache.felix.http.base.internal.handler.WhiteboardFilterHandler) WhiteboardFilterHandler(org.apache.felix.http.base.internal.handler.WhiteboardFilterHandler) FilterHandler(org.apache.felix.http.base.internal.handler.FilterHandler) ServletException(javax.servlet.ServletException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) ServletInfo(org.apache.felix.http.base.internal.runtime.ServletInfo) HttpServiceServletHandler(org.apache.felix.http.base.internal.handler.HttpServiceServletHandler) ListenerInfo(org.apache.felix.http.base.internal.runtime.ListenerInfo) ResourceServlet(org.apache.felix.http.base.internal.service.ResourceServlet) WhiteboardServletHandler(org.apache.felix.http.base.internal.handler.WhiteboardServletHandler) FilterInfo(org.apache.felix.http.base.internal.runtime.FilterInfo) WhiteboardListenerHandler(org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler) ListenerHandler(org.apache.felix.http.base.internal.handler.ListenerHandler)

Aggregations

IOException (java.io.IOException)1 ServletException (javax.servlet.ServletException)1 ExtServletContext (org.apache.felix.http.base.internal.context.ExtServletContext)1 FilterHandler (org.apache.felix.http.base.internal.handler.FilterHandler)1 HttpServiceServletHandler (org.apache.felix.http.base.internal.handler.HttpServiceServletHandler)1 ListenerHandler (org.apache.felix.http.base.internal.handler.ListenerHandler)1 ServletHandler (org.apache.felix.http.base.internal.handler.ServletHandler)1 WhiteboardFilterHandler (org.apache.felix.http.base.internal.handler.WhiteboardFilterHandler)1 WhiteboardListenerHandler (org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler)1 WhiteboardServletHandler (org.apache.felix.http.base.internal.handler.WhiteboardServletHandler)1 FilterInfo (org.apache.felix.http.base.internal.runtime.FilterInfo)1 ListenerInfo (org.apache.felix.http.base.internal.runtime.ListenerInfo)1 ResourceInfo (org.apache.felix.http.base.internal.runtime.ResourceInfo)1 ServletInfo (org.apache.felix.http.base.internal.runtime.ServletInfo)1 ResourceServlet (org.apache.felix.http.base.internal.service.ResourceServlet)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1