WebSocketParam增加getAnnotations系列方法
This commit is contained in:
@@ -458,6 +458,12 @@ public final class Rest {
|
|||||||
av0.visitEnd();
|
av0.visitEnd();
|
||||||
fv.visitEnd();
|
fv.visitEnd();
|
||||||
}
|
}
|
||||||
|
{//_redkale_annotations
|
||||||
|
fv = cw2.visitField(ACC_PUBLIC + ACC_STATIC, "_redkale_annotations", "[Ljava/lang/annotation/Annotation;", null, null);
|
||||||
|
av0 = fv.visitAnnotation(convertDisabledDesc, true);
|
||||||
|
av0.visitEnd();
|
||||||
|
fv.visitEnd();
|
||||||
|
}
|
||||||
{ //空构造函数
|
{ //空构造函数
|
||||||
mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
|
mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null));
|
||||||
mv.visitVarInsn(ALOAD, 0);
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
@@ -504,6 +510,25 @@ public final class Rest {
|
|||||||
mv.visitMaxs(2, 2);
|
mv.visitMaxs(2, 2);
|
||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "getAnnotations", "()[Ljava/lang/annotation/Annotation;", null, null));
|
||||||
|
mv.visitFieldInsn(GETSTATIC, newDynMessageFullName + endfix, "_redkale_annotations", "[Ljava/lang/annotation/Annotation;");
|
||||||
|
Label l1 = new Label();
|
||||||
|
mv.visitJumpInsn(IFNONNULL, l1);
|
||||||
|
mv.visitInsn(ICONST_0);
|
||||||
|
mv.visitTypeInsn(ANEWARRAY, "java/lang/annotation/Annotation");
|
||||||
|
mv.visitInsn(ARETURN);
|
||||||
|
mv.visitLabel(l1);
|
||||||
|
mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
|
||||||
|
mv.visitFieldInsn(GETSTATIC, newDynMessageFullName + endfix, "_redkale_annotations", "[Ljava/lang/annotation/Annotation;");
|
||||||
|
mv.visitFieldInsn(GETSTATIC, newDynMessageFullName + endfix, "_redkale_annotations", "[Ljava/lang/annotation/Annotation;");
|
||||||
|
mv.visitInsn(ARRAYLENGTH);
|
||||||
|
mv.visitMethodInsn(INVOKESTATIC, "java/util/Arrays", "copyOf", "([Ljava/lang/Object;I)[Ljava/lang/Object;", false);
|
||||||
|
mv.visitTypeInsn(CHECKCAST, "[Ljava/lang/annotation/Annotation;");
|
||||||
|
mv.visitInsn(ARETURN);
|
||||||
|
mv.visitMaxs(2, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
{ //execute
|
{ //execute
|
||||||
mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "execute", "(L" + newDynWebSokcetFullName + ";)V", null, null));
|
mv = new MethodDebugVisitor(cw2.visitMethod(ACC_PUBLIC, "execute", "(L" + newDynWebSokcetFullName + ";)V", null, null));
|
||||||
mv.visitVarInsn(ALOAD, 0);
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
@@ -543,7 +568,11 @@ public final class Rest {
|
|||||||
mv.visitEnd();
|
mv.visitEnd();
|
||||||
}
|
}
|
||||||
cw2.visitEnd();
|
cw2.visitEnd();
|
||||||
newLoader.loadClass((newDynMessageFullName + endfix).replace('/', '.'), cw2.toByteArray());
|
try {
|
||||||
|
newLoader.loadClass((newDynMessageFullName + endfix).replace('/', '.'), cw2.toByteArray()).getField("_redkale_annotations").set(null, method.getAnnotations());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{ //_DynXXXWebSocketMessage class
|
{ //_DynXXXWebSocketMessage class
|
||||||
|
|||||||
@@ -5,6 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.net.http;
|
package org.redkale.net.http;
|
||||||
|
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 供WebSocket.preOnMessage 方法获取RestWebSocket里OnMessage方法的参数 <br>
|
* 供WebSocket.preOnMessage 方法获取RestWebSocket里OnMessage方法的参数 <br>
|
||||||
@@ -18,4 +22,27 @@ public interface WebSocketParam {
|
|||||||
public <T> T getValue(String name);
|
public <T> T getValue(String name);
|
||||||
|
|
||||||
public String[] getNames();
|
public String[] getNames();
|
||||||
|
|
||||||
|
public Annotation[] getAnnotations();
|
||||||
|
|
||||||
|
default <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
|
||||||
|
for (Annotation ann : getAnnotations()) {
|
||||||
|
if (ann.getClass() == annotationClass) return (T) ann;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
default <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
|
||||||
|
Annotation[] annotations = getAnnotations();
|
||||||
|
if (annotations == null) return (T[]) Array.newInstance(annotationClass, 0);
|
||||||
|
T[] news = (T[]) Array.newInstance(annotationClass, annotations.length);
|
||||||
|
int index = 0;
|
||||||
|
for (Annotation ann : annotations) {
|
||||||
|
if (ann.getClass() == annotationClass) {
|
||||||
|
news[index++] = (T) ann;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (index < 1) return (T[]) Array.newInstance(annotationClass, 0);
|
||||||
|
return Arrays.copyOf(news, index);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
package org.redkale.test.wsdync;
|
package org.redkale.test.wsdync;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.util.*;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import org.redkale.convert.ConvertDisabled;
|
import org.redkale.convert.ConvertDisabled;
|
||||||
@@ -70,6 +71,9 @@ public final class _DyncChatWebSocketServlet extends WebSocketServlet {
|
|||||||
@ConvertDisabled
|
@ConvertDisabled
|
||||||
public _DyncChatWebSocket _redkale_websocket;
|
public _DyncChatWebSocket _redkale_websocket;
|
||||||
|
|
||||||
|
@ConvertDisabled
|
||||||
|
public static Annotation[] _redkale_annotations;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getNames() {
|
public String[] getNames() {
|
||||||
return new String[]{"message", "extmap"};
|
return new String[]{"message", "extmap"};
|
||||||
@@ -82,6 +86,12 @@ public final class _DyncChatWebSocketServlet extends WebSocketServlet {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Annotation[] getAnnotations() {
|
||||||
|
if (_redkale_annotations == null) return new Annotation[0];
|
||||||
|
return Arrays.copyOf(_redkale_annotations, _redkale_annotations.length);
|
||||||
|
}
|
||||||
|
|
||||||
public void execute(_DyncChatWebSocket websocket) {
|
public void execute(_DyncChatWebSocket websocket) {
|
||||||
this._redkale_websocket = websocket;
|
this._redkale_websocket = websocket;
|
||||||
websocket.preOnMessage("sendmessage", this, this);
|
websocket.preOnMessage("sendmessage", this, this);
|
||||||
@@ -105,6 +115,9 @@ public final class _DyncChatWebSocketServlet extends WebSocketServlet {
|
|||||||
@ConvertDisabled
|
@ConvertDisabled
|
||||||
public _DyncChatWebSocket _redkale_websocket;
|
public _DyncChatWebSocket _redkale_websocket;
|
||||||
|
|
||||||
|
@ConvertDisabled
|
||||||
|
public static Annotation[] _redkale_annotations;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getNames() {
|
public String[] getNames() {
|
||||||
return new String[]{"roomid"};
|
return new String[]{"roomid"};
|
||||||
@@ -116,6 +129,12 @@ public final class _DyncChatWebSocketServlet extends WebSocketServlet {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Annotation[] getAnnotations() {
|
||||||
|
if (_redkale_annotations == null) return new Annotation[0];
|
||||||
|
return Arrays.copyOf(_redkale_annotations, _redkale_annotations.length);
|
||||||
|
}
|
||||||
|
|
||||||
public void execute(_DyncChatWebSocket websocket) {
|
public void execute(_DyncChatWebSocket websocket) {
|
||||||
this._redkale_websocket = websocket;
|
this._redkale_websocket = websocket;
|
||||||
websocket.preOnMessage("joinroom", this, this);
|
websocket.preOnMessage("joinroom", this, this);
|
||||||
|
|||||||
Reference in New Issue
Block a user