解决WebSocket注入多Service问题
This commit is contained in:
@@ -487,8 +487,8 @@ public final class Rest {
|
||||
sb1.append(Type.getDescriptor(field.getType()));
|
||||
sb2.append(Utility.getTypeDescriptor(field.getGenericType()));
|
||||
}
|
||||
final String resourceDesc = sb1.toString();
|
||||
final String resourceGenericDesc = sb1.length() == sb2.length() ? null : sb2.toString();
|
||||
final String serviceParamsDesc = sb1.toString();
|
||||
final String serviceParamsGenericDesc = sb1.equals(sb2) ? null : sb2.toString();
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
|
||||
@@ -628,7 +628,7 @@ public final class Rest {
|
||||
"_redkale_resource_" + i,
|
||||
Type.getDescriptor(resourcesFields.get(i).getType()));
|
||||
}
|
||||
mv.visitMethodInsn(INVOKESPECIAL, newDynWebSokcetFullName, "<init>", "(" + resourceDesc + ")V", false);
|
||||
mv.visitMethodInsn(INVOKESPECIAL, newDynWebSokcetFullName, "<init>", "(" + serviceParamsDesc + ")V", false);
|
||||
mv.visitInsn(ARETURN);
|
||||
mv.visitMaxs(2 + resourcesFields.size(), 1);
|
||||
mv.visitEnd();
|
||||
@@ -793,8 +793,7 @@ public final class Rest {
|
||||
mv.visitInsn(ARETURN);
|
||||
Label label2 = new Label();
|
||||
mv.visitLabel(label2);
|
||||
mv.visitLocalVariable(
|
||||
"this", "L" + newDynSuperMessageFullName + ";", null, label0, label2, 0);
|
||||
mv.visitLocalVariable("this", "L" + newDynSuperMessageFullName + ";", null, label0, label2, 0);
|
||||
mv.visitLocalVariable("name", "Ljava/lang/String;", null, label0, label2, 1);
|
||||
mv.visitMaxs(2, 2);
|
||||
mv.visitEnd();
|
||||
@@ -981,9 +980,9 @@ public final class Rest {
|
||||
cw2.visitInnerClass(
|
||||
newDynWebSokcetFullName, newDynName, newDynWebSokcetSimpleName, ACC_PUBLIC + ACC_STATIC);
|
||||
{
|
||||
String resSignature = resourceGenericDesc == null ? null : ("(" + resourceGenericDesc + ")V");
|
||||
String resSignature = serviceParamsGenericDesc == null ? null : ("(" + serviceParamsGenericDesc + ")V");
|
||||
mv = new MethodDebugVisitor(
|
||||
cw2.visitMethod(ACC_PUBLIC, "<init>", "(" + resourceDesc + ")V", resSignature, null));
|
||||
cw2.visitMethod(ACC_PUBLIC, "<init>", "(" + serviceParamsDesc + ")V", resSignature, null));
|
||||
Label sublabel0 = new Label();
|
||||
mv.visitLabel(sublabel0);
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
@@ -999,8 +998,14 @@ public final class Rest {
|
||||
Label sublabel2 = new Label();
|
||||
mv.visitLabel(sublabel2);
|
||||
mv.visitLocalVariable("this", "L" + newDynWebSokcetFullName + ";", null, sublabel0, sublabel2, 0);
|
||||
if (!resourceDesc.isEmpty()) {
|
||||
mv.visitLocalVariable("service", resourceDesc, resSignature, sublabel0, sublabel2, 1);
|
||||
for (int i = 0; i < resourcesFields.size(); i++) {
|
||||
Field field = resourcesFields.get(i);
|
||||
String fieldDesc = Type.getDescriptor(field.getType());
|
||||
String fieldSignature = Utility.getTypeDescriptor(field.getGenericType());
|
||||
if (fieldDesc.equals(fieldSignature)) {
|
||||
fieldSignature = null;
|
||||
}
|
||||
mv.visitLocalVariable(field.getName(), fieldDesc, fieldSignature, sublabel0, sublabel2, 1 + i);
|
||||
}
|
||||
mv.visitMaxs(2, 1 + resourcesFields.size());
|
||||
mv.visitEnd();
|
||||
|
||||
@@ -116,8 +116,7 @@ public final class CacheMemorySource extends AbstractCacheSource {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "{type=memory, name='" + resourceName() + "', hash="
|
||||
+ Objects.hashCode(this) + "}";
|
||||
return getClass().getSimpleName() + "_" + Objects.hash(this) + "{type=memory, name='" + resourceName() + "'}";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -71,7 +71,7 @@ public class DataMemorySource extends AbstractDataSource {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getClass().getSimpleName() + "{type=memory, name='" + resourceName() + "'}";
|
||||
return getClass().getSimpleName() + "_" + Objects.hash(this) + "{type=memory, name='" + resourceName() + "'}";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -13,6 +13,7 @@ import org.redkale.annotation.Resource;
|
||||
import org.redkale.convert.ConvertDisabled;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.test.rest.UserService;
|
||||
import org.redkale.test.ws.ChatMessage;
|
||||
import org.redkale.test.ws.ChatService;
|
||||
import org.redkale.test.ws.ChatWebSocket;
|
||||
@@ -24,6 +25,9 @@ public final class _DyncChatWebSocketServlet extends WebSocketServlet {
|
||||
@Resource
|
||||
private ChatService _redkale_resource_0;
|
||||
|
||||
@Resource
|
||||
private UserService _redkale_resource_1;
|
||||
|
||||
public static Map<String, Annotation[]> _redkale_annotations;
|
||||
|
||||
public _DyncChatWebSocketServlet() {
|
||||
@@ -33,7 +37,7 @@ public final class _DyncChatWebSocketServlet extends WebSocketServlet {
|
||||
|
||||
@Override
|
||||
protected <G extends Serializable, T> WebSocket<G, T> createWebSocket() {
|
||||
return (WebSocket) new _DyncChatWebSocket(_redkale_resource_0);
|
||||
return (WebSocket) new _DyncChatWebSocket(_redkale_resource_0, _redkale_resource_1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -43,9 +47,10 @@ public final class _DyncChatWebSocketServlet extends WebSocketServlet {
|
||||
|
||||
public static class _DyncChatWebSocket extends ChatWebSocket {
|
||||
|
||||
public _DyncChatWebSocket(ChatService service) {
|
||||
public _DyncChatWebSocket(ChatService service, UserService userService) {
|
||||
super();
|
||||
this.service = service;
|
||||
this.userService = userService;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user