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);
}
}
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;
}
}
}
}
}
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);
}
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
}
}
}
}
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);
}
}
Aggregations