Commit a7cbd12e authored by Liang Ding's avatar Liang Ding

重构请求路由 #61

parent c4d5cbe3
......@@ -206,7 +206,7 @@ public final class Server extends BaseServer {
Dispatcher.HANDLERS.add(3, new PermalinkHandler());
Dispatcher.endRequestHandler = new AfterRequestHandler();
routeConsoleProcessors();
routeProcessors();
final Latkes.RuntimeDatabase runtimeDatabase = Latkes.getRuntimeDatabase();
final String jdbcUsername = Latkes.getLocalProperty("jdbc.username");
......@@ -365,10 +365,87 @@ public final class Server extends BaseServer {
}
}
/**
* 后台控制器使用函数式路由. https://github.com/b3log/solo/issues/12580
*/
public static void routeConsoleProcessors() {
public static void routeProcessors() {
routeConsoleProcessors();
routeIndexProcessors();
Dispatcher.mapping();
}
private static void routeIndexProcessors() {
final BeanManager beanManager = BeanManager.getInstance();
final ArticleProcessor articleProcessor = beanManager.getReference(ArticleProcessor.class);
final Dispatcher.RouterGroup articleGroup = Dispatcher.group();
articleGroup.post("/console/markdown/2html", articleProcessor::markdown2HTML).
get("/console/article-pwd", articleProcessor::showArticlePwdForm).
post("/console/article-pwd", articleProcessor::onArticlePwdForm).
post("/articles/random", articleProcessor::getRandomArticles).
get("/article/id/{id}/relevant/articles", articleProcessor::getRelevantArticles).
get("/get-article-content", articleProcessor::getArticleContent).
get("/articles", articleProcessor::getArticlesByPage).
get("/articles/tags/{tagTitle}", articleProcessor::getTagArticlesByPage).
get("/articles/archives/{yyyy}/{MM}", articleProcessor::getArchivesArticlesByPage).
get("/articles/authors/{author}", articleProcessor::getAuthorsArticlesByPage).
get("/authors/{author}", articleProcessor::showAuthorArticles).
get("/archives/{yyyy}/{MM}", articleProcessor::showArchiveArticles).
get("/article", articleProcessor::showArticle);
final B3Receiver b3Receiver = beanManager.getReference(B3Receiver.class);
final Dispatcher.RouterGroup b3Group = Dispatcher.group();
b3Group.route().post().put().uri("/apis/symphony/article").handler(b3Receiver::postArticle).
put("/apis/symphony/comment", b3Receiver::addComment);
final BlogProcessor blogProcessor = beanManager.getReference(BlogProcessor.class);
final Dispatcher.RouterGroup blogGroup = Dispatcher.group();
blogGroup.get("/manifest.json", blogProcessor::getPWAManifestJSON).
get("/blog/info", blogProcessor::getBlogInfo).
get("/blog/articles-tags", blogProcessor::getArticlesTags);
final CategoryProcessor categoryProcessor = beanManager.getReference(CategoryProcessor.class);
final Dispatcher.RouterGroup categoryGroup = Dispatcher.group();
categoryGroup.get("/articles/category/{categoryURI}", categoryProcessor::getCategoryArticlesByPage).
get("/category/{categoryURI}", categoryProcessor::showCategoryArticles);
final CommentProcessor commentProcessor = beanManager.getReference(CommentProcessor.class);
final Dispatcher.RouterGroup commentGroup = Dispatcher.group();
commentGroup.post("/article/comments", commentProcessor::addArticleComment);
final FeedProcessor feedProcessor = beanManager.getReference(FeedProcessor.class);
final Dispatcher.RouterGroup feedGroup = Dispatcher.group();
feedGroup.route().get().head().uri("/atom.xml").handler(feedProcessor::blogArticlesAtom).
get().head().uri("/rss.xml").handler(feedProcessor::blogArticlesRSS);
final IndexProcessor indexProcessor = beanManager.getReference(IndexProcessor.class);
final Dispatcher.RouterGroup indexGroup = Dispatcher.group();
indexGroup.route().get(new String[]{"", "/", "/index.html"}, indexProcessor::showIndex).
get("/start", indexProcessor::showStart).
get("/logout", indexProcessor::logout).
get("/kill-browser", indexProcessor::showKillBrowser);
final OAuthProcessor oAuthProcessor = beanManager.getReference(OAuthProcessor.class);
final Dispatcher.RouterGroup oauthGroup = Dispatcher.group();
oauthGroup.get("/login/redirect", oAuthProcessor::redirectAuth).
get("/login/callback", oAuthProcessor::authCallback);
final SearchProcessor searchProcessor = beanManager.getReference(SearchProcessor.class);
final Dispatcher.RouterGroup searchGroup = Dispatcher.group();
searchGroup.get("/opensearch.xml", searchProcessor::showOpensearchXML).
get("/search", searchProcessor::search);
final SitemapProcessor sitemapProcessor = beanManager.getReference(SitemapProcessor.class);
final Dispatcher.RouterGroup sitemapGroup = Dispatcher.group();
sitemapGroup.get("/sitemap.xml", sitemapProcessor::sitemap);
final TagProcessor tagProcessor = beanManager.getReference(TagProcessor.class);
final Dispatcher.RouterGroup tagGroup = Dispatcher.group();
tagGroup.get("/tags/{tagTitle}", tagProcessor::showTagArticles);
final UserTemplateProcessor userTemplateProcessor = beanManager.getReference(UserTemplateProcessor.class);
final Dispatcher.RouterGroup userTemplateGroup = Dispatcher.group();
userTemplateGroup.get("/{name}.html", userTemplateProcessor::showPage);
}
private static void routeConsoleProcessors() {
final BeanManager beanManager = BeanManager.getInstance();
final ConsoleAuthAdvice consoleAuthAdvice = beanManager.getReference(ConsoleAuthAdvice.class);
......@@ -500,8 +577,6 @@ public final class Server extends BaseServer {
final Dispatcher.RouterGroup staticSiteConsoleGroup = Dispatcher.group();
staticSiteConsoleGroup.middlewares(consoleAdminAuthAdvice::handle);
staticSiteConsoleGroup.put("/console/staticsite", staticSiteConsole::genSite);
Dispatcher.mapping();
}
/**
......
......@@ -26,13 +26,15 @@ import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.event.Event;
import org.b3log.latke.event.EventManager;
import org.b3log.latke.http.*;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.http.Request;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.Response;
import org.b3log.latke.http.Session;
import org.b3log.latke.http.renderer.AbstractFreeMarkerRenderer;
import org.b3log.latke.http.renderer.JsonRenderer;
import org.b3log.latke.http.renderer.TextHtmlRenderer;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.Pagination;
import org.b3log.latke.model.User;
import org.b3log.latke.service.LangPropsService;
......@@ -56,10 +58,10 @@ import java.util.*;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/ZephyrJung">Zephyr</a>
* @version 1.4.5.9, Jan 9, 2020
* @version 2.0.0.0, Feb 9, 2020
* @since 0.3.1
*/
@RequestProcessor
@Singleton
public class ArticleProcessor {
/**
......@@ -146,7 +148,6 @@ public class ArticleProcessor {
*
* @param context the specified request context
*/
@RequestProcessing(value = "/console/markdown/2html", method = HttpMethod.POST)
public void markdown2HTML(final RequestContext context) {
final JSONObject result = Solos.newSucc();
context.renderJSON(result);
......@@ -180,7 +181,6 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/console/article-pwd", method = HttpMethod.GET)
public void showArticlePwdForm(final RequestContext context) {
final String articleId = context.param("articleId");
if (StringUtils.isBlank(articleId)) {
......@@ -227,7 +227,6 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/console/article-pwd", method = HttpMethod.POST)
public void onArticlePwdForm(final RequestContext context) {
try {
final Request request = context.getRequest();
......@@ -268,7 +267,6 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/articles/random", method = HttpMethod.POST)
public void getRandomArticles(final RequestContext context) {
final JSONObject jsonObject = new JSONObject();
......@@ -301,7 +299,6 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/article/id/{id}/relevant/articles", method = HttpMethod.GET)
public void getRelevantArticles(final RequestContext context) {
final JSONObject jsonObject = new JSONObject();
......@@ -349,9 +346,7 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/get-article-content", method = HttpMethod.GET)
public void getArticleContent(final RequestContext context) {
final Request request = context.getRequest();
final String articleId = context.param("id");
if (StringUtils.isBlank(articleId)) {
return;
......@@ -380,7 +375,6 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/articles", method = HttpMethod.GET)
public void getArticlesByPage(final RequestContext context) {
final JSONObject jsonObject = new JSONObject();
final Request request = context.getRequest();
......@@ -422,7 +416,6 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/articles/tags/{tagTitle}", method = HttpMethod.GET)
public void getTagArticlesByPage(final RequestContext context) {
final JSONObject jsonObject = new JSONObject();
......@@ -475,7 +468,6 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/articles/archives/{yyyy}/{MM}", method = HttpMethod.GET)
public void getArchivesArticlesByPage(final RequestContext context) {
final JSONObject jsonObject = new JSONObject();
......@@ -527,7 +519,6 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/articles/authors/{author}", method = HttpMethod.GET)
public void getAuthorsArticlesByPage(final RequestContext context) {
final JSONObject jsonObject = new JSONObject();
......@@ -577,7 +568,6 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/authors/{author}", method = HttpMethod.GET)
public void showAuthorArticles(final RequestContext context) {
final Request request = context.getRequest();
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "author-articles.ftl");
......@@ -638,7 +628,6 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/archives/{yyyy}/{MM}", method = HttpMethod.GET)
public void showArchiveArticles(final RequestContext context) {
final Request request = context.getRequest();
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "archive-articles.ftl");
......@@ -693,7 +682,6 @@ public class ArticleProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/article", method = HttpMethod.GET)
public void showArticle(final RequestContext context) {
// See PermalinkHandler#dispatchToArticleProcessor()
final JSONObject article = (JSONObject) context.attr(Article.ARTICLE);
......
......@@ -22,11 +22,9 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.Role;
import org.b3log.latke.model.User;
import org.b3log.latke.repository.Transaction;
......@@ -48,10 +46,10 @@ import java.util.Date;
* Receiving articles and comments from B3log community. Visits <a href="https://hacpai.com/b3log">B3log 构思</a> for more details.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.0.1.1, Mar 26, 2019
* @version 3.0.0.0, Feb 9, 2020
* @since 0.5.5
*/
@RequestProcessor
@Singleton
public class B3Receiver {
/**
......@@ -140,7 +138,6 @@ public class B3Receiver {
*
* @param context the specified request context
*/
@RequestProcessing(value = "/apis/symphony/article", method = {HttpMethod.POST, HttpMethod.PUT})
public void postArticle(final RequestContext context) {
final JSONObject ret = new JSONObject().put(Keys.CODE, 0);
context.renderJSON(ret);
......@@ -249,7 +246,6 @@ public class B3Receiver {
*
* @param context the specified request context
*/
@RequestProcessing(value = "/apis/symphony/comment", method = HttpMethod.PUT)
public void addComment(final RequestContext context) {
final JSONObject ret = new JSONObject().put(Keys.CODE, 0);
context.renderJSON(ret);
......
......@@ -24,12 +24,10 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.http.renderer.JsonRenderer;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.Pagination;
import org.b3log.latke.model.User;
import org.b3log.solo.Server;
......@@ -46,10 +44,10 @@ import java.nio.charset.StandardCharsets;
* Blog processor.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.4.0.2, Nov 15, 2019
* @version 2.0.0.0, Feb 9, 2020
* @since 0.4.6
*/
@RequestProcessor
@Singleton
public class BlogProcessor {
/**
......@@ -105,7 +103,6 @@ public class BlogProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/manifest.json", method = HttpMethod.GET)
public void getPWAManifestJSON(final RequestContext context) {
final JsonRenderer renderer = new JsonRenderer();
renderer.setPretty(true);
......@@ -143,7 +140,6 @@ public class BlogProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/blog/info", method = HttpMethod.GET)
public void getBlogInfo(final RequestContext context) {
final JsonRenderer renderer = new JsonRenderer();
context.setRenderer(renderer);
......@@ -182,7 +178,6 @@ public class BlogProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/blog/articles-tags", method = HttpMethod.GET)
public void getArticlesTags(final RequestContext context) {
final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(Pagination.PAGINATION_CURRENT_PAGE_NUM, 1);
......
......@@ -21,14 +21,12 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.Response;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.http.renderer.AbstractFreeMarkerRenderer;
import org.b3log.latke.http.renderer.JsonRenderer;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.Pagination;
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.service.ServiceException;
......@@ -51,10 +49,10 @@ import java.util.Map;
* Category processor.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.0, Mar 30, 2019
* @version 2.0.0.0, Feb 9, 2020
* @since 2.0.0
*/
@RequestProcessor
@Singleton
public class CategoryProcessor {
/**
......@@ -109,7 +107,6 @@ public class CategoryProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/articles/category/{categoryURI}", method = HttpMethod.GET)
public void getCategoryArticlesByPage(final RequestContext context) {
final JSONObject jsonObject = new JSONObject();
......@@ -157,7 +154,6 @@ public class CategoryProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/category/{categoryURI}", method = HttpMethod.GET)
public void showCategoryArticles(final RequestContext context) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "category-articles.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
......
......@@ -22,12 +22,10 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.http.renderer.JsonRenderer;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.User;
import org.b3log.latke.service.LangPropsService;
import org.b3log.solo.model.Article;
......@@ -51,10 +49,10 @@ import java.util.Map;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/armstrong">ArmstrongCN</a>
* @version 1.4.0.0, Apr 18, 2019
* @version 2.0.0.0, Feb 9, 2020
* @since 0.3.1
*/
@RequestProcessor
@Singleton
public class CommentProcessor {
/**
......@@ -125,7 +123,6 @@ public class CommentProcessor {
*
* @param context the specified context, including a request json object
*/
@RequestProcessing(value = "/article/comments", method = HttpMethod.POST)
public void addArticleComment(final RequestContext context) {
final JSONObject requestJSONObject = context.requestJSON();
requestJSONObject.put(Common.TYPE, Article.ARTICLE);
......
......@@ -23,13 +23,11 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.http.renderer.AtomRenderer;
import org.b3log.latke.http.renderer.RssRenderer;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.User;
import org.b3log.latke.repository.*;
import org.b3log.latke.service.ServiceException;
......@@ -60,10 +58,10 @@ import java.util.List;
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://github.com/feroozkhanchintu">feroozkhanchintu</a>
* @author <a href="https://github.com/nanolikeyou">nanolikeyou</a>
* @version 2.0.0.3, Jul 29, 2019
* @version 3.0.0.0, Feb 9, 2020
* @since 0.3.1
*/
@RequestProcessor
@Singleton
public class FeedProcessor {
/**
......@@ -94,7 +92,6 @@ public class FeedProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/atom.xml", method = {HttpMethod.GET, HttpMethod.HEAD})
public void blogArticlesAtom(final RequestContext context) {
final AtomRenderer renderer = new AtomRenderer();
context.setRenderer(renderer);
......@@ -167,7 +164,6 @@ public class FeedProcessor {
* @param context the specified context
* @throws Exception exception
*/
@RequestProcessing(value = "/rss.xml", method = {HttpMethod.GET, HttpMethod.HEAD})
public void blogArticlesRSS(final RequestContext context) {
final RssRenderer renderer = new RssRenderer();
context.setRenderer(renderer);
......
......@@ -23,11 +23,13 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.http.*;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.http.Cookie;
import org.b3log.latke.http.Request;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.Response;
import org.b3log.latke.http.renderer.AbstractFreeMarkerRenderer;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.Pagination;
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.service.ServiceException;
......@@ -54,10 +56,10 @@ import java.util.Map;
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="https://hacpai.com/member/DASHU">DASHU</a>
* @author <a href="https://vanessa.b3log.org">Vanessa</a>
* @version 1.2.4.18, Jan 7, 2020
* @version 2.0.0.0, Feb 9, 2020
* @since 0.3.1
*/
@RequestProcessor
@Singleton
public class IndexProcessor {
/**
......@@ -101,7 +103,6 @@ public class IndexProcessor {
* @param context the specified context
* @throws Exception exception
*/
@RequestProcessing(value = {"", "/", "/index.html"}, method = HttpMethod.GET)
public void showIndex(final RequestContext context) {
final Request request = context.getRequest();
final Response response = context.getResponse();
......@@ -160,7 +161,6 @@ public class IndexProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/start", method = HttpMethod.GET)
public void showStart(final RequestContext context) {
if (initService.isInited() && null != Solos.getCurrentUser(context.getRequest(), context.getResponse())) {
context.sendRedirect(Latkes.getServePath());
......@@ -196,7 +196,6 @@ public class IndexProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/logout", method = HttpMethod.GET)
public void logout(final RequestContext context) {
final Request request = context.getRequest();
......@@ -211,7 +210,6 @@ public class IndexProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/kill-browser", method = HttpMethod.GET)
public void showKillBrowser(final RequestContext context) {
final Request request = context.getRequest();
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "common-template/kill-browser.ftl");
......
......@@ -23,13 +23,11 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Latkes;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.Request;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.Response;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.Role;
import org.b3log.latke.model.User;
import org.b3log.latke.service.LangPropsService;
......@@ -50,10 +48,10 @@ import java.util.concurrent.ConcurrentHashMap;
* </ul>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.1.4, Jan 18, 2020
* @version 2.0.0.0, Feb 9, 2020
* @since 2.9.5
*/
@RequestProcessor
@Singleton
public class OAuthProcessor {
/**
......@@ -107,7 +105,6 @@ public class OAuthProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/login/redirect", method = HttpMethod.GET)
public void redirectAuth(final RequestContext context) {
String referer = context.param("referer");
if (StringUtils.isBlank(referer)) {
......@@ -127,7 +124,6 @@ public class OAuthProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/login/callback", method = HttpMethod.GET)
public synchronized void authCallback(final RequestContext context) {
String state = context.param("state");
final String referer = STATES.get(state);
......
......@@ -23,14 +23,12 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Latkes;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.Request;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.http.renderer.AbstractFreeMarkerRenderer;
import org.b3log.latke.http.renderer.TextXmlRenderer;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.Pagination;
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.util.Paginator;
......@@ -57,10 +55,10 @@ import java.util.Map;
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 1.1.1.3, Mar 19, 2019
* @version 2.0.0.0, Feb 9, 2020
* @since 2.4.0
*/
@RequestProcessor
@Singleton
public class SearchProcessor {
/**
......@@ -103,7 +101,6 @@ public class SearchProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/opensearch.xml", method = HttpMethod.GET)
public void showOpensearchXML(final RequestContext context) {
final TextXmlRenderer renderer = new TextXmlRenderer();
context.setRenderer(renderer);
......@@ -127,7 +124,6 @@ public class SearchProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/search", method = HttpMethod.GET)
public void search(final RequestContext context) {
final Request request = context.getRequest();
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "common-template/search.ftl");
......
......@@ -24,12 +24,10 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.Latkes;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.http.renderer.TextXmlRenderer;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.repository.FilterOperator;
import org.b3log.latke.repository.PropertyFilter;
import org.b3log.latke.repository.Query;
......@@ -53,10 +51,10 @@ import org.json.JSONObject;
* Sitemap processor.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.2.6, Jan 15, 2019
* @version 2.0.0.0, Feb 9, 2020
* @since 0.3.1
*/
@RequestProcessor
@Singleton
public class SitemapProcessor {
/**
......@@ -93,7 +91,6 @@ public class SitemapProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/sitemap.xml", method = HttpMethod.GET)
public void sitemap(final RequestContext context) {
final TextXmlRenderer renderer = new TextXmlRenderer();
context.setRenderer(renderer);
......
......@@ -21,12 +21,10 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.http.renderer.AbstractFreeMarkerRenderer;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.model.Pagination;
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.util.Paginator;
......@@ -46,10 +44,10 @@ import java.util.Map;
* Tag processor.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.1.8, Jan 5, 2019
* @version 2.0.0.0, Feb 9, 2020
* @since 0.3.1
*/
@RequestProcessor
@Singleton
public class TagProcessor {
/**
......@@ -104,7 +102,6 @@ public class TagProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/tags/{tagTitle}", method = HttpMethod.GET)
public void showTagArticles(final RequestContext context) {
final AbstractFreeMarkerRenderer renderer = new SkinRenderer(context, "tag-articles.ftl");
final Map<String, Object> dataModel = renderer.getDataModel();
......
......@@ -23,15 +23,13 @@ import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.b3log.latke.Keys;
import org.b3log.latke.http.HttpMethod;
import org.b3log.latke.http.Request;
import org.b3log.latke.http.RequestContext;
import org.b3log.latke.http.Response;
import org.b3log.latke.http.annotation.RequestProcessing;
import org.b3log.latke.http.annotation.RequestProcessor;
import org.b3log.latke.http.renderer.AbstractFreeMarkerRenderer;
import org.b3log.latke.http.renderer.TextHtmlRenderer;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.ioc.Singleton;
import org.b3log.latke.service.LangPropsService;
import org.b3log.latke.util.Locales;
import org.b3log.solo.model.Option;
......@@ -54,10 +52,10 @@ import java.util.Map;
* </p>
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.12, Jan 3, 2020
* @version 2.0.0.0, Feb 9, 2020
* @since 0.4.5
*/
@RequestProcessor
@Singleton
public class UserTemplateProcessor {
/**
......@@ -94,7 +92,6 @@ public class UserTemplateProcessor {
*
* @param context the specified context
*/
@RequestProcessing(value = "/{name}.html", method = HttpMethod.GET)
public void showPage(final RequestContext context) {
final String requestURI = context.requestURI();
final String templateName = context.pathVar("name") + ".ftl";
......
......@@ -52,7 +52,7 @@ import java.util.Collection;
* Abstract test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 3.0.0.3, Nov 6, 2019
* @version 4.0.0.0, Feb 9, 2020
* @since 2.9.7
*/
public abstract class AbstractTestCase {
......@@ -123,7 +123,7 @@ public abstract class AbstractTestCase {
requestJSONObject.put(UserExt.USER_B3_KEY, "pass");
initService.init(requestJSONObject);
final ErrorProcessor errorProcessor = beanManager.getReference(ErrorProcessor.class);
Dispatcher.get("/error/{statusCode}", errorProcessor::showErrorPage);
Dispatcher.error("/error/{statusCode}", errorProcessor::showErrorPage);
final UserQueryService userQueryService = getUserQueryService();
Assert.assertNotNull(userQueryService.getUserByName("Solo"));
}
......@@ -155,7 +155,7 @@ public abstract class AbstractTestCase {
public MockDispatcher mockDispatcher(final Request request, final Response response) {
final MockDispatcher ret = new MockDispatcher();
ret.init();
Server.routeConsoleProcessors();
Server.routeProcessors();
ret.handle(request, response);
return ret;
......
......@@ -20,7 +20,9 @@ package org.b3log.solo.processor;
import org.b3log.latke.http.Dispatcher;
import org.b3log.latke.http.Request;
import org.b3log.latke.http.Response;
import org.b3log.latke.http.handler.*;
import org.b3log.latke.http.handler.ContextHandleHandler;
import org.b3log.latke.http.handler.Handler;
import org.b3log.latke.http.handler.RouteHandler;
import java.util.ArrayList;
import java.util.List;
......@@ -29,7 +31,7 @@ import java.util.List;
* Mock dispatcher for unit tests.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.2, Dec 5, 2018
* @version 2.0.0.0, Feb 9, 2020
* @since 1.7.0
*/
public class MockDispatcher {
......@@ -41,9 +43,7 @@ public class MockDispatcher {
public void init() {
HANDLERS.add(new RouteHandler());
HANDLERS.add(new BeforeHandleHandler());
HANDLERS.add(new ContextHandleHandler());
HANDLERS.add(new AfterHandleHandler());
}
public void handle(final Request req, final Response resp) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment