You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@seata.apache.org by "funky-eyes (via GitHub)" <gi...@apache.org> on 2024/09/08 06:28:12 UTC
Re: [PR] feature: support http protocol [incubator-seata]
funky-eyes commented on code in PR #6801:
URL: https://github.com/apache/incubator-seata/pull/6801#discussion_r1749098760
##########
server/src/main/java/org/apache/seata/server/controller/ClusterController.java:
##########
@@ -56,23 +57,16 @@
*/
@RestController
@RequestMapping("/metadata/v1")
-public class ClusterController {
+public class ClusterController implements HttpController {
Review Comment:
为什么必须继承HttpController?可以设计成直接按RestController扫描吗?然后用一个适配器模式去设计吗?
Why do I have to inherit HttpController? Can I design it to scan directly by RestController? Then use an adapter pattern to design it?
##########
server/src/main/java/org/apache/seata/server/console/controller/HttpControllerManager.java:
##########
@@ -0,0 +1,21 @@
+package org.apache.seata.server.console.controller;
+
+import org.apache.seata.core.rpc.netty.http.HttpController;
+import org.apache.seata.core.rpc.netty.http.HttpDispatchHandler;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.util.List;
+
+@Component
+public class HttpControllerManager {
+
+ @Autowired
+ private List<HttpController> httpControllerList;
+
+ @PostConstruct
+ private void init() {
+ httpControllerList.forEach(HttpDispatchHandler::addHttpController);
Review Comment:
不应该采用List<HttpController>这种方式,应该继承AbstractAutoProxyCreator,去做controller的扫描,然后使用适配器等模式将其包装后,进行addHttpController
##########
core/src/main/java/org/apache/seata/core/rpc/netty/http/HttpDispatchHandler.java:
##########
@@ -0,0 +1,205 @@
+package org.apache.seata.core.rpc.netty.http;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.handler.codec.http.*;
+import io.netty.handler.codec.http.multipart.Attribute;
+import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder;
+import io.netty.handler.codec.http.multipart.InterfaceHttpData;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.AsyncEvent;
+import javax.servlet.AsyncListener;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Parameter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+public class HttpDispatchHandler extends SimpleChannelInboundHandler<HttpRequest> {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(HttpDispatchHandler.class);
+ private static final Map<String, HttpController> httpControllerMap = new ConcurrentHashMap<>();
+ private static final Map<String, Method> requestMethodMap = new ConcurrentHashMap<>();
+ private static final String INVALID_DEFAULT_VALUE = "\"\\n\\t\\t\\n\\t\\t\\n\\ue000\\ue001\\ue002\\n\\t\\t\\t\\t\\n";
+ private static final List<Class> mappingClass = new ArrayList<Class>() {{
+ add(GetMapping.class);
+ add(PostMapping.class);
Review Comment:
put跟delete应该也要做适配
Put and delete should also be adapted
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@seata.apache.org
For additional commands, e-mail: notifications-help@seata.apache.org