use of org.b3log.latke.servlet.HttpControl 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);
}
use of org.b3log.latke.servlet.HttpControl 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);
}
use of org.b3log.latke.servlet.HttpControl 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);
}
Aggregations