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