修复Rest将Future<HttpResult<byte[]>>类型用finishJsonFuture格式输出

This commit is contained in:
redkale
2023-04-06 11:07:09 +08:00
parent 5746449cfb
commit 91d7f51678
3 changed files with 10 additions and 10 deletions

View File

@@ -3165,7 +3165,8 @@ public final class Rest {
} else if (CompletionStage.class.isAssignableFrom(returnType)) { } else if (CompletionStage.class.isAssignableFrom(returnType)) {
mv.visitVarInsn(ASTORE, maxLocals); mv.visitVarInsn(ASTORE, maxLocals);
mv.visitVarInsn(ALOAD, 2); //response mv.visitVarInsn(ALOAD, 2); //response
if (returnGenericNoFutureType == HttpScope.class) { Class returnNoFutureType = TypeToken.typeToClassOrElse(returnGenericNoFutureType, Object.class);
if (returnNoFutureType == HttpScope.class) {
if (rcs != null && rcs.length > 0) { if (rcs != null && rcs.length > 0) {
mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, newDynName, REST_CONVERT_FIELD_PREFIX + restConverts.size(), convertDesc); mv.visitFieldInsn(GETFIELD, newDynName, REST_CONVERT_FIELD_PREFIX + restConverts.size(), convertDesc);
@@ -3175,10 +3176,10 @@ public final class Rest {
mv.visitVarInsn(ALOAD, maxLocals); mv.visitVarInsn(ALOAD, maxLocals);
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishScopeFuture", "(" + stageDesc + ")V", false); mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishScopeFuture", "(" + stageDesc + ")V", false);
} }
} else if (returnGenericNoFutureType != byte[].class } else if (returnNoFutureType != byte[].class
&& returnGenericNoFutureType != RetResult.class && returnNoFutureType != RetResult.class
&& returnGenericNoFutureType != HttpResult.class && returnNoFutureType != HttpResult.class
&& returnGenericNoFutureType != File.class && returnNoFutureType != File.class
&& !((returnGenericNoFutureType instanceof Class) && (((Class) returnGenericNoFutureType).isPrimitive() || CharSequence.class.isAssignableFrom((Class) returnGenericNoFutureType)))) { && !((returnGenericNoFutureType instanceof Class) && (((Class) returnGenericNoFutureType).isPrimitive() || CharSequence.class.isAssignableFrom((Class) returnGenericNoFutureType)))) {
if (rcs != null && rcs.length > 0) { if (rcs != null && rcs.length > 0) {
mv.visitVarInsn(ALOAD, 0); mv.visitVarInsn(ALOAD, 0);

View File

@@ -79,12 +79,12 @@ public abstract class Sncp {
} }
//key: actionid //key: actionid
public static LinkedHashMap<Uint128, Method> loadMethodActions(final Class resourceServiceType) { public static LinkedHashMap<Uint128, Method> loadMethodActions(final Class serviceTypeOrImplClass) {
final List<Method> list = new ArrayList<>(); final List<Method> list = new ArrayList<>();
final List<Method> multis = new ArrayList<>(); final List<Method> multis = new ArrayList<>();
final Map<Uint128, Method> actionids = new LinkedHashMap<>(); final Map<Uint128, Method> actionids = new LinkedHashMap<>();
RedkaleClassLoader.putReflectionPublicMethods(resourceServiceType.getName()); RedkaleClassLoader.putReflectionPublicMethods(serviceTypeOrImplClass.getName());
for (final java.lang.reflect.Method method : resourceServiceType.getMethods()) { for (final java.lang.reflect.Method method : serviceTypeOrImplClass.getMethods()) {
if (method.isSynthetic()) { if (method.isSynthetic()) {
continue; continue;
} }
@@ -116,7 +116,7 @@ public abstract class Sncp {
Method old = actionids.get(actionid); Method old = actionids.get(actionid);
if (old != null) { if (old != null) {
if (old.getDeclaringClass().equals(method.getDeclaringClass())) { if (old.getDeclaringClass().equals(method.getDeclaringClass())) {
throw new SncpException(resourceServiceType.getName() + " have one more same action(Method=" + method + ", " + old + ", actionid=" + actionid + ")"); throw new SncpException(serviceTypeOrImplClass.getName() + " have one more same action(Method=" + method + ", " + old + ", actionid=" + actionid + ")");
} }
continue; continue;
} }

View File

@@ -56,7 +56,6 @@ public class SncpServlet extends Servlet<SncpContext, SncpRequest, SncpResponse>
this.serviceid = Sncp.serviceid(resourceName, resourceType); this.serviceid = Sncp.serviceid(resourceName, resourceType);
Class serviceImplClass = Sncp.getServiceType(service); Class serviceImplClass = Sncp.getServiceType(service);
RedkaleClassLoader.putReflectionPublicMethods(serviceImplClass.getName());
for (Map.Entry<Uint128, Method> en : Sncp.loadMethodActions(serviceImplClass).entrySet()) { for (Map.Entry<Uint128, Method> en : Sncp.loadMethodActions(serviceImplClass).entrySet()) {
SncpActionServlet action; SncpActionServlet action;
try { try {