Search in sources :

Example 1 with FilterHandler

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

the class PerBundleHttpServiceImpl method unregisterAll.

public void unregisterAll() {
    final Set<Servlet> servlets = new HashSet<Servlet>(this.localServlets);
    for (final Servlet servlet : servlets) {
        unregisterServlet(servlet, false);
    }
    final Set<FilterHandler> filters = new HashSet<FilterHandler>(this.localFilters);
    for (final FilterHandler holder : filters) {
        this.sharedHttpService.unregisterFilter(holder, false);
    }
}
Also used : Servlet(javax.servlet.Servlet) FilterHandler(org.apache.felix.http.base.internal.handler.FilterHandler) HttpServiceFilterHandler(org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler) HashSet(java.util.HashSet)

Example 2 with FilterHandler

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

the class PerBundleHttpServiceImpl method unregisterFilter.

private void unregisterFilter(final Filter filter, final boolean destroy) {
    if (filter != null) {
        synchronized (this.localFilters) {
            final Iterator<FilterHandler> i = this.localFilters.iterator();
            while (i.hasNext()) {
                final FilterHandler h = i.next();
                if (h.getFilter() == filter) {
                    this.sharedHttpService.unregisterFilter(h, destroy);
                    i.remove();
                    break;
                }
            }
        }
    }
}
Also used : FilterHandler(org.apache.felix.http.base.internal.handler.FilterHandler) HttpServiceFilterHandler(org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler)

Example 3 with FilterHandler

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

the class RequestDispatcherImpl method include.

@Override
public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    final ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request, this.resolution.handler.getContext(), this.requestInfo, DispatcherType.INCLUDE, this.resolution.handler.getServletInfo().isAsyncSupported(), this.resolution.handler.getMultipartConfig(), this.resolution.handler.getMultipartSecurityContext());
    final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
    final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.INCLUDE, requestURI);
    final FilterChain filterChain = new InvocationChain(resolution.handler, filterHandlers);
    filterChain.doFilter(req, response);
}
Also used : FilterChain(javax.servlet.FilterChain) FilterHandler(org.apache.felix.http.base.internal.handler.FilterHandler)

Example 4 with FilterHandler

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

the class RequestDispatcherImpl method forward.

