Skip to content

Commit

Permalink
fix: fix for Git request parameter problem
Browse files Browse the repository at this point in the history
  • Loading branch information
goodjava committed Jan 2, 2024
1 parent 36a5cd5 commit f8defd8
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion jcommon/docean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Based on Java20
* Fully utilized coroutines and ScopeValue
* JVM parameters that need to be added:
--enable-preview--add-modulesjdk.incubator.concurrent-ea--add-opensjava.base/java.lang=ALL-UNNAMED--add-opensjava.base/jdk.internal.misc=ALL-UNNAMED-Dio.netty.tryReflectionSetAccessible=true
--enable-preview --add-modulesjdk.incubator.concurrent -ea --add-opensjava.base/java.lang=ALL-UNNAMED--add-opensjava.base/jdk.internal.misc=ALL-UNNAMED-Dio.netty.tryReflectionSetAccessible=true
* A lightweight microservices development framework. It can be embedded into the Spring framework.
* Features: Compliant with Java standards, lightweight, no unnecessary libraries, low memory footprint, fast service
requests, high maintainability, and supports plugin extensions.
Expand Down
8 changes: 8 additions & 0 deletions jcommon/docean/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@
<target>21</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>21</source>
<target>21</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,12 @@ public void callMethod(MvcContext context, MvcRequest request, MvcResponse respo
Safe.run(() -> {
JsonElement args = getArgs(method, request.getMethod().toLowerCase(Locale.ROOT), request);
context.setParams(args);
Object[] params = methodInvoker.getMethodParams(method.getMethod(), args);
setMvcContext(context, params);
Object[] params = new Object[]{null};
if (method.getMethod().getParameterTypes().length == 1 && method.getMethod().getParameterTypes()[0].equals(MvcContext.class)) {
params[0] = context;
} else {
params = methodInvoker.getMethodParams(method.getMethod(), args);
}
Object data = this.mvcConfig.isUseCglib() ? methodInvoker.invokeFastMethod(method.getObj(), method.getMethod(), params) :
methodInvoker.invokeMethod(method.getObj(), method.getMethod(), params);

Expand Down
17 changes: 11 additions & 6 deletions jcommon/docean/src/main/java/com/xiaomi/youpin/docean/mvc/Get.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.xiaomi.youpin.docean.mvc;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.xiaomi.youpin.docean.anno.RequestParam;
import com.xiaomi.youpin.docean.mvc.httpmethod.HttpMethodUtils;
import io.netty.handler.codec.http.QueryStringDecoder;
Expand All @@ -31,22 +33,25 @@
*/
public abstract class Get {

public static JsonArray getParams(HttpRequestMethod method, String uri) {
public static JsonElement getParams(HttpRequestMethod method, String uri) {
QueryStringDecoder decoder = new QueryStringDecoder(uri);
Map<String, String> params = decoder.parameters().entrySet().stream().collect(Collectors.toMap(it -> it.getKey(), it -> it.getValue().get(0)));
JsonArray array = new JsonArray();
HttpMethodUtils.addMvcContext(method, array);
if (null == params) {
return array;

//只有一个参数,并且是MvcContext
if (HttpMethodUtils.paramIsMvcContext(method)) {
JsonObject res = new JsonObject();
params.entrySet().forEach(it-> res.addProperty(it.getKey(),it.getValue()));
return res;
}

JsonArray array = new JsonArray();
Annotation[][] anns = method.getMethod().getParameterAnnotations();
Arrays.stream(anns).forEach(it -> {
if (it.length > 0) {
RequestParam param = getRequestParam(it);
String name = param.value();
if (!params.containsKey(name)) {
array.add("");
// throw new DoceanException("Missing parameter:" + name);
} else {
array.add(params.get(name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
public class HttpMethodUtils {

public static void addMvcContext(HttpRequestMethod method, JsonArray array) {
if (paramIsMvcContext(method)) {
array.add(new JsonObject());
}
}

public static boolean paramIsMvcContext(HttpRequestMethod method) {
Class<?>[] types = method.getMethod().getParameterTypes();
if (types.length > 0 && types[0] == MvcContext.class) {
array.add(new JsonObject());
return true;
}
return false;
}


Expand Down

0 comments on commit f8defd8

Please sign in to comment.