Pil0tXia commented on code in PR #4768: URL: https://github.com/apache/eventmesh/pull/4768#discussion_r1549238601
########## eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/InsertWebHookConfigHandler.java: ########## @@ -76,24 +74,18 @@ public InsertWebHookConfigHandler(WebHookConfigOperation operation) { /** * Handles requests by adding a WebHook configuration. * - * @param httpExchange the exchange containing the request from the client and used to send the response - * @throws IOException if an I/O error occurs while handling the request + * @throws Exception if an I/O error occurs while handling the request */ - @Override - public void handle(HttpExchange httpExchange) throws IOException { - NetUtils.sendSuccessResponseHeaders(httpExchange); - // Resolve to WebHookConfig - String requestBody = NetUtils.parsePostBody(httpExchange); - WebHookConfig webHookConfig = JsonUtils.parseObject(requestBody, WebHookConfig.class); + @Override + public void handle(HttpRequest httpRequest, ChannelHandlerContext ctx) throws Exception { + Map<String, Object> body = parseHttpRequestBody(httpRequest); + Objects.requireNonNull(body, "body can not be null"); + 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!"; + write(ctx, result.getBytes(Constants.DEFAULT_CHARSET), HttpHeaderValues.TEXT_HTML); - try (OutputStream out = httpExchange.getResponseBody()) { - // 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!"; - out.write(result.getBytes(Constants.DEFAULT_CHARSET)); - } catch (Exception e) { - log.error("get WebHookConfigOperation implementation Failed.", e); - } } Review Comment: `HttpHeaderValues.TEXT_HTML` param can be wrapped in `AbstractHttpHandler`. Redundant line L89 & L79. ########## eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/AbstractHttpHandler.java: ########## @@ -17,18 +17,132 @@ package org.apache.eventmesh.runtime.admin.handler; -import com.sun.net.httpserver.HttpHandler; +import org.apache.eventmesh.common.enums.HttpMethod; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.util.HttpRequestUtil; +import org.apache.eventmesh.runtime.util.HttpResponseUtils; -import lombok.Data; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; -/** - * An abstract class that implements the {@link HttpHandler} interface - * and provides basic functionality for HTTP request handling. - * <p> - * Subclasses should extend this class to implement specific HTTP request handling logic. - */ +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; +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.util.AsciiString; + +import lombok.Data; @Data -public abstract class AbstractHttpHandler implements HttpHandler { +public abstract class AbstractHttpHandler implements org.apache.eventmesh.runtime.admin.handler.HttpHandler { + Review Comment: `implements HttpHandler` is available. -- 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: issues-unsubscr...@eventmesh.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@eventmesh.apache.org For additional commands, e-mail: issues-h...@eventmesh.apache.org