@Override
public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException {
    if (response.isCommitted()) {
        throw new ServletException("Response has been committed");
    } else {
        // See section 9.4 of Servlet 3.0 spec
        response.resetBuffer();
    }
    try {
        final ServletRequestWrapper req = new ServletRequestWrapper((HttpServletRequest) request, this.resolution.handler.getContext(), this.requestInfo, DispatcherType.FORWARD, this.resolution.handler.getServletInfo().isAsyncSupported(), this.resolution.handler.getMultipartConfig(), this.resolution.handler.getMultipartSecurityContext());
        final String requestURI = UriUtils.concat(this.requestInfo.servletPath, this.requestInfo.pathInfo);
        final FilterHandler[] filterHandlers = this.resolution.handlerRegistry.getFilterHandlers(this.resolution.handler, DispatcherType.FORWARD, requestURI);
        final FilterChain filterChain = new InvocationChain(resolution.handler, filterHandlers);
        filterChain.doFilter(req, response);
    } finally {
        // see section 9.4 of Servlet 3.0 spec...
        if (!request.isAsyncStarted()) {
            response.flushBuffer();
            try {
                try {
                    response.getWriter().close();
                } catch (final IllegalStateException ise) {
                    // output stream has been used
                    response.getOutputStream().close();
                }
            } catch (final Exception ignore) {
            // ignore everything, see FELIX-5053
            }
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) FilterChain(javax.servlet.FilterChain) FilterHandler(org.apache.felix.http.base.internal.handler.FilterHandler) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 5 with FilterHandler

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

the class ServletResponseWrapper method sendError.

@Override
public void sendError(final int code, final String message) throws IOException {
    resetBuffer();
    setStatus(code);
    boolean invokeSuper = true;
    if (invocationCount.incrementAndGet() == 1) {
        // If we are allowed to have a body
        if (code != SC_NO_CONTENT && code != SC_NOT_MODIFIED && code != SC_PARTIAL_CONTENT && code >= SC_OK) {
            final Throwable exception = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
            final ServletHandler errorResolution = (errorRegistry == null ? null : errorRegistry.getErrorHandler(code, exception));
            if (errorResolution != null) {
                try {
                    request.setAttribute(RequestDispatcher.ERROR_STATUS_CODE, new Integer(code));
                    if (message != null) {
                        request.setAttribute(RequestDispatcher.ERROR_MESSAGE, message);
                    }
                    request.setAttribute(RequestDispatcher.ERROR_REQUEST_URI, request.getRequestURI());
                    if (this.servletName != null) {
                        request.setAttribute(RequestDispatcher.ERROR_SERVLET_NAME, this.servletName);
                    }
                    final String servletPath = null;
                    final String pathInfo = request.getRequestURI();
                    // XXX
                    final String queryString = null;
                    final RequestInfo requestInfo = new RequestInfo(servletPath, pathInfo, queryString, pathInfo);
                    final FilterHandler[] filterHandlers = errorRegistry.getFilterHandlers(errorResolution, DispatcherType.ERROR, request.getRequestURI());
                    final ServletRequestWrapper reqWrapper = new ServletRequestWrapper(request, errorResolution.getContext(), requestInfo, null, false, null, null);
                    final FilterChain filterChain = new InvocationChain(errorResolution, filterHandlers);
                    filterChain.doFilter(reqWrapper, this);
                    invokeSuper = false;
                } catch (final ServletException e) {
                // ignore
                } finally {
                    request.removeAttribute(RequestDispatcher.ERROR_STATUS_CODE);
                    request.removeAttribute(RequestDispatcher.ERROR_MESSAGE);
                    request.removeAttribute(RequestDispatcher.ERROR_REQUEST_URI);
                    request.removeAttribute(RequestDispatcher.ERROR_SERVLET_NAME);
                    request.removeAttribute(RequestDispatcher.ERROR_EXCEPTION);
                    request.removeAttribute(RequestDispatcher.ERROR_EXCEPTION_TYPE);
                }
            }
        }
    }
    if (invokeSuper) {
        super.sendError(code, message);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServletException(javax.servlet.ServletException) ServletHandler(org.apache.felix.http.base.internal.handler.ServletHandler) FilterChain(javax.servlet.FilterChain) FilterHandler(org.apache.felix.http.base.internal.handler.FilterHandler)

Aggregations

FilterHandler (org.apache.felix.http.base.internal.handler.FilterHandler)10 HttpServiceFilterHandler (org.apache.felix.http.base.internal.handler.HttpServiceFilterHandler)5 ServletException (javax.servlet.ServletException)4 FilterChain (javax.servlet.FilterChain)3 IOException (java.io.IOException)2 ExtServletContext (org.apache.felix.http.base.internal.context.ExtServletContext)2 ServletHandler (org.apache.felix.http.base.internal.handler.ServletHandler)2 FilterInfo (org.apache.felix.http.base.internal.runtime.FilterInfo)2 Test (org.junit.Test)2 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Filter (javax.servlet.Filter)1 FilterConfig (javax.servlet.FilterConfig)1 Servlet (javax.servlet.Servlet)1 HttpServiceServletHandler (org.apache.felix.http.base.internal.handler.HttpServiceServletHandler)1 ListenerHandler (org.apache.felix.http.base.internal.handler.ListenerHandler)1 WhiteboardFilterHandler (org.apache.felix.http.base.internal.handler.WhiteboardFilterHandler)1 WhiteboardListenerHandler (org.apache.felix.http.base.internal.handler.WhiteboardListenerHandler)1