Search in sources :

Example 6 with FilterMap

use of org.apache.catalina.deploy.FilterMap in project Payara by payara.

the class StandardContext method addFilterMaps.

/**
 * Add multiple filter mappings to this Context.
 *
 * @param filterMaps The filter mappings to be added
 *
 * @exception IllegalArgumentException if the specified filter name
 *  does not match an existing filter definition, or the filter mapping
 *  is malformed
 */
public void addFilterMaps(FilterMaps filterMaps) {
    String[] servletNames = filterMaps.getServletNames();
    String[] urlPatterns = filterMaps.getURLPatterns();
    for (String servletName : servletNames) {
        FilterMap fmap = new FilterMap();
        fmap.setFilterName(filterMaps.getFilterName());
        fmap.setServletName(servletName);
        fmap.setDispatcherTypes(filterMaps.getDispatcherTypes());
        addFilterMap(fmap);
    }
    for (String urlPattern : urlPatterns) {
        FilterMap fmap = new FilterMap();
        fmap.setFilterName(filterMaps.getFilterName());
        fmap.setURLPattern(urlPattern);
        fmap.setDispatcherTypes(filterMaps.getDispatcherTypes());
        addFilterMap(fmap);
    }
}
Also used : FilterMap(org.apache.catalina.deploy.FilterMap)

Example 7 with FilterMap

use of org.apache.catalina.deploy.FilterMap in project Payara by payara.

the class StandardHostValve method status.

/**
 * Handle the HTTP status code (and corresponding message) generated
 * while processing the specified Request to produce the specified
 * Response.  Any exceptions that occur during generation of the error
 * report are logged and swallowed.
 *
 * @param request The request being processed
 * @param response The response being generated
 */
protected void status(Request request, Response response) {
    // Handle a custom error page for this status code
    Context context = request.getContext();
    if (context == null)
        return;
    /*
         * Only look for error pages when isError() is set.
         * isError() is set when response.sendError() is invoked.
         */
    if (!response.isError()) {
        return;
    }
    int statusCode = ((HttpResponse) response).getStatus();
    ErrorPage errorPage = context.findErrorPage(statusCode);
    if (errorPage != null) {
        if (errorPage.getLocation() != null) {
            File file = new File(context.getDocBase(), errorPage.getLocation());
            if (!file.exists()) {
                File file2 = new File(errorPage.getLocation());
                if (!file2.exists()) {
                    boolean fileExists = false;
                    for (String servletMapping : ((StandardHost) getContainer()).findDeployedApp(context.getPath()).findServletMappings()) {
                        if (URLPattern.match(servletMapping, errorPage.getLocation())) {
                            fileExists = true;
                            break;
                        }
                    }
                    if (!fileExists) {
                        for (FilterMap mapping : ((StandardHost) getContainer()).findDeployedApp(context.getPath()).findFilterMaps()) {
                            if (mapping.getDispatcherTypes().contains(DispatcherType.ERROR) && URLPattern.match(mapping.getURLPattern(), errorPage.getLocation())) {
                                fileExists = true;
                                break;
                            }
                        }
                        if (!fileExists) {
                            log.log(Level.WARNING, LogFacade.ERROR_PAGE_NOT_EXIST, new Object[] { file.getAbsolutePath(), file2.getAbsolutePath() });
                        }
                    }
                }
            }
        }
        setErrorPageContentType(response, errorPage.getLocation(), context);
        dispatchToErrorPage(request, response, errorPage, null, null, statusCode);
    } else if (statusCode >= 400 && statusCode < 600 && context.getDefaultErrorPage() != null) {
        dispatchToErrorPage(request, response, context.getDefaultErrorPage(), null, null, statusCode);
    } else // START SJSAS 6324911
    {
        errorPage = ((StandardHost) getContainer()).findErrorPage(statusCode);
        if (errorPage != null) {
            if (errorPage.getLocation() != null) {
                File file = new File(context.getDocBase(), errorPage.getLocation());
                if (!file.exists()) {
                    File file2 = new File(errorPage.getLocation());
                    if (!file2.exists()) {
                        log.log(Level.WARNING, LogFacade.ERROR_PAGE_NOT_EXIST, new Object[] { file.getAbsolutePath(), file2.getAbsolutePath() });
                    }
                }
            }
            try {
                setErrorPageContentType(response, errorPage.getLocation(), context);
                handleHostErrorPage(response, errorPage, statusCode);
            } catch (Exception e) {
                log("Exception processing " + errorPage, e);
            }
        }
    }
// END SJSAS 6324911
}
Also used : ErrorPage(org.apache.catalina.deploy.ErrorPage) FilterMap(org.apache.catalina.deploy.FilterMap) ClientAbortException(org.apache.catalina.connector.ClientAbortException)

Aggregations

FilterMap (org.apache.catalina.deploy.FilterMap)7 DispatcherType (javax.servlet.DispatcherType)2 FilterDef (org.apache.catalina.deploy.FilterDef)2 CacheManager (com.sun.appserv.web.cache.CacheManager)1 CacheMapping (com.sun.appserv.web.cache.mapping.CacheMapping)1 ValueConstraint (com.sun.appserv.web.cache.mapping.ValueConstraint)1 File (java.io.File)1 HashMap (java.util.HashMap)1 ClientAbortException (org.apache.catalina.connector.ClientAbortException)1 ErrorPage (org.apache.catalina.deploy.ErrorPage)1 Tomcat (org.apache.catalina.startup.Tomcat)1 org.glassfish.web.deployment.runtime (org.glassfish.web.deployment.runtime)1