This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
package org.redkale.test.http;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.*;
|
||||
import java.nio.charset.*;
|
||||
import java.util.*;
|
||||
@@ -18,24 +19,6 @@ import org.redkale.net.http.*;
|
||||
*/
|
||||
public interface HttpRequestDesc {
|
||||
|
||||
//获取请求方法 GET、POST等
|
||||
public String getMethod();
|
||||
|
||||
//获取协议名 http、https、ws、wss等
|
||||
public String getProtocol();
|
||||
|
||||
//获取Host的Header值
|
||||
public String getHost();
|
||||
|
||||
//获取请求内容的长度, 为-1表示内容长度不确定
|
||||
public long getContentLength();
|
||||
|
||||
//获取Content-Type的header值
|
||||
public String getContentType();
|
||||
|
||||
//获取Connection的Header值
|
||||
public String getConnection();
|
||||
|
||||
//获取客户端地址IP
|
||||
public SocketAddress getRemoteAddress();
|
||||
|
||||
@@ -67,11 +50,29 @@ public interface HttpRequestDesc {
|
||||
//获取所有Cookie对象
|
||||
public java.net.HttpCookie[] getCookies();
|
||||
|
||||
//获取Cookie值
|
||||
public String getCookie(String name);
|
||||
|
||||
//获取Cookie值, 没有返回默认值
|
||||
public String getCookie(String name, String defaultValue);
|
||||
|
||||
//获取Cookie值
|
||||
public String getCookie(String name);
|
||||
//获取协议名 http、https、ws、wss等
|
||||
public String getProtocol();
|
||||
|
||||
//获取请求方法 GET、POST等
|
||||
public String getMethod();
|
||||
|
||||
//获取Content-Type的header值
|
||||
public String getContentType();
|
||||
|
||||
//获取请求内容的长度, 为-1表示内容长度不确定
|
||||
public long getContentLength();
|
||||
|
||||
//获取Connection的Header值
|
||||
public String getConnection();
|
||||
|
||||
//获取Host的Header值
|
||||
public String getHost();
|
||||
|
||||
//获取请求的URL
|
||||
public String getRequestURI();
|
||||
@@ -82,20 +83,9 @@ public interface HttpRequestDesc {
|
||||
//从prefix之后截取getRequestURI再对"/"进行分隔
|
||||
public String[] getRequstURIPaths(String prefix);
|
||||
|
||||
//获取请求URL分段中含prefix段的long值
|
||||
// 例如请求URL /pipes/record/query/time:1453104341363/id:40
|
||||
// 获取time参数: long time = request.getRequstURIPath("time:", 0L);
|
||||
public long getRequstURIPath(String prefix, long defaultValue);
|
||||
|
||||
//获取请求URL分段中含prefix段的int值
|
||||
// 例如请求URL /pipes/record/query/offset:2/limit:50
|
||||
// 获取page参数: int offset = request.getRequstURIPath("offset:", 1);
|
||||
// 获取size参数: int limit = request.getRequstURIPath("limit:", 20);
|
||||
public int getRequstURIPath(String prefix, int defaultValue);
|
||||
|
||||
//获取请求URL分段中含prefix段的值
|
||||
//例如请求URL /pipes/record/query/name:hello
|
||||
//获取name参数: String name = request.getRequstURIPath("name:", "none");
|
||||
// 获取请求URL分段中含prefix段的值
|
||||
// 例如请求URL /pipes/record/query/name:hello
|
||||
// 获取name参数: String name = request.getRequstURIPath("name:", "none");
|
||||
public String getRequstURIPath(String prefix, String defaultValue);
|
||||
|
||||
// 获取请求URL分段中含prefix段的short值
|
||||
@@ -103,6 +93,43 @@ public interface HttpRequestDesc {
|
||||
// 获取type参数: short type = request.getRequstURIPath("type:", (short)0);
|
||||
public short getRequstURIPath(String prefix, short defaultValue);
|
||||
|
||||
// 获取请求URL分段中含prefix段的short值
|
||||
// 例如请求URL /pipes/record/query/type:a
|
||||
// 获取type参数: short type = request.getRequstURIPath(16, "type:", (short)0); type = 10
|
||||
public short getRequstURIPath(int radix, String prefix, short defvalue);
|
||||
|
||||
// 获取请求URL分段中含prefix段的int值
|
||||
// 例如请求URL /pipes/record/query/offset:2/limit:50
|
||||
// 获取offset参数: int offset = request.getRequstURIPath("offset:", 1);
|
||||
// 获取limit参数: int limit = request.getRequstURIPath("limit:", 20);
|
||||
public int getRequstURIPath(String prefix, int defaultValue);
|
||||
|
||||
// 获取请求URL分段中含prefix段的int值
|
||||
// 例如请求URL /pipes/record/query/offset:2/limit:10
|
||||
// 获取offset参数: int offset = request.getRequstURIPath("offset:", 1);
|
||||
// 获取limit参数: int limit = request.getRequstURIPath(16, "limit:", 20); // limit = 16
|
||||
public int getRequstURIPath(int radix, String prefix, int defaultValue);
|
||||
|
||||
// 获取请求URL分段中含prefix段的float值
|
||||
// 例如请求URL /pipes/record/query/point:40.0
|
||||
// 获取time参数: float point = request.getRequstURIPath("point:", 0.0f);
|
||||
public float getRequstURIPath(String prefix, float defvalue);
|
||||
|
||||
// 获取请求URL分段中含prefix段的long值
|
||||
// 例如请求URL /pipes/record/query/time:1453104341363/id:40
|
||||
// 获取time参数: long time = request.getRequstURIPath("time:", 0L);
|
||||
public long getRequstURIPath(String prefix, long defaultValue);
|
||||
|
||||
// 获取请求URL分段中含prefix段的long值
|
||||
// 例如请求URL /pipes/record/query/time:1453104341363/id:40
|
||||
// 获取time参数: long time = request.getRequstURIPath("time:", 0L);
|
||||
public long getRequstURIPath(int radix, String prefix, long defvalue);
|
||||
|
||||
// 获取请求URL分段中含prefix段的double值 <br>
|
||||
// 例如请求URL /pipes/record/query/point:40.0 <br>
|
||||
// 获取time参数: double point = request.getRequstURIPath("point:", 0.0);
|
||||
public double getRequstURIPath(String prefix, double defvalue);
|
||||
|
||||
//获取所有的header名
|
||||
public String[] getHeaderNames();
|
||||
|
||||
@@ -113,10 +140,10 @@ public interface HttpRequestDesc {
|
||||
public String getHeader(String name, String defaultValue);
|
||||
|
||||
//获取指定的header的json值
|
||||
public <T> T getJsonHeader(JsonConvert convert, Class<T> clazz, String name);
|
||||
public <T> T getJsonHeader(Type type, String name);
|
||||
|
||||
//获取指定的header的json值
|
||||
public <T> T getJsonHeader(Class<T> clazz, String name);
|
||||
public <T> T getJsonHeader(JsonConvert convert, Type type, String name);
|
||||
|
||||
//获取指定的header的boolean值, 没有返回默认boolean值
|
||||
public boolean getBooleanHeader(String name, boolean defaultValue);
|
||||
@@ -124,15 +151,30 @@ public interface HttpRequestDesc {
|
||||
// 获取指定的header的short值, 没有返回默认short值
|
||||
public short getShortHeader(String name, short defaultValue);
|
||||
|
||||
// 获取指定的header的short值, 没有返回默认short值
|
||||
public short getShortHeader(int radix, String name, short defaultValue);
|
||||
|
||||
// 获取指定的header的short值, 没有返回默认short值
|
||||
public short getShortHeader(String name, int defaultValue);
|
||||
|
||||
// 获取指定的header的short值, 没有返回默认short值
|
||||
public short getShortHeader(int radix, String name, int defaultValue);
|
||||
|
||||
//获取指定的header的int值, 没有返回默认int值
|
||||
public int getIntHeader(String name, int defaultValue);
|
||||
|
||||
// 获取指定的header的float值, 没有返回默认float值
|
||||
public float getFloatHeader(String name, float defaultValue);
|
||||
//获取指定的header的int值, 没有返回默认int值
|
||||
public int getIntHeader(int radix, String name, int defaultValue);
|
||||
|
||||
// 获取指定的header的long值, 没有返回默认long值
|
||||
public long getLongHeader(String name, long defaultValue);
|
||||
|
||||
// 获取指定的header的long值, 没有返回默认long值
|
||||
public long getLongHeader(int radix, String name, long defaultValue);
|
||||
|
||||
// 获取指定的header的float值, 没有返回默认float值
|
||||
public float getFloatHeader(String name, float defaultValue);
|
||||
|
||||
//获取指定的header的double值, 没有返回默认double值
|
||||
public double getDoubleHeader(String name, double defaultValue);
|
||||
|
||||
@@ -146,10 +188,10 @@ public interface HttpRequestDesc {
|
||||
public String getParameter(String name, String defaultValue);
|
||||
|
||||
//获取指定的参数json值
|
||||
public <T> T getJsonParameter(JsonConvert convert, Class<T> clazz, String name);
|
||||
public <T> T getJsonParameter(Type type, String name);
|
||||
|
||||
//获取指定的参数json值
|
||||
public <T> T getJsonParameter(Class<T> clazz, String name);
|
||||
public <T> T getJsonParameter(JsonConvert convert, Type type, String name);
|
||||
|
||||
//获取指定的参数boolean值, 没有返回默认boolean值
|
||||
public boolean getBooleanParameter(String name, boolean defaultValue);
|
||||
@@ -157,18 +199,47 @@ public interface HttpRequestDesc {
|
||||
//获取指定的参数short值, 没有返回默认short值
|
||||
public short getShortParameter(String name, short defaultValue);
|
||||
|
||||
//获取指定的参数short值, 没有返回默认short值
|
||||
public short getShortParameter(int radix, String name, short defaultValue);
|
||||
|
||||
//获取指定的参数short值, 没有返回默认short值
|
||||
public short getShortParameter(int radix, String name, int defaultValue);
|
||||
|
||||
//获取指定的参数int值, 没有返回默认int值
|
||||
public int getIntParameter(String name, int defaultValue);
|
||||
|
||||
//获取指定的参数float值, 没有返回默认float值
|
||||
public float getFloatParameter(String name, float defaultValue);
|
||||
//获取指定的参数int值, 没有返回默认int值
|
||||
public int getIntParameter(int radix, String name, int defaultValue);
|
||||
|
||||
//获取指定的参数long值, 没有返回默认long值
|
||||
public long getLongParameter(String name, long defaultValue);
|
||||
|
||||
//获取指定的参数long值, 没有返回默认long值
|
||||
public long getLongParameter(int radix, String name, long defaultValue);
|
||||
|
||||
//获取指定的参数float值, 没有返回默认float值
|
||||
public float getFloatParameter(String name, float defaultValue);
|
||||
|
||||
//获取指定的参数double值, 没有返回默认double值
|
||||
public double getDoubleParameter(String name, double defaultValue);
|
||||
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", false, 0);
|
||||
public org.redkale.source.Flipper getFlipper();
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", needcreate, 0);
|
||||
public org.redkale.source.Flipper getFlipper(boolean needcreate);
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", false, maxLimit);
|
||||
public org.redkale.source.Flipper getFlipper(int maxLimit);
|
||||
|
||||
//获取翻页对象 同 getFlipper("flipper", needcreate, maxLimit)
|
||||
public org.redkale.source.Flipper getFlipper(boolean needcreate, int maxLimit);
|
||||
|
||||
//获取翻页对象 http://redkale.org/pipes/records/list/offset:0/limit:20/sort:createtime%20ASC
|
||||
//http://redkale.org/pipes/records/list?flipper={'offset':0,'limit':20, 'sort':'createtime ASC'}
|
||||
//以上两种接口都可以获取到翻页对象
|
||||
public org.redkale.source.Flipper getFlipper(String name, boolean needcreate, int maxLimit);
|
||||
|
||||
//获取HTTP上下文对象
|
||||
public HttpContext getContext();
|
||||
|
||||
|
||||
@@ -10,7 +10,10 @@ import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
import java.nio.*;
|
||||
import java.nio.channels.*;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.net.http.*;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -18,6 +21,12 @@ import org.redkale.convert.json.*;
|
||||
*/
|
||||
public interface HttpResponseDesc {
|
||||
|
||||
//增加Cookie值
|
||||
public HttpResponse addCookie(HttpCookie... cookies);
|
||||
|
||||
//增加Cookie值
|
||||
public HttpResponse addCookie(Collection<HttpCookie> cookies);
|
||||
|
||||
//设置状态码
|
||||
public void setStatus(int status);
|
||||
|
||||
@@ -28,26 +37,26 @@ public interface HttpResponseDesc {
|
||||
public String getContentType();
|
||||
|
||||
//设置 ContentType
|
||||
public void setContentType(String contentType);
|
||||
public HttpResponse setContentType(String contentType);
|
||||
|
||||
//获取内容长度
|
||||
public long getContentLength();
|
||||
|
||||
//设置内容长度
|
||||
public void setContentLength(long contentLength);
|
||||
public HttpResponse setContentLength(long contentLength);
|
||||
|
||||
//设置Header值
|
||||
public void setHeader(String name, Object value);
|
||||
public HttpResponse setHeader(String name, Object value);
|
||||
|
||||
//添加Header值
|
||||
public void addHeader(String name, Object value);
|
||||
public HttpResponse addHeader(String name, Object value);
|
||||
|
||||
//添加Header值
|
||||
public HttpResponse addHeader(Map<String, ?> map);
|
||||
|
||||
//跳过header的输出
|
||||
//通常应用场景是,调用者的输出内容里已经包含了HTTP的响应头信息,因此需要调用此方法避免重复输出HTTP响应头信息。
|
||||
public void skipHeader();
|
||||
|
||||
//增加Cookie值
|
||||
public void addCookie(HttpCookie... cookies);
|
||||
public HttpResponse skipHeader();
|
||||
|
||||
//异步输出指定内容
|
||||
public <A> void sendBody(ByteBuffer buffer, A attachment, CompletionHandler<Integer, A> handler);
|
||||
@@ -73,6 +82,18 @@ public interface HttpResponseDesc {
|
||||
//将对象以JSON格式输出
|
||||
public void finishJson(final Object... objs);
|
||||
|
||||
//将RetResult对象以JSON格式输出
|
||||
public void finishJson(final org.redkale.service.RetResult ret);
|
||||
|
||||
//将RetResult对象以JSON格式输出
|
||||
public void finishJson(final JsonConvert convert, final org.redkale.service.RetResult ret);
|
||||
|
||||
//将对象以JavaScript格式输出
|
||||
public void finishJsResult(String var, Object result);
|
||||
|
||||
//将对象以JavaScript格式输出
|
||||
public void finishJsResult(JsonConvert jsonConvert, String var, Object result);
|
||||
|
||||
//将指定字符串以响应结果输出
|
||||
public void finish(String obj);
|
||||
|
||||
@@ -102,4 +123,10 @@ public interface HttpResponseDesc {
|
||||
//将指定文件按响应结果输出
|
||||
public void finish(File file) throws IOException;
|
||||
|
||||
//将文件按指定文件名输出
|
||||
public void finish(final String filename, File file) throws IOException;
|
||||
|
||||
//HttpResponse回收时回调的监听方法
|
||||
public void setRecycleListener(BiConsumer<HttpRequest, HttpResponse> recycleListener);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user