Search in sources :

Example 1 with HTTP500Renderer

use of org.b3log.latke.servlet.renderer.HTTP500Renderer in project solo by b3log.

the class InitCheckFilter method doFilter.

/**
     * If Solo has not been initialized, so redirects to /init.
     *
     * @param request the specified request
     * @param response the specified response
     * @param chain filter chain
     * @throws IOException io exception
     * @throws ServletException servlet exception
     */
@Override
public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
    final HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    final String requestURI = httpServletRequest.getRequestURI();
    LOGGER.log(Level.TRACE, "Request[URI={0}]", requestURI);
    // If requests Latke Remote APIs, skips this filter 
    if (requestURI.startsWith(Latkes.getContextPath() + "/latke/remote")) {
        chain.doFilter(request, response);
        return;
    }
    final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
    final InitService initService = beanManager.getReference(InitService.class);
    if (initService.isInited()) {
        chain.doFilter(request, response);
        return;
    }
    if ("POST".equalsIgnoreCase(httpServletRequest.getMethod()) && (Latkes.getContextPath() + "/init").equals(requestURI)) {
        // Do initailization
        chain.doFilter(request, response);
        return;
    }
    if (!initReported) {
        LOGGER.log(Level.DEBUG, "Solo has not been initialized, so redirects to /init");
        initReported = true;
    }
    final HTTPRequestContext context = new HTTPRequestContext();
    context.setRequest((HttpServletRequest) request);
    context.setResponse((HttpServletResponse) response);
    request.setAttribute(Keys.HttpRequest.REQUEST_URI, Latkes.getContextPath() + "/init");
    request.setAttribute(Keys.HttpRequest.REQUEST_METHOD, HTTPRequestMethod.GET.name());
    final HttpControl httpControl = new HttpControl(DispatcherServlet.SYS_HANDLER.iterator(), context);
    try {
        httpControl.nextHandler();
    } catch (final Exception e) {
        context.setRenderer(new HTTP500Renderer(e));
    }
    DispatcherServlet.result(context);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HTTPRequestContext(org.b3log.latke.servlet.HTTPRequestContext) HttpControl(org.b3log.latke.servlet.HttpControl) HTTP500Renderer(org.b3log.latke.servlet.renderer.HTTP500Renderer) InitService(org.b3log.solo.service.InitService) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) LatkeBeanManager(org.b3log.latke.ioc.LatkeBeanManager)

Example 2 with HTTP500Renderer

use of org.b3log.latke.servlet.renderer.HTTP500Renderer in project solo by b3log.

the class PermalinkFilter method dispatchToArticleOrPageProcessor.

/**
     * Dispatches the specified request to the specified article or page 
     * processor with the specified response.
     * 
     * @param request the specified request
     * @param response the specified response
     * @param article the specified article
     * @param page the specified page
     * @throws ServletException servlet exception
     * @throws IOException io exception
     * @see HTTPRequestDispatcher#dispatch(org.b3log.latke.servlet.HTTPRequestContext) 
     */
private void dispatchToArticleOrPageProcessor(final ServletRequest request, final ServletResponse response, final JSONObject article, final JSONObject page) throws ServletException, IOException {
    final HTTPRequestContext context = new HTTPRequestContext();
    context.setRequest((HttpServletRequest) request);
    context.setResponse((HttpServletResponse) response);
    if (null != article) {
        request.setAttribute(Article.ARTICLE, article);
        request.setAttribute(Keys.HttpRequest.REQUEST_URI, Latkes.getContextPath() + "/article");
    } else {
        request.setAttribute(Page.PAGE, page);
        request.setAttribute(Keys.HttpRequest.REQUEST_URI, Latkes.getContextPath() + "/page");
    }
    request.setAttribute(Keys.HttpRequest.REQUEST_METHOD, HTTPRequestMethod.GET.name());
    final HttpControl httpControl = new HttpControl(DispatcherServlet.SYS_HANDLER.iterator(), context);
    try {
        httpControl.nextHandler();
    } catch (final Exception e) {
        context.setRenderer(new HTTP500Renderer(e));
    }
    DispatcherServlet.result(context);
}
Also used : HTTPRequestContext(org.b3log.latke.servlet.HTTPRequestContext) HttpControl(org.b3log.latke.servlet.HttpControl) HTTP500Renderer(org.b3log.latke.servlet.renderer.HTTP500Renderer) ServletException(javax.servlet.ServletException) RepositoryException(org.b3log.latke.repository.RepositoryException) IOException(java.io.IOException)

Example 3 with HTTP500Renderer

use of org.b3log.latke.servlet.renderer.HTTP500Renderer in project solo by b3log.

the class MockDispatcherServlet method service.

protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
    final HTTPRequestContext httpRequestContext = new HTTPRequestContext();
    httpRequestContext.setRequest(req);
    httpRequestContext.setResponse(resp);
    final HttpControl httpControl = new HttpControl(SYS_HANDLER.iterator(), httpRequestContext);
    try {
        httpControl.nextHandler();
    } catch (final Exception e) {
        httpRequestContext.setRenderer(new HTTP500Renderer(e));
    }
    result(httpRequestContext);
}
Also used : HTTPRequestContext(org.b3log.latke.servlet.HTTPRequestContext) HttpControl(org.b3log.latke.servlet.HttpControl) HTTP500Renderer(org.b3log.latke.servlet.renderer.HTTP500Renderer) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)3 ServletException (javax.servlet.ServletException)3 HTTPRequestContext (org.b3log.latke.servlet.HTTPRequestContext)3 HttpControl (org.b3log.latke.servlet.HttpControl)3 HTTP500Renderer (org.b3log.latke.servlet.renderer.HTTP500Renderer)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 LatkeBeanManager (org.b3log.latke.ioc.LatkeBeanManager)1 RepositoryException (org.b3log.latke.repository.RepositoryException)1 InitService (org.b3log.solo.service.InitService)1