YongGoose commented on code in PR #7451: URL: https://github.com/apache/incubator-seata/pull/7451#discussion_r2157151379
########## core/src/main/java/org/apache/seata/core/rpc/netty/http/HttpDispatchHandler.java: ########## @@ -82,13 +56,13 @@ protected void channelRead0(ChannelHandlerContext ctx, HttpRequest httpRequest) HttpInvocation httpInvocation = ControllerManager.getHttpInvocation(path); if (httpInvocation == null) { - sendErrorResponse(ctx, HttpResponseStatus.NOT_FOUND, keepAlive); + sendErrorResponse(ctx, HttpResponseStatus.NOT_FOUND, false); return; } - HttpContext httpContext = new HttpContext(httpRequest, ctx, keepAlive); + HttpContext<HttpRequest> httpContext = new HttpContext<>(httpRequest, ctx, keepAlive,HttpContext.HTTP_1_1); ObjectNode requestDataNode = OBJECT_MAPPER.createObjectNode(); - requestDataNode.putIfAbsent("param", ParameterParser.convertParamMap(queryStringDecoder.parameters())); + requestDataNode.put("param", ParameterParser.convertParamMap(queryStringDecoder.parameters())); Review Comment: Since the `requestDataNode` object is created just above, using `putIfAbsent` doesn’t seem strictly necessary.  > This is the constructor that is invoked by createObjectNode. However, put has been marked as deprecated, so using `set` is recommended instead. ########## core/src/test/java/org/apache/seata/core/rpc/netty/http/Http2HttpHandlerTest.java: ########## @@ -0,0 +1,183 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.core.rpc.netty.http; + +import com.fasterxml.jackson.databind.ObjectMapper; +import io.netty.buffer.Unpooled; +import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.handler.codec.http2.DefaultHttp2DataFrame; +import io.netty.handler.codec.http2.DefaultHttp2Headers; +import io.netty.handler.codec.http2.DefaultHttp2HeadersFrame; +import io.netty.handler.codec.http2.Http2Headers; +import io.netty.handler.codec.http2.Http2HeadersFrame; +import io.netty.handler.codec.http2.Http2StreamFrame; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.*; + +class Http2HttpHandlerTest { + private Http2HttpHandler handler; + private EmbeddedChannel channel; + private TestController testController = new TestController(); + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + + class TestController { + public String handleRequest(String param) { + return "Processed: " + param; + } + } + + @BeforeEach + void setUp() throws Exception { + handler = new Http2HttpHandler(); + channel = new EmbeddedChannel(handler); + // 注册controller + Method method = TestController.class.getMethod("handleRequest", String.class); + ParamMetaData paramMetaData = new ParamMetaData(); + paramMetaData.setParamConvertType(ParamMetaData.ParamConvertType.REQUEST_PARAM); + paramMetaData.setParamName("param"); + ParamMetaData[] paramMetaDatas = new ParamMetaData[]{paramMetaData}; + HttpInvocation invocation = new HttpInvocation(); + invocation.setController(testController); + invocation.setMethod(method); + invocation.setPath("/test"); + invocation.setParamMetaData(paramMetaDatas); + ControllerManager.addHttpInvocation(invocation); + } + + private Http2StreamFrame waitForHttp2Response(long timeoutMs) { + long startTime = System.currentTimeMillis(); + Http2StreamFrame response = null; + while (response == null && (System.currentTimeMillis() - startTime) < timeoutMs) { + response = channel.readOutbound(); + if (response == null) { + try { + Thread.sleep(10); + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException("Interrupted while waiting for response", e); + } + } + } + return response; + } + + @Test + void testHttp2GetRequestWithParameters() throws Exception { + // 构造 GET 请求 + Http2Headers headers = new DefaultHttp2Headers(); + headers.method("GET"); + headers.path("/test?param=testValue"); + Http2HeadersFrame headersFrame = new DefaultHttp2HeadersFrame(headers, true); + channel.writeInbound(headersFrame); + + // 使用等待方法获取响应 Review Comment: + 1 -- 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-unsubscr...@seata.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org