This commit is contained in:
@@ -361,6 +361,17 @@ public final class Rest {
|
|||||||
if (ptype != byte[].class && ptype != File.class && ptype != File[].class) throw new RuntimeException("@RestUploadFile must on byte[] or File or File[] Parameter in " + method);
|
if (ptype != byte[].class && ptype != File.class && ptype != File[].class) throw new RuntimeException("@RestUploadFile must on byte[] or File or File[] Parameter in " + method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RestURI annuri = param.getAnnotation(RestURI.class);
|
||||||
|
if (annuri != null) {
|
||||||
|
if (annhead != null) throw new RuntimeException("@RestURI and @RestHeader cannot on the same Parameter in " + method);
|
||||||
|
if (anncookie != null) throw new RuntimeException("@RestURI and @RestCookie cannot on the same Parameter in " + method);
|
||||||
|
if (annsid != null) throw new RuntimeException("@RestURI and @RestSessionid cannot on the same Parameter in " + method);
|
||||||
|
if (annaddr != null) throw new RuntimeException("@RestURI and @RestAddress cannot on the same Parameter in " + method);
|
||||||
|
if (annbody != null) throw new RuntimeException("@RestURI and @RestBody cannot on the same Parameter in " + method);
|
||||||
|
if (annfile != null) throw new RuntimeException("@RestURI and @RestUploadFile cannot on the same Parameter in " + method);
|
||||||
|
if (ptype != String.class) throw new RuntimeException("@RestURI must on String Parameter in " + method);
|
||||||
|
}
|
||||||
|
|
||||||
RestParam annpara = param.getAnnotation(RestParam.class);
|
RestParam annpara = param.getAnnotation(RestParam.class);
|
||||||
if (annpara != null) radix = annpara.radix();
|
if (annpara != null) radix = annpara.radix();
|
||||||
if (annpara != null) comment = annpara.comment();
|
if (annpara != null) comment = annpara.comment();
|
||||||
@@ -381,7 +392,7 @@ public final class Rest {
|
|||||||
&& (entry.name.startsWith("find") || entry.name.startsWith("delete")) && params.length == 1) {
|
&& (entry.name.startsWith("find") || entry.name.startsWith("delete")) && params.length == 1) {
|
||||||
if (ptype.isPrimitive() || ptype == String.class) n = "#";
|
if (ptype.isPrimitive() || ptype == String.class) n = "#";
|
||||||
}
|
}
|
||||||
paramlist.add(new Object[]{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annhead, anncookie, annbody, annfile, param.getParameterizedType()});
|
paramlist.add(new Object[]{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annhead, anncookie, annbody, annfile, annuri, param.getParameterizedType()});
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object> mappingMap = new LinkedHashMap<>();
|
Map<String, Object> mappingMap = new LinkedHashMap<>();
|
||||||
@@ -425,7 +436,7 @@ public final class Rest {
|
|||||||
av0 = mv.visitAnnotation(webparamsDesc, true);
|
av0 = mv.visitAnnotation(webparamsDesc, true);
|
||||||
AnnotationVisitor av1 = av0.visitArray("value");
|
AnnotationVisitor av1 = av0.visitArray("value");
|
||||||
//设置 WebParam
|
//设置 WebParam
|
||||||
for (Object[] ps : paramlist) { //{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annhead, anncookie, annbody, annfile, pgentype}
|
for (Object[] ps : paramlist) { //{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annhead, anncookie, annbody, annfile, annuri, pgentype}
|
||||||
final boolean ishead = ((RestHeader) ps[9]) != null; //是否取getHeader 而不是 getParameter
|
final boolean ishead = ((RestHeader) ps[9]) != null; //是否取getHeader 而不是 getParameter
|
||||||
final boolean iscookie = ((RestCookie) ps[10]) != null; //是否取getCookie
|
final boolean iscookie = ((RestCookie) ps[10]) != null; //是否取getCookie
|
||||||
|
|
||||||
@@ -460,7 +471,8 @@ public final class Rest {
|
|||||||
RestCookie anncookie = (RestCookie) ps[10];
|
RestCookie anncookie = (RestCookie) ps[10];
|
||||||
RestBody annbody = (RestBody) ps[11];
|
RestBody annbody = (RestBody) ps[11];
|
||||||
RestUploadFile annfile = (RestUploadFile) ps[12];
|
RestUploadFile annfile = (RestUploadFile) ps[12];
|
||||||
java.lang.reflect.Type pgentype = (java.lang.reflect.Type) ps[13];
|
RestURI annuri = (RestURI) ps[13];
|
||||||
|
java.lang.reflect.Type pgentype = (java.lang.reflect.Type) ps[14];
|
||||||
|
|
||||||
final boolean ishead = annhead != null; //是否取getHeader 而不是 getParameter
|
final boolean ishead = annhead != null; //是否取getHeader 而不是 getParameter
|
||||||
final boolean iscookie = anncookie != null; //是否取getCookie
|
final boolean iscookie = anncookie != null; //是否取getCookie
|
||||||
@@ -549,6 +561,11 @@ public final class Rest {
|
|||||||
mv.visitVarInsn(ASTORE, maxLocals);
|
mv.visitVarInsn(ASTORE, maxLocals);
|
||||||
varInsns.add(new int[]{ALOAD, maxLocals});
|
varInsns.add(new int[]{ALOAD, maxLocals});
|
||||||
}
|
}
|
||||||
|
} else if (annuri != null) { //HttpRequest.getRequestURI
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequestURI", "()Ljava/lang/String;", false);
|
||||||
|
mv.visitVarInsn(ASTORE, maxLocals);
|
||||||
|
varInsns.add(new int[]{ALOAD, maxLocals});
|
||||||
} else if ("#".equals(pname)) { //从request.getRequstURI 中取参数
|
} else if ("#".equals(pname)) { //从request.getRequstURI 中取参数
|
||||||
if (ptype == boolean.class) {
|
if (ptype == boolean.class) {
|
||||||
mv.visitVarInsn(ALOAD, 1);
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
@@ -827,7 +844,8 @@ public final class Rest {
|
|||||||
RestAddress ra = field.getAnnotation(RestAddress.class);
|
RestAddress ra = field.getAnnotation(RestAddress.class);
|
||||||
RestBody rb = field.getAnnotation(RestBody.class);
|
RestBody rb = field.getAnnotation(RestBody.class);
|
||||||
RestUploadFile ru = field.getAnnotation(RestUploadFile.class);
|
RestUploadFile ru = field.getAnnotation(RestUploadFile.class);
|
||||||
if (rh == null && rc == null && ra == null && rb == null && rs == null && ru == null) continue;
|
RestURI ri = field.getAnnotation(RestURI.class);
|
||||||
|
if (rh == null && rc == null && ra == null && rb == null && rs == null && ru == null && ri == null) continue;
|
||||||
if (rh != null && field.getType() != String.class) throw new RuntimeException("@RestHeader must on String Field in " + field);
|
if (rh != null && field.getType() != String.class) throw new RuntimeException("@RestHeader must on String Field in " + field);
|
||||||
if (rc != null && field.getType() != String.class) throw new RuntimeException("@RestCookie must on String Field in " + field);
|
if (rc != null && field.getType() != String.class) throw new RuntimeException("@RestCookie must on String Field in " + field);
|
||||||
if (rs != null && field.getType() != String.class) throw new RuntimeException("@RestSessionid must on String Field in " + field);
|
if (rs != null && field.getType() != String.class) throw new RuntimeException("@RestSessionid must on String Field in " + field);
|
||||||
@@ -840,6 +858,7 @@ public final class Rest {
|
|||||||
if (hasupload) throw new RuntimeException("@RestUploadFile repeat on Field(" + field + ") in " + method);
|
if (hasupload) throw new RuntimeException("@RestUploadFile repeat on Field(" + field + ") in " + method);
|
||||||
hasupload = true;
|
hasupload = true;
|
||||||
}
|
}
|
||||||
|
if (ri != null && field.getType() != String.class) throw new RuntimeException("@RestURI must on String Field in " + field);
|
||||||
org.redkale.util.Attribute attr = org.redkale.util.Attribute.create(loop, field);
|
org.redkale.util.Attribute attr = org.redkale.util.Attribute.create(loop, field);
|
||||||
String attrFieldName;
|
String attrFieldName;
|
||||||
String restname = "";
|
String restname = "";
|
||||||
@@ -873,6 +892,9 @@ public final class Rest {
|
|||||||
} else if (ru != null && field.getType() == File[].class) {
|
} else if (ru != null && field.getType() == File[].class) {
|
||||||
attrFieldName = "_redkale_attr_uploadfiles_" + restAttributes.size();
|
attrFieldName = "_redkale_attr_uploadfiles_" + restAttributes.size();
|
||||||
//restname = "";
|
//restname = "";
|
||||||
|
} else if (ri != null && field.getType() == String.class) {
|
||||||
|
attrFieldName = "_redkale_attr_uri_" + restAttributes.size();
|
||||||
|
//restname = "";
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -905,6 +927,8 @@ public final class Rest {
|
|||||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getSessionid", "(Z)Ljava/lang/String;", false);
|
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getSessionid", "(Z)Ljava/lang/String;", false);
|
||||||
} else if (en.getKey().contains("_address_")) {
|
} else if (en.getKey().contains("_address_")) {
|
||||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRemoteAddr", "()Ljava/lang/String;", false);
|
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRemoteAddr", "()Ljava/lang/String;", false);
|
||||||
|
} else if (en.getKey().contains("_uri_")) {
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequestURI", "()Ljava/lang/String;", false);
|
||||||
} else if (en.getKey().contains("_bodystring_")) {
|
} else if (en.getKey().contains("_bodystring_")) {
|
||||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getBodyUTF8", "()Ljava/lang/String;", false);
|
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getBodyUTF8", "()Ljava/lang/String;", false);
|
||||||
} else if (en.getKey().contains("_bodybytes_")) {
|
} else if (en.getKey().contains("_bodybytes_")) {
|
||||||
|
|||||||
26
src/org/redkale/net/http/RestURI.java
Normal file
26
src/org/redkale/net/http/RestURI.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
|
* To change this template file, choose Tools | Templates
|
||||||
|
* and open the template in the editor.
|
||||||
|
*/
|
||||||
|
package org.redkale.net.http;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
import static java.lang.annotation.ElementType.*;
|
||||||
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 只能注解于Service类的方法的String参数或参数内的String字段
|
||||||
|
* <p>
|
||||||
|
* 用于获取HTTP请求URL HttpRequest.getRequestURI
|
||||||
|
* <p>
|
||||||
|
* 详情见: https://redkale.org
|
||||||
|
*
|
||||||
|
* @author zhangjx
|
||||||
|
*/
|
||||||
|
@Inherited
|
||||||
|
@Documented
|
||||||
|
@Target({PARAMETER, FIELD})
|
||||||
|
@Retention(RUNTIME)
|
||||||
|
public @interface RestURI {
|
||||||
|
}
|
||||||
@@ -38,6 +38,9 @@ public class HelloEntity {
|
|||||||
@RestAddress
|
@RestAddress
|
||||||
private String clientaddr;
|
private String clientaddr;
|
||||||
|
|
||||||
|
@RestURI
|
||||||
|
private String uri;
|
||||||
|
|
||||||
public HelloEntity() {
|
public HelloEntity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,6 +137,14 @@ public class HelloEntity {
|
|||||||
this.uploads = uploads;
|
this.uploads = uploads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUri() {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUri(String uri) {
|
||||||
|
this.uri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return JsonFactory.root().getConvert().convertTo(this);
|
return JsonFactory.root().getConvert().convertTo(this);
|
||||||
|
|||||||
Reference in New Issue
Block a user