diff --git a/src/main/java/org/redkale/net/Request.java b/src/main/java/org/redkale/net/Request.java index 02232768a..80fab985c 100644 --- a/src/main/java/org/redkale/net/Request.java +++ b/src/main/java/org/redkale/net/Request.java @@ -7,7 +7,6 @@ package org.redkale.net; import java.io.*; import java.lang.annotation.Annotation; -import java.lang.reflect.Array; import java.nio.ByteBuffer; import java.util.*; import java.util.function.Function; @@ -176,6 +175,12 @@ public abstract class Request { return createTime; } + /** + * 获取当前操作Method上的注解集合 + * + * @return Annotation[] + */ + @ConvertDisabled public Annotation[] getAnnotations() { if (annotations == null) { return new Annotation[0]; @@ -183,6 +188,13 @@ public abstract class Request { return Arrays.copyOfRange(annotations, 0, annotations.length); } + /** + * 获取当前操作Method上的注解 + * + * @param 注解泛型 + * @param annotationClass 注解类型 + * @return Annotation + */ public T getAnnotation(Class annotationClass) { if (annotations != null) { for (Annotation ann : annotations) { @@ -194,9 +206,16 @@ public abstract class Request { return null; } + /** + * 获取当前操作Method上的注解集合 + * + * @param 注解泛型 + * @param annotationClass 注解类型 + * @return Annotation[] + */ public T[] getAnnotationsByType(Class annotationClass) { if (annotations == null) { - return (T[]) Array.newInstance(annotationClass, 0); + return Creator.newArray(annotationClass, 0); } else { List list = new ArrayList<>(); for (Annotation ann : annotations) { diff --git a/src/main/java/org/redkale/net/http/HttpRequest.java b/src/main/java/org/redkale/net/http/HttpRequest.java index 3c664c89c..29e597848 100644 --- a/src/main/java/org/redkale/net/http/HttpRequest.java +++ b/src/main/java/org/redkale/net/http/HttpRequest.java @@ -167,8 +167,6 @@ public class HttpRequest extends Request { protected int actionid; - protected Annotation[] annotations; - protected String remoteAddr; protected String locale; @@ -354,7 +352,7 @@ public class HttpRequest extends Request { return 1; } hbytes.put(buffer, remainHalf); - this.headerLength = this.headerBytes.length(); + this.headerLength = hbytes.length(); this.headerHalfLen = this.headerLength; this.headerParsed = false; } else if (context.lazyHeader && getmethod) { // 非GET必须要读header,会有Content-Length @@ -390,8 +388,8 @@ public class HttpRequest extends Request { buffer.clear(); return rs; } - this.headerParsed = true; this.headerHalfLen = this.headerLength; + this.headerParsed = true; } if (this.contentType != null && this.contentType.contains("boundary=")) { this.boundary = true; @@ -1313,7 +1311,6 @@ public class HttpRequest extends Request { this.boundary = false; this.moduleid = 0; this.actionid = 0; - this.annotations = null; this.remoteAddr = null; this.params.clear(); this.bodyBytes.clear(); @@ -1667,67 +1664,6 @@ public class HttpRequest extends Request { return this.actionid; } - /** - * 获取当前操作Method上的注解集合 - * - * @return Annotation[] - */ - @Override - @ConvertDisabled - public Annotation[] getAnnotations() { - if (this.annotations == null) { - return new Annotation[0]; - } - Annotation[] newanns = new Annotation[this.annotations.length]; - System.arraycopy(this.annotations, 0, newanns, 0, newanns.length); - return newanns; - } - - /** - * 获取当前操作Method上的注解 - * - * @param 注解泛型 - * @param annotationClass 注解类型 - * @return Annotation - */ - @Override - public T getAnnotation(Class annotationClass) { - if (this.annotations == null) { - return null; - } - for (Annotation ann : this.annotations) { - if (ann.getClass() == annotationClass) { - return (T) ann; - } - } - return null; - } - - /** - * 获取当前操作Method上的注解集合 - * - * @param 注解泛型 - * @param annotationClass 注解类型 - * @return Annotation[] - */ - @Override - public T[] getAnnotationsByType(Class annotationClass) { - if (this.annotations == null) { - return Creator.newArray(annotationClass, 0); - } - T[] news = Creator.newArray(annotationClass, this.annotations.length); - int index = 0; - for (Annotation ann : this.annotations) { - if (ann.getClass() == annotationClass) { - news[index++] = (T) ann; - } - } - if (index < 1) { - return Creator.newArray(annotationClass, 0); - } - return Arrays.copyOf(news, index); - } - /** * 获取客户端地址IP * diff --git a/src/main/java/org/redkale/net/http/HttpServlet.java b/src/main/java/org/redkale/net/http/HttpServlet.java index cdde2fbeb..a96045ec6 100644 --- a/src/main/java/org/redkale/net/http/HttpServlet.java +++ b/src/main/java/org/redkale/net/http/HttpServlet.java @@ -124,7 +124,7 @@ public class HttpServlet extends Servlet } request.moduleid = entry.moduleid; request.actionid = entry.actionid; - request.annotations = entry.annotations; + request.setAnnotations(entry.annotations); if (entry.auth) { response.thenEvent(authSuccessServlet); authenticate(request, response); @@ -143,7 +143,7 @@ public class HttpServlet extends Servlet request.actionEntry = entry; request.moduleid = entry.moduleid; request.actionid = entry.actionid; - request.annotations = entry.annotations; + request.setAnnotations(entry.annotations); if (entry.auth) { response.thenEvent(authSuccessServlet); authenticate(request, response);