This commit is contained in:
@@ -195,6 +195,29 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加Cookie值
|
||||
*
|
||||
* @param cookies cookie
|
||||
*
|
||||
* @return HttpResponse
|
||||
*/
|
||||
public HttpResponse addCookie(Collection<HttpCookie> cookies) {
|
||||
if (cookies == null || cookies.isEmpty()) return this;
|
||||
if (this.cookies == null) {
|
||||
this.cookies = cookies.toArray(new HttpCookie[cookies.size()]);
|
||||
} else {
|
||||
HttpCookie[] news = new HttpCookie[this.cookies.length + cookies.size()];
|
||||
System.arraycopy(this.cookies, 0, news, 0, this.cookies.length);
|
||||
int i = this.cookies.length;
|
||||
for (HttpCookie cookie : cookies) {
|
||||
news[i++] = cookie;
|
||||
}
|
||||
this.cookies = news;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象以JSON格式输出
|
||||
*
|
||||
@@ -690,6 +713,21 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加Header值
|
||||
*
|
||||
* @param map header值
|
||||
*
|
||||
* @return HttpResponse
|
||||
*/
|
||||
public HttpResponse addHeader(Map<String, ?> map) {
|
||||
if (map == null || map.isEmpty()) return this;
|
||||
for (Map.Entry<String, ?> en : map.entrySet()) {
|
||||
this.header.addValue(en.getKey(), String.valueOf(en.getValue()));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置状态码
|
||||
*
|
||||
|
||||
@@ -73,6 +73,7 @@ public final class Rest {
|
||||
final String webServletDesc = Type.getDescriptor(WebServlet.class);
|
||||
final String httpRequestDesc = Type.getDescriptor(HttpRequest.class);
|
||||
final String httpResponseDesc = Type.getDescriptor(HttpResponse.class);
|
||||
final String restoutputDesc = Type.getDescriptor(RestOutput.class);
|
||||
final String attrDesc = Type.getDescriptor(org.redkale.util.Attribute.class);
|
||||
final String authDesc = Type.getDescriptor(HttpBaseServlet.AuthIgnore.class);
|
||||
final String actionDesc = Type.getDescriptor(HttpBaseServlet.WebAction.class);
|
||||
@@ -810,6 +811,22 @@ public final class Rest {
|
||||
}
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (!sncp && RestOutput.class.isAssignableFrom(returnType)) {
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "finishJson", "(Lorg/redkale/net/http/HttpResponse;" + restoutputDesc + ")V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "finishJsResult", "(Lorg/redkale/net/http/HttpResponse;Ljava/lang/String;" + restoutputDesc + ")V", false);
|
||||
}
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (Number.class.isAssignableFrom(returnType) || CharSequence.class.isAssignableFrom(returnType)) { //returnType == String.class 必须放在前面
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
|
||||
@@ -19,6 +19,22 @@ public abstract class RestHttpServlet<T> extends HttpBaseServlet {
|
||||
|
||||
protected abstract T currentUser(HttpRequest req) throws IOException;
|
||||
|
||||
protected void finishJson(final HttpResponse response, RestOutput output) throws IOException {
|
||||
if (output != null) {
|
||||
response.addHeader(output.getHeaders());
|
||||
response.addCookie(output.getCookies());
|
||||
}
|
||||
response.finishJson(output == null ? null : output.getResult());
|
||||
}
|
||||
|
||||
protected void finishJsResult(final HttpResponse response, final String var, RestOutput output) throws IOException {
|
||||
if (output != null) {
|
||||
response.addHeader(output.getHeaders());
|
||||
response.addCookie(output.getCookies());
|
||||
}
|
||||
response.finishJsResult(var, output == null ? null : output.getResult());
|
||||
}
|
||||
|
||||
Attribute[] _paramAttrs; // 为null表示无DynCall处理,index=0固定为null, 其他为参数标记的DynCall回调方法
|
||||
|
||||
protected void _callParameter(final HttpResponse response, final Object... params) {
|
||||
|
||||
Reference in New Issue
Block a user