From 57d0c042f23d4d8830c59d372eb3cfa69d4fb08a Mon Sep 17 00:00:00 2001 From: karsonto Date: Wed, 3 Apr 2024 11:52:00 +0800 Subject: [PATCH] use httpRequest --- .../common/protocol/http/HttpCommand.java | 9 +--- .../admin/handler/AbstractHttpHandler.java | 51 +++++++++++++++---- .../admin/handler/ConfigurationHandler.java | 4 +- .../handler/DeleteWebHookConfigHandler.java | 13 +++-- .../runtime/admin/handler/EventHandler.java | 11 ++-- .../admin/handler/GrpcClientHandler.java | 11 ++-- .../admin/handler/HTTPClientHandler.java | 12 ++--- .../runtime/admin/handler/HttpHandler.java | 5 +- .../handler/InsertWebHookConfigHandler.java | 10 ++-- .../runtime/admin/handler/MetaHandler.java | 4 +- .../runtime/admin/handler/MetricsHandler.java | 4 +- .../QueryRecommendEventMeshHandler.java | 7 +-- .../QueryWebHookConfigByIdHandler.java | 10 ++-- ...eryWebHookConfigByManufacturerHandler.java | 14 ++--- .../RedirectClientByIpPortHandler.java | 7 +-- .../handler/RedirectClientByPathHandler.java | 7 +-- .../RedirectClientBySubSystemHandler.java | 7 +-- .../admin/handler/RejectAllClientHandler.java | 4 +- .../handler/RejectClientByIpPortHandler.java | 7 +-- .../RejectClientBySubSystemHandler.java | 7 +-- .../handler/ShowClientBySystemHandler.java | 7 +-- .../admin/handler/ShowClientHandler.java | 4 +- .../ShowListenClientByTopicHandler.java | 7 +-- .../admin/handler/TCPClientHandler.java | 11 ++-- .../runtime/admin/handler/TopicHandler.java | 18 +++---- .../handler/UpdateWebHookConfigHandler.java | 10 ++-- .../runtime/boot/EventMeshAdminServer.java | 37 +------------- 27 files changed, 147 insertions(+), 151 deletions(-) diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java index b3112b7d3c..b635ce9f64 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java @@ -42,6 +42,7 @@ import lombok.Data; +@Deprecated @Data public class HttpCommand implements ProtocolTransportObject { @@ -69,14 +70,6 @@ public class HttpCommand implements ProtocolTransportObject { public URI requestURI; - public URI getRequestURI() { - return requestURI; - } - - public void setRequestURI(URI requestURI) { - this.requestURI = requestURI; - } - public CmdType cmdType = CmdType.REQ; public HttpCommand() { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AbstractHttpHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AbstractHttpHandler.java index c5b8bf55d0..44f042c4b0 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AbstractHttpHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AbstractHttpHandler.java @@ -18,10 +18,10 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.enums.HttpMethod; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.util.HttpResponseUtils; +import java.io.IOException; import java.util.HashMap; import java.util.Map; @@ -31,9 +31,15 @@ import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.HttpVersion; +import io.netty.handler.codec.http.QueryStringDecoder; +import io.netty.handler.codec.http.multipart.Attribute; +import io.netty.handler.codec.http.multipart.DefaultHttpDataFactory; +import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder; +import io.netty.handler.codec.http.multipart.InterfaceHttpData; import io.netty.util.AsciiString; import lombok.Data; @@ -41,6 +47,8 @@ @Data public abstract class AbstractHttpHandler implements org.apache.eventmesh.runtime.admin.handler.HttpHandler { + private static final DefaultHttpDataFactory DEFAULT_HTTP_DATA_FACTORY = new DefaultHttpDataFactory(false); + protected void write(ChannelHandlerContext ctx, byte[] result, AsciiString headerValue) { ctx.writeAndFlush(HttpResponseUtils.getHttpResponse(result, ctx, headerValue)).addListener(ChannelFutureListener.CLOSE); } @@ -111,32 +119,57 @@ protected Map queryToMap(String query) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { - switch (HttpMethod.valueOf(httpCommand.getHttpMethod())) { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + switch (HttpMethod.valueOf(httpRequest.method().name())) { case OPTIONS: preflight(ctx); break; case GET: - get(httpCommand, ctx); + get(httpRequest, ctx); break; case POST: - post(httpCommand, ctx); + post(httpRequest, ctx); break; case DELETE: - delete(httpCommand, ctx); + delete(httpRequest, ctx); break; default: // do nothing break; } } - protected void post(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception{ + protected void post(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception{ + } + + protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception{ } - protected void delete(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception{ + protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception{ } - protected void get(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception{ + protected Map parseHttpRequestBody(final HttpRequest httpRequest) throws IOException { + final long bodyDecodeStart = System.currentTimeMillis(); + final Map httpRequestBody = new HashMap<>(); + + if (io.netty.handler.codec.http.HttpMethod.GET.equals(httpRequest.method())) { + new QueryStringDecoder(httpRequest.uri()) + .parameters() + .forEach((key, value) -> httpRequestBody.put(key, value.get(0))); + } else if (io.netty.handler.codec.http.HttpMethod.POST.equals(httpRequest.method())) { + decodeHttpRequestBody(httpRequest, httpRequestBody); + } + return httpRequestBody; + } + + private void decodeHttpRequestBody(HttpRequest httpRequest, Map httpRequestBody) throws IOException { + final HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(DEFAULT_HTTP_DATA_FACTORY, httpRequest); + for (final InterfaceHttpData param : decoder.getBodyHttpDatas()) { + if (InterfaceHttpData.HttpDataType.Attribute == param.getHttpDataType()) { + final Attribute data = (Attribute) param; + httpRequestBody.put(data.getName(), data.getValue()); + } + } + decoder.destroy(); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ConfigurationHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ConfigurationHandler.java index 8d29cf500b..8a7d3d7ce8 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ConfigurationHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ConfigurationHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.admin.response.GetConfigurationResponse; import org.apache.eventmesh.runtime.common.EventHttpHandler; @@ -33,6 +32,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -73,7 +73,7 @@ public ConfigurationHandler( } @Override - protected void get(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/DeleteWebHookConfigHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/DeleteWebHookConfigHandler.java index 969a01b44d..66315f1257 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/DeleteWebHookConfigHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/DeleteWebHookConfigHandler.java @@ -18,17 +18,17 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; -import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.common.EventHttpHandler; import org.apache.eventmesh.webhook.api.WebHookConfig; import org.apache.eventmesh.webhook.api.WebHookConfigOperation; +import java.util.Map; import java.util.Objects; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -43,8 +43,7 @@ * {@linkplain org.apache.eventmesh.webhook.admin.FileWebHookConfigOperation * #deleteWebHookConfig FileWebHookConfigOperation} method as implementation to delete the WebHook configuration file; *

- * When {@code eventMesh.webHook.operationMode=nacos}, It calls the - * {@linkplain org.apache.eventmesh.webhook.admin.NacosWebHookConfigOperation + * When {@code eventMesh.webHook.operationMode=nacos}, It calls the {@linkplain org.apache.eventmesh.webhook.admin.NacosWebHookConfigOperation * #deleteWebHookConfig NacosWebHookConfigOperation} method as implementation to delete the WebHook configuration from Nacos. *

* The {@linkplain org.apache.eventmesh.webhook.receive.storage.HookConfigOperationManager#deleteWebHookConfig HookConfigOperationManager} , another @@ -70,11 +69,11 @@ public DeleteWebHookConfigHandler(WebHookConfigOperation operation) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { - Body body = httpCommand.getBody(); + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + Map body = parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); // Resolve to WebHookConfig - WebHookConfig webHookConfig = JsonUtils.mapToObject(body.toMap(), WebHookConfig.class); + WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); // Delete the existing WebHookConfig Integer code = operation.deleteWebHookConfig(webHookConfig); // operating result String result = 1 == code ? "deleteWebHookConfig Succeed!" : "deleteWebHookConfig Failed!"; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/EventHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/EventHandler.java index e69de0b5b7..9e4dcadc3f 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/EventHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/EventHandler.java @@ -17,12 +17,12 @@ package org.apache.eventmesh.runtime.admin.handler; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.common.EventHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.plugin.MQAdminWrapper; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -35,6 +35,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -74,10 +75,10 @@ public EventHandler( } @Override - protected void get(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); - String queryString = httpCommand.getRequestURI().getQuery(); + String queryString = URI.create(httpRequest.uri()).getQuery(); if (queryString == null || "".equals(queryString)) { write401(ctx); return; @@ -99,10 +100,10 @@ protected void get(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Ex } @Override - protected void post(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + protected void post(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); - String request = JsonUtils.toJSONString(httpCommand.getBody().toMap()); + String request = JsonUtils.toJSONString(parseHttpRequestBody(httpRequest)); byte[] rawRequest = request.getBytes(StandardCharsets.UTF_8); CloudEvent event = Objects.requireNonNull(EventFormatProvider .getInstance() diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/GrpcClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/GrpcClientHandler.java index a87ba75fd0..3712defd1a 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/GrpcClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/GrpcClientHandler.java @@ -18,8 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; -import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.admin.request.DeleteGrpcClientRequest; import org.apache.eventmesh.runtime.admin.response.GetClientResponse; @@ -39,6 +37,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -71,10 +70,10 @@ public GrpcClientHandler( } @Override - protected void delete(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { - Body body = httpCommand.getBody(); + protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + Map body = parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); - DeleteGrpcClientRequest deleteGrpcClientRequest = JsonUtils.mapToObject(body.toMap(), DeleteGrpcClientRequest.class); + DeleteGrpcClientRequest deleteGrpcClientRequest = JsonUtils.mapToObject(body, DeleteGrpcClientRequest.class); String url = Objects.requireNonNull(deleteGrpcClientRequest).getUrl(); ConsumerManager consumerManager = eventMeshGrpcServer.getConsumerManager(); Map> clientTable = consumerManager.getClientTable(); @@ -93,7 +92,7 @@ protected void delete(HttpCommand httpCommand, ChannelHandlerContext ctx) throws } @Override - protected void get(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/HTTPClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/HTTPClientHandler.java index 00b37fa0eb..f4e8eb7369 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/HTTPClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/HTTPClientHandler.java @@ -18,8 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; -import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.admin.request.DeleteHTTPClientRequest; import org.apache.eventmesh.runtime.admin.response.GetClientResponse; @@ -31,12 +29,14 @@ import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -68,10 +68,10 @@ public HTTPClientHandler( this.eventMeshHTTPServer = eventMeshHTTPServer; } - protected void delete(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { - Body body = httpCommand.getBody(); + protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + Map body = parseHttpRequestBody(httpRequest); if (!Objects.isNull(body)) { - DeleteHTTPClientRequest deleteHTTPClientRequest = JsonUtils.mapToObject(body.toMap(), DeleteHTTPClientRequest.class); + DeleteHTTPClientRequest deleteHTTPClientRequest = JsonUtils.mapToObject(body, DeleteHTTPClientRequest.class); String url = Objects.requireNonNull(deleteHTTPClientRequest).getUrl(); for (List clientList : eventMeshHTTPServer.getSubscriptionManager().getLocalClientInfoMapping().values()) { @@ -91,7 +91,7 @@ protected void delete(HttpCommand httpCommand, ChannelHandlerContext ctx) throws * * @throws Exception if an I/O error occurs while handling the request */ - protected void get(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { HttpHeaders responseHeaders = new DefaultHttpHeaders(); // Set the response headers responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/HttpHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/HttpHandler.java index 7813d77b7c..bfce52b12d 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/HttpHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/HttpHandler.java @@ -17,14 +17,13 @@ package org.apache.eventmesh.runtime.admin.handler; -import org.apache.eventmesh.common.protocol.http.HttpCommand; - import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.HttpRequest; /** * Admin HttpHandler */ public interface HttpHandler { - void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception; + void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception; } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java index d64b2419aa..efbc968ead 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java @@ -18,17 +18,17 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; -import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.common.EventHttpHandler; import org.apache.eventmesh.webhook.api.WebHookConfig; import org.apache.eventmesh.webhook.api.WebHookConfigOperation; +import java.util.Map; import java.util.Objects; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -78,10 +78,10 @@ public InsertWebHookConfigHandler(WebHookConfigOperation operation) { */ @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { - Body body = httpCommand.getBody(); + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + Map body = parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); - WebHookConfig webHookConfig = JsonUtils.mapToObject(body.toMap(), WebHookConfig.class); + WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); // Add the WebHookConfig if no existing duplicate configuration is found Integer code = operation.insertWebHookConfig(webHookConfig); // operating result String result = 1 == code ? "insertWebHookConfig Succeed!" : "insertWebHookConfig Failed!"; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetaHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetaHandler.java index 3b58f157ce..77e995b7fd 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetaHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetaHandler.java @@ -19,7 +19,6 @@ import org.apache.eventmesh.api.meta.dto.EventMeshDataInfo; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.admin.response.GetRegistryResponse; import org.apache.eventmesh.runtime.common.EventHttpHandler; @@ -36,6 +35,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -65,7 +65,7 @@ public MetaHandler(MetaStorage eventMeshMetaStorage) { } @Override - protected void get(HttpCommand httpCommand, ChannelHandlerContext ctx) throws IOException { + protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws IOException { HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetricsHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetricsHandler.java index 37338c0cea..cf2e46ecc6 100755 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetricsHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/MetricsHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.metrics.api.model.HttpSummaryMetrics; import org.apache.eventmesh.metrics.api.model.TcpSummaryMetrics; @@ -35,6 +34,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -69,7 +69,7 @@ public MetricsHandler(EventMeshHTTPServer eventMeshHTTPServer, } @Override - protected void get(HttpCommand httpCommand, ChannelHandlerContext ctx) throws IOException { + protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws IOException { HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java index 74765d9cb9..83bd76e6b3 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.utils.NetUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.common.EventHttpHandler; @@ -28,10 +27,12 @@ import org.apache.commons.lang3.StringUtils; +import java.net.URI; import java.util.Map; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -66,12 +67,12 @@ public QueryRecommendEventMeshHandler(EventMeshTCPServer eventMeshTCPServer) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { String result = ""; if (!eventMeshTCPServer.getEventMeshTCPConfiguration().isEventMeshServerMetaStorageEnable()) { throw new Exception("registry enable config is false, not support"); } - String queryString = httpCommand.getRequestURI().getQuery(); + String queryString = URI.create(httpRequest.uri()).getQuery(); Map queryStringInfo = NetUtils.formData2Dic(queryString); // Extract parameters from the query string String group = queryStringInfo.get(EventMeshConstants.MANAGE_GROUP); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByIdHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByIdHandler.java index 9c888bcdef..58a2438bea 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByIdHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByIdHandler.java @@ -18,8 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; -import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.common.EventHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -27,11 +25,13 @@ import org.apache.eventmesh.webhook.api.WebHookConfig; import org.apache.eventmesh.webhook.api.WebHookConfigOperation; +import java.util.Map; import java.util.Objects; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -84,14 +84,14 @@ public QueryWebHookConfigByIdHandler(WebHookConfigOperation operation) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); // Resolve to WebHookConfig - Body body = httpCommand.getBody(); + Map body = parseHttpRequestBody(httpRequest); if (!Objects.isNull(body)) { - WebHookConfig webHookConfig = JsonUtils.mapToObject(body.toMap(), WebHookConfig.class); + WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); // Retrieve the WebHookConfig by callback path WebHookConfig result = operation.queryWebHookConfigById(webHookConfig); // operating result String json = JsonUtils.toJSONString(result); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByManufacturerHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByManufacturerHandler.java index 2524d6fbbc..9b484f6a1f 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByManufacturerHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryWebHookConfigByManufacturerHandler.java @@ -18,8 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; -import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.common.EventHttpHandler; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -28,11 +26,13 @@ import org.apache.eventmesh.webhook.api.WebHookConfigOperation; import java.util.List; +import java.util.Map; import java.util.Objects; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -81,16 +81,16 @@ public QueryWebHookConfigByManufacturerHandler(WebHookConfigOperation operation) } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); // Resolve to WebHookConfig - Body body = httpCommand.getBody(); + Map body = parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); - WebHookConfig webHookConfig = JsonUtils.mapToObject(body.toMap(), WebHookConfig.class); - Integer pageNum = Integer.valueOf(body.toMap().get("pageNum").toString()); - Integer pageSize = Integer.valueOf(body.toMap().get("pageSize").toString()); + WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); + Integer pageNum = Integer.valueOf(body.get("pageNum").toString()); + Integer pageSize = Integer.valueOf(body.get("pageSize").toString()); // Retrieve the WebHookConfig list by manufacturer name List listWebHookConfig = operation.queryWebHookConfigByManufacturer(webHookConfig, pageNum, pageSize); // operating result diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java index e857a8ceba..9689a27a59 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.utils.NetUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.common.EventHttpHandler; @@ -30,11 +29,13 @@ import org.apache.commons.lang3.StringUtils; import java.net.InetSocketAddress; +import java.net.URI; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -73,9 +74,9 @@ public RedirectClientByIpPortHandler(EventMeshTCPServer eventMeshTCPServer) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { String result = ""; - String queryString = httpCommand.getRequestURI().getQuery(); + String queryString = URI.create(httpRequest.uri()).getQuery(); Map queryStringInfo = NetUtils.formData2Dic(queryString); // Extract parameters from the query string String ip = queryStringInfo.get(EventMeshConstants.MANAGE_IP); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java index eaaa5ffdfb..9a186b339f 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.utils.NetUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.common.EventHttpHandler; @@ -30,11 +29,13 @@ import org.apache.commons.lang3.StringUtils; import java.net.InetSocketAddress; +import java.net.URI; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -72,9 +73,9 @@ public RedirectClientByPathHandler(EventMeshTCPServer eventMeshTCPServer) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { String result = ""; - String queryString = httpCommand.getRequestURI().getQuery(); + String queryString = URI.create(httpRequest.uri()).getQuery(); Map queryStringInfo = NetUtils.formData2Dic(queryString); // Extract parameters from the query string String path = queryStringInfo.get(EventMeshConstants.MANAGE_PATH); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java index 978852c6e6..ce6cfbb179 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.utils.NetUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.common.EventHttpHandler; @@ -30,11 +29,13 @@ import org.apache.commons.lang3.StringUtils; import java.net.InetSocketAddress; +import java.net.URI; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -72,8 +73,8 @@ public RedirectClientBySubSystemHandler(final EventMeshTCPServer eventMeshTCPSer } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { - final Map queryStringInfo = NetUtils.formData2Dic(httpCommand.getRequestURI().getQuery()); + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + final Map queryStringInfo = NetUtils.formData2Dic(URI.create(httpRequest.uri()).getQuery()); // Extract parameters from the query string final String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM); final String destEventMeshIp = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_IP); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java index 68189405f3..7e149df4dc 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.utils.NetUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.common.EventHttpHandler; @@ -34,6 +33,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -65,7 +65,7 @@ public RejectAllClientHandler(final EventMeshTCPServer eventMeshTCPServer) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { // Retrieve the mapping between Sessions and their corresponding client address final ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); final ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java index dea3aea3d2..74136f617b 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.utils.NetUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.common.EventHttpHandler; @@ -30,6 +29,7 @@ import org.apache.commons.lang3.StringUtils; import java.net.InetSocketAddress; +import java.net.URI; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -37,6 +37,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -75,9 +76,9 @@ public RejectClientByIpPortHandler(EventMeshTCPServer eventMeshTCPServer) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { String result = ""; - String queryString = httpCommand.getRequestURI().getQuery(); + String queryString = URI.create(httpRequest.uri()).getQuery(); Map queryStringInfo = NetUtils.formData2Dic(queryString); // Extract parameters from the query string String ip = queryStringInfo.get(EventMeshConstants.MANAGE_IP); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java index c7804fc393..a13abedc54 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.utils.NetUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.common.EventHttpHandler; @@ -30,6 +29,7 @@ import org.apache.commons.lang3.StringUtils; import java.net.InetSocketAddress; +import java.net.URI; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -38,6 +38,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -84,9 +85,9 @@ private String printClients(Collection clients) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { String result; - String queryString = httpCommand.getRequestURI().getQuery(); + String queryString = URI.create(httpRequest.uri()).getQuery(); Map queryStringInfo = NetUtils.formData2Dic(queryString); // Extract parameter from the query string String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java index d1e6392c2b..d231efd8d8 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.common.utils.NetUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; @@ -28,11 +27,13 @@ import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import java.net.InetSocketAddress; +import java.net.URI; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -65,9 +66,9 @@ public ShowClientBySystemHandler(EventMeshTCPServer eventMeshTCPServer) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { StringBuilder result = new StringBuilder(); - String queryString = httpCommand.getRequestURI().getQuery(); + String queryString = URI.create(httpRequest.uri()).getQuery(); Map queryStringInfo = NetUtils.formData2Dic(queryString); // Extract parameter from the query string String subSystem = queryStringInfo.get(EventMeshConstants.MANAGE_SUBSYSTEM); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java index 69d202382b..4012c2796d 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.common.EventHttpHandler; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; @@ -31,6 +30,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -60,7 +60,7 @@ public ShowClientHandler(EventMeshTCPServer eventMeshTCPServer) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { StringBuilder result = new StringBuilder(); String newLine = System.getProperty("line.separator"); log.info("showAllClient================="); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java index a50eae48fb..46f9154d6f 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.common.utils.NetUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; @@ -28,11 +27,13 @@ import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import java.net.URI; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -65,9 +66,9 @@ public ShowListenClientByTopicHandler(EventMeshTCPServer eventMeshTCPServer) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { StringBuilder result = new StringBuilder(); - String queryString = httpCommand.getRequestURI().getQuery(); + String queryString = URI.create(httpRequest.uri()).getQuery(); Map queryStringInfo = NetUtils.formData2Dic(queryString); // Extract parameter from the query string String topic = queryStringInfo.get(EventMeshConstants.MANAGE_TOPIC); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TCPClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TCPClientHandler.java index 56cf9fc3a9..a4da5bf94c 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TCPClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TCPClientHandler.java @@ -18,8 +18,6 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; -import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.admin.request.DeleteTCPClientRequest; @@ -43,6 +41,7 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -75,11 +74,11 @@ public TCPClientHandler( } @Override - protected void delete(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { // Parse the request body string into a DeleteTCPClientRequest object - Body body = httpCommand.getBody(); + Map body = parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); - DeleteTCPClientRequest deleteTCPClientRequest = JsonUtils.mapToObject(body.toMap(), DeleteTCPClientRequest.class); + DeleteTCPClientRequest deleteTCPClientRequest = JsonUtils.mapToObject(body, DeleteTCPClientRequest.class); String host = Objects.requireNonNull(deleteTCPClientRequest).getHost(); int port = deleteTCPClientRequest.getPort(); @@ -104,7 +103,7 @@ protected void delete(HttpCommand httpCommand, ChannelHandlerContext ctx) throws } @Override - protected void get(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { // Set the response headers HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TopicHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TopicHandler.java index d8a1df9ae2..c30533d535 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TopicHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/TopicHandler.java @@ -19,8 +19,6 @@ import org.apache.eventmesh.api.admin.TopicProperties; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; -import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.admin.request.CreateTopicRequest; import org.apache.eventmesh.runtime.admin.request.DeleteTopicRequest; @@ -30,11 +28,13 @@ import org.apache.eventmesh.runtime.util.HttpResponseUtils; import java.util.List; +import java.util.Map; import java.util.Objects; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpHeaders; +import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.HttpResponseStatus; @@ -76,7 +76,7 @@ public TopicHandler( } @Override - protected void get(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { + protected void get(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); @@ -90,13 +90,13 @@ protected void get(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Ex } @Override - protected void post(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { - Body body = httpCommand.getBody(); + protected void post(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + Map body = parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); - CreateTopicRequest createTopicRequest = JsonUtils.mapToObject(body.toMap(), CreateTopicRequest.class); + CreateTopicRequest createTopicRequest = JsonUtils.mapToObject(body, CreateTopicRequest.class); String topicName = Objects.requireNonNull(createTopicRequest).getName(); admin.createTopic(topicName); writeSuccess(ctx); @@ -104,13 +104,13 @@ protected void post(HttpCommand httpCommand, ChannelHandlerContext ctx) throws E } @Override - protected void delete(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { - Body body = httpCommand.getBody(); + protected void delete(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + Map body = parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); HttpHeaders responseHeaders = new DefaultHttpHeaders(); responseHeaders.add(EventMeshConstants.CONTENT_TYPE, EventMeshConstants.APPLICATION_JSON); responseHeaders.add(EventMeshConstants.HANDLER_ORIGIN, "*"); - DeleteTopicRequest deleteTopicRequest = JsonUtils.mapToObject(body.toMap(), DeleteTopicRequest.class); + DeleteTopicRequest deleteTopicRequest = JsonUtils.mapToObject(body, DeleteTopicRequest.class); String topicName = Objects.requireNonNull(deleteTopicRequest).getName(); admin.deleteTopic(topicName); writeSuccess(ctx); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/UpdateWebHookConfigHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/UpdateWebHookConfigHandler.java index feaa53b289..030df9f944 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/UpdateWebHookConfigHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/UpdateWebHookConfigHandler.java @@ -18,17 +18,17 @@ package org.apache.eventmesh.runtime.admin.handler; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; -import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.common.EventHttpHandler; import org.apache.eventmesh.webhook.api.WebHookConfig; import org.apache.eventmesh.webhook.api.WebHookConfigOperation; +import java.util.Map; import java.util.Objects; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpHeaderValues; +import io.netty.handler.codec.http.HttpRequest; import lombok.extern.slf4j.Slf4j; @@ -73,11 +73,11 @@ public UpdateWebHookConfigHandler(WebHookConfigOperation operation) { } @Override - public void handle(HttpCommand httpCommand, ChannelHandlerContext ctx) throws Exception { - Body body = httpCommand.getBody(); + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + Map body = parseHttpRequestBody(httpRequest); Objects.requireNonNull(body, "body can not be null"); // Resolve to WebHookConfig - WebHookConfig webHookConfig = JsonUtils.mapToObject(body.toMap(), WebHookConfig.class); + WebHookConfig webHookConfig = JsonUtils.mapToObject(body, WebHookConfig.class); // Update the existing WebHookConfig Integer code = operation.updateWebHookConfig(webHookConfig); // operating result String result = 1 == code ? "updateWebHookConfig Succeed!" : "updateWebHookConfig Failed!"; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshAdminServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshAdminServer.java index 7295abee06..aca7caca19 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshAdminServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshAdminServer.java @@ -18,24 +18,17 @@ package org.apache.eventmesh.runtime.boot; import static org.apache.eventmesh.runtime.util.HttpResponseUtils.getHttpResponse; -import static org.apache.eventmesh.runtime.util.Utils.parseHttpHeader; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; -import org.apache.eventmesh.common.protocol.http.body.Body; -import org.apache.eventmesh.common.protocol.http.header.Header; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.admin.handler.AdminHandlerManager; import org.apache.eventmesh.runtime.admin.handler.HttpHandler; import org.apache.eventmesh.runtime.admin.response.Error; import org.apache.eventmesh.runtime.util.HttpResponseUtils; -import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; import java.net.URI; -import java.util.Collections; -import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -115,8 +108,7 @@ public void parseHttpRequest(ChannelHandlerContext ctx, HttpRequest httpRequest) Optional httpHandlerOpt = adminHandlerManager.getHttpHandler(uri.getPath()); if (httpHandlerOpt.isPresent()) { try { - HttpCommand httpCommand = parseHttpRequest(httpRequest); - httpHandlerOpt.get().handle(httpCommand, ctx); + httpHandlerOpt.get().handle(httpRequest, ctx); return; } catch (Exception e) { StringWriter writer = new StringWriter(); @@ -135,33 +127,6 @@ public void parseHttpRequest(ChannelHandlerContext ctx, HttpRequest httpRequest) } } - private HttpCommand parseHttpRequest(HttpRequest httpRequest) { - HttpCommand httpCommand = new HttpCommand(); - httpCommand.setHttpMethod(httpRequest.method().name()); - httpCommand.setHeader(new Header() { - @Override - public Map toMap() { - return parseHttpHeader(httpRequest); - } - }); - httpCommand.setBody(new Body() { - @Override - public Map toMap() { - try { - return EventMeshAdminServer.super.parseHttpRequestBody(httpRequest); - } catch (IOException ex) { - log.error("parse HttpRequest Body error!", ex); - } - return Collections.emptySortedMap(); - } - }); - httpCommand.setHttpVersion(httpRequest.protocolVersion() == null ? "" - : httpRequest.protocolVersion().protocolName()); - httpCommand.setRequestURI(URI.create(httpRequest.uri())); - return httpCommand; - } - - private class AdminServerInitializer extends ChannelInitializer {