Search in sources :

Example 1 with FinishRequestException

use of com.revolsys.ui.web.exception.FinishRequestException in project com.revolsys.open by revolsys.

the class IafServlet method processRequest.

/**
 * Process the service request, uses the full path name of the request to
 * finds the page definition. The component heirarchy, list of request
 * processors and the menu tree from the config are used to handle the
 * request. If a PageNotFoundException was thrown by any of the request
 * processors a 404 response error code is set and no further processing is
 * performed. If a RedirectException is thrown the response is redirected to
 * the url from the exception.
 *
 * @param request the servlet request
 * @param response the servlet response
 * @exception ServletException if any unhandled exceptions occured during the
 *              processing of the request
 * @exception IOException if there was a problem sending data to the client
 * @see PageNotFoundException
 * @see RedirectException
 */
public void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
    try {
        String path = request.getServletPath();
        final String pathInfo = request.getPathInfo();
        if (pathInfo != null && !path.endsWith(pathInfo)) {
            path += pathInfo;
        }
        boolean secure = false;
        final String contextPath = request.getContextPath();
        if (path.endsWith(".wp")) {
            path = path.substring(0, path.length() - 3);
        } else if (path.endsWith(".wps")) {
            secure = true;
            path = path.substring(0, path.length() - 4);
        }
        final Page page = this.applicationConfig.getPage(contextPath + path);
        WebUiContext.set(new WebUiContext(this.applicationConfig, contextPath, page, request, response));
        if (page.isSecure() && !secure) {
            response.sendRedirect(page.getFullUrl());
            return;
        }
        processArguments(page, request);
        processAttributes(page, request);
        request.setAttribute("niceConfig", this.applicationConfig);
        request.setAttribute("nicePage", page);
        final String menuName = request.getParameter("menuName");
        request.setAttribute("menuSelected", menuName);
        request.setAttribute("title", page.getTitle());
        page.invokeActions(this.servletContext, request, response);
        final Layout layout = page.getLayout();
        if (layout != null) {
            final String file = layout.getFile();
            if (file != null && file.length() > 0) {
                forward(file, request, response);
            }
        }
    } catch (final FinishRequestException fre) {
        // Do nothing as the actions have handled the request
        return;
    } catch (final AuthenticationException pne) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    } catch (final PageNotFoundException pne) {
        log.error(pne.getMessage(), pne);
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } catch (final RedirectException re) {
        response.sendRedirect(response.encodeRedirectURL(re.getUrl()));
    } catch (final Throwable t) {
        log.error(t.getMessage(), t);
        throw new ServletException(t);
    }
}
Also used : ServletException(javax.servlet.ServletException) FinishRequestException(com.revolsys.ui.web.exception.FinishRequestException) PageNotFoundException(com.revolsys.ui.web.exception.PageNotFoundException) Layout(com.revolsys.ui.web.config.Layout) AuthenticationException(com.revolsys.ui.web.exception.AuthenticationException) Page(com.revolsys.ui.web.config.Page) WebUiContext(com.revolsys.ui.web.config.WebUiContext) RedirectException(com.revolsys.ui.web.exception.RedirectException)

Aggregations

Layout (com.revolsys.ui.web.config.Layout)1 Page (com.revolsys.ui.web.config.Page)1 WebUiContext (com.revolsys.ui.web.config.WebUiContext)1 AuthenticationException (com.revolsys.ui.web.exception.AuthenticationException)1 FinishRequestException (com.revolsys.ui.web.exception.FinishRequestException)1 PageNotFoundException (com.revolsys.ui.web.exception.PageNotFoundException)1 RedirectException (com.revolsys.ui.web.exception.RedirectException)1 ServletException (javax.servlet.ServletException)1