Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
karsonto committed Jan 18, 2024
1 parent ff7aaf5 commit 3b74f5b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public void start() throws IOException {
int port = eventMeshTCPServer.getEventMeshTCPConfiguration().getEventMeshServerAdminPort();
HttpHandlerManager httpHandlerManager = new HttpHandlerManager();
EventMeshAdminServer server = new EventMeshAdminServer(port, false, eventMeshHTTPServer.getEventMeshHttpConfiguration(), httpHandlerManager);
httpHandlerManager.bind(server);
try {
server.init();
// TODO: Optimized for automatic injection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package org.apache.eventmesh.runtime.admin.controller;

import org.apache.eventmesh.runtime.boot.AbstractHTTPServer;
import org.apache.eventmesh.runtime.common.EventHttpHandler;
import org.apache.eventmesh.runtime.util.HttpResponseUtils;
import org.apache.eventmesh.runtime.util.Utils;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -67,12 +67,6 @@ public class HttpHandlerManager {

private final Map<String, HttpHandler> httpHandlerMap = new ConcurrentHashMap<>();

private AbstractHTTPServer abstractHTTPServer;

public void bind(AbstractHTTPServer abstractHTTPServer) {
this.abstractHTTPServer = abstractHTTPServer;
}

/**
* Registers an HTTP handler.
*
Expand Down Expand Up @@ -102,10 +96,10 @@ public void exec(ChannelHandlerContext ctx, HttpRequest httpRequest) {
return;
} catch (Exception e) {
log.error(e.getMessage(), e);
abstractHTTPServer.sendError(ctx, HttpResponseStatus.valueOf(500));
ctx.writeAndFlush(HttpResponseUtils.createInternalServerError()).addListener(ChannelFutureListener.CLOSE);
}
} else {
abstractHTTPServer.sendError(ctx, HttpResponseStatus.NOT_FOUND);
ctx.writeAndFlush(HttpResponseUtils.create404NotFound()).addListener(ChannelFutureListener.CLOSE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public static HttpResponse createInternalServerError() {
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}

public static HttpResponse create404NotFound() {
return new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
}

private static ByteBuf createByteBuf(ChannelHandlerContext ctx, String body) {
byte[] bytes = body.getBytes(Constants.DEFAULT_CHARSET);
ByteBuf byteBuf = ctx.alloc().buffer(bytes.length);
Expand Down

0 comments on commit 3b74f5b

Please sign in to comment.