RestURI更名RestPath
This commit is contained in:
@@ -319,7 +319,7 @@
|
||||
<cache limit="0M" lengthmax="1M" watch="false"/>
|
||||
<!--
|
||||
支持类似nginx中的rewrite, 目前只支持静态资源对静态资源的跳转。
|
||||
type: 匹配的类型, 目前只支持location(匹配requestURI), 默认: location
|
||||
type: 匹配的类型, 目前只支持location(匹配path), 默认: location
|
||||
match: 匹配的正则表达式
|
||||
forward: 需跳转后的资源链接
|
||||
例如下面例子是将/xxx-yyy.html的页面全部跳转到/xxx.html
|
||||
|
||||
@@ -79,7 +79,7 @@ public class HttpClusterRpcClient extends HttpRpcClient {
|
||||
private CompletableFuture<HttpResult<byte[]>> httpAsync(boolean produce, Serializable userid, HttpSimpleRequest req) {
|
||||
req.setTraceid(Traces.computeIfAbsent(req.getTraceid(), Traces.currentTraceid()));
|
||||
final WorkThread workThread = WorkThread.currentWorkThread();
|
||||
String module = req.getRequestURI();
|
||||
String module = req.getPath();
|
||||
module = module.substring(1); //去掉/
|
||||
module = module.substring(0, module.indexOf('/'));
|
||||
HttpHeaders headers = req.getHeaders();
|
||||
@@ -127,10 +127,10 @@ public class HttpClusterRpcClient extends HttpRpcClient {
|
||||
if (req.getBody() != null && req.getBody().length > 0) {
|
||||
String paramstr = req.getParametersToString();
|
||||
if (paramstr != null) {
|
||||
if (req.getRequestURI().indexOf('?') > 0) {
|
||||
req.setRequestURI(req.getRequestURI() + "&" + paramstr);
|
||||
if (req.getPath().indexOf('?') > 0) {
|
||||
req.setPath(req.getPath() + "&" + paramstr);
|
||||
} else {
|
||||
req.setRequestURI(req.getRequestURI() + "?" + paramstr);
|
||||
req.setPath(req.getPath() + "?" + paramstr);
|
||||
}
|
||||
}
|
||||
clientBody = req.getBody();
|
||||
@@ -143,19 +143,18 @@ public class HttpClusterRpcClient extends HttpRpcClient {
|
||||
if (logger.isLoggable(Level.FINEST)) {
|
||||
logger.log(Level.FINEST, "httpAsync: module=" + localModule + ", resname=" + resname + ", enter forEachCollectionFuture");
|
||||
}
|
||||
return forEachCollectionFuture(workThread, logger.isLoggable(Level.FINEST), userid, req,
|
||||
(req.getPath() != null && !req.getPath().isEmpty() ? req.getPath() : "") + req.getRequestURI(),
|
||||
return forEachCollectionFuture(logger.isLoggable(Level.FINEST), req, req.requestPath(),
|
||||
clientHeaders, clientBody, addrs.iterator());
|
||||
});
|
||||
}
|
||||
|
||||
private CompletableFuture<HttpResult<byte[]>> forEachCollectionFuture(final WorkThread workThread, boolean finest, Serializable userid,
|
||||
HttpSimpleRequest req, String requesturi, final HttpHeaders clientHeaders, byte[] clientBody, Iterator<InetSocketAddress> it) {
|
||||
private CompletableFuture<HttpResult<byte[]>> forEachCollectionFuture(boolean finest, HttpSimpleRequest req,
|
||||
String requestPath, final HttpHeaders clientHeaders, byte[] clientBody, Iterator<InetSocketAddress> it) {
|
||||
if (!it.hasNext()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
InetSocketAddress addr = it.next();
|
||||
String url = "http://" + addr.getHostString() + ":" + addr.getPort() + requesturi;
|
||||
String url = "http://" + addr.getHostString() + ":" + addr.getPort() + requestPath;
|
||||
if (finest) {
|
||||
if (clientBody != null) {
|
||||
logger.log(Level.FINEST, "forEachCollectionFuture: url: " + url + ", body: " + new String(clientBody, StandardCharsets.UTF_8) + ", headers: " + clientHeaders);
|
||||
@@ -186,75 +185,4 @@ public class HttpClusterRpcClient extends HttpRpcClient {
|
||||
});
|
||||
}
|
||||
|
||||
//
|
||||
// private CompletableFuture<HttpResult<byte[]>> httpAsync(Serializable userid, HttpSimpleRequest req) {
|
||||
// final boolean finest = logger.isLoggable(Level.FINEST);
|
||||
// String module = req.getRequestURI();
|
||||
// module = module.substring(1); //去掉/
|
||||
// module = module.substring(0, module.indexOf('/'));
|
||||
// Map<String, String> headers = req.getHeaders();
|
||||
// String resname = headers == null ? "" : headers.getOrDefault(Rest.REST_HEADER_RESNAME, "");
|
||||
// return clusterAgent.queryHttpAddress("http", module, resname).thenCompose(addrs -> {
|
||||
// if (addrs == null || addrs.isEmpty()) return new HttpResult().status(404).toAnyFuture();
|
||||
// java.net.http.HttpRequest.Builder builder = java.net.http.HttpRequest.newBuilder().timeout(Duration.ofMillis(30000));
|
||||
// if (req.isRpc()) builder.header(Rest.REST_HEADER_RPC_NAME, "true");
|
||||
// if (req.isFrombody()) builder.header(Rest.REST_HEADER_PARAM_FROM_BODY, "true");
|
||||
// if (req.getReqConvertType() != null) builder.header(Rest.REST_HEADER_REQ_CONVERT, req.getReqConvertType().toString());
|
||||
// if (req.getRespConvertType() != null) builder.header(Rest.REST_HEADER_RESP_CONVERT, req.getRespConvertType().toString());
|
||||
// if (userid != 0) builder.header(Rest.REST_HEADER_CURRUSERID, "" + userid);
|
||||
// if (headers != null) headers.forEach((n, v) -> {
|
||||
// if (!DISALLOWED_HEADERS_SET.contains(n.toLowerCase())) builder.header(n, v);
|
||||
// });
|
||||
// builder.header("Content-Type", "x-www-form-urlencoded");
|
||||
// if (req.getBody() != null && req.getBody().length > 0) {
|
||||
// String paramstr = req.getParametersToString();
|
||||
// if (paramstr != null) {
|
||||
// if (req.getRequestURI().indexOf('?') > 0) {
|
||||
// req.setRequestURI(req.getRequestURI() + "&" + paramstr);
|
||||
// } else {
|
||||
// req.setRequestURI(req.getRequestURI() + "?" + paramstr);
|
||||
// }
|
||||
// }
|
||||
// builder.POST(java.net.http.HttpRequest.BodyPublishers.ofByteArray(req.getBody()));
|
||||
// } else {
|
||||
// String paramstr = req.getParametersToString();
|
||||
// if (paramstr != null) builder.POST(java.net.http.HttpRequest.BodyPublishers.ofString(paramstr));
|
||||
// }
|
||||
// return forEachCollectionFuture(finest, userid, req, (req.getPath() != null && !req.getPath().isEmpty() ? req.getPath() : "") + req.getRequestURI(), builder, addrs.iterator());
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// private CompletableFuture<HttpResult<byte[]>> forEachCollectionFuture(boolean finest, Serializable userid, HttpSimpleRequest req, String requesturi, java.net.http.HttpRequest.Builder builder, Iterator<InetSocketAddress> it) {
|
||||
// if (!it.hasNext()) return CompletableFuture.completedFuture(null);
|
||||
// InetSocketAddress addr = it.next();
|
||||
// String url = "http://" + addr.getHostString() + ":" + addr.getPort() + requesturi;
|
||||
// return httpClient.sendAsync(builder.copy().uri(URI.create(url)).build(), java.net.http.HttpResponse.BodyHandlers.ofByteArray()).thenCompose(resp -> {
|
||||
// if (resp.statusCode() != 200) return forEachCollectionFuture(finest, userid, req, requesturi, builder, it);
|
||||
// HttpResult rs = new HttpResult();
|
||||
// java.net.http.HttpHeaders hs = resp.headers();
|
||||
// if (hs != null) {
|
||||
// Map<String, List<String>> hm = hs.map();
|
||||
// if (hm != null) {
|
||||
// for (Map.Entry<String, List<String>> en : hm.entrySet()) {
|
||||
// if ("date".equals(en.getKey()) || "content-type".equals(en.getKey())
|
||||
// || "server".equals(en.getKey()) || "connection".equals(en.getKey())) continue;
|
||||
// List<String> val = en.getValue();
|
||||
// if (val != null && val.size() == 1) {
|
||||
// rs.header(en.getKey(), val.get(0));
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// rs.setResult(resp.body());
|
||||
// if (finest) {
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// Map<String, String> params = req.getParams();
|
||||
// if (params != null && !params.isEmpty()) {
|
||||
// params.forEach((n, v) -> sb.append('&').append(n).append('=').append(v));
|
||||
// }
|
||||
// logger.log(Level.FINEST, url + "?userid=" + userid + sb + ", result = " + new String(resp.body(), StandardCharsets.UTF_8));
|
||||
// }
|
||||
// return CompletableFuture.completedFuture(rs);
|
||||
// });
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class HttpLocalRpcClient extends HttpRpcClient {
|
||||
}
|
||||
|
||||
public HttpServlet findHttpServlet(HttpSimpleRequest request) {
|
||||
return dispatcherServlet().findServletByTopic(generateHttpReqTopic(request, request.getPath()));
|
||||
return dispatcherServlet().findServletByTopic(generateHttpReqTopic(request, request.getContextPath()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -108,7 +108,7 @@ public class HttpLocalRpcClient extends HttpRpcClient {
|
||||
request.setTraceid(Traces.currentTraceid());
|
||||
}
|
||||
CompletableFuture future = new CompletableFuture();
|
||||
String topic = generateHttpReqTopic(request, request.getPath());
|
||||
String topic = generateHttpReqTopic(request, request.getContextPath());
|
||||
HttpServlet servlet = findHttpServlet(topic);
|
||||
if (servlet == null) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
|
||||
@@ -105,7 +105,7 @@ public abstract class HttpRpcClient implements ClusterRpcClient<HttpSimpleReques
|
||||
}
|
||||
|
||||
public String generateHttpReqTopic(HttpSimpleRequest request, String path) {
|
||||
String module = request.getRequestURI();
|
||||
String module = request.getPath();
|
||||
if (path != null && !path.isEmpty() && module.startsWith(path)) {
|
||||
module = module.substring(path.length());
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ public class HttpMessageRequest extends HttpRequest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpMessageRequest setRequestURI(String uri) {
|
||||
this.requestURI = uri;
|
||||
public HttpMessageRequest setPath(String path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -171,7 +171,7 @@ public class HttpMessageResponse extends HttpResponse {
|
||||
@Override
|
||||
public void finish(int status, String msg) {
|
||||
if (status > 400) {
|
||||
messageClient.logger.log(Level.WARNING, "HttpMessageResponse.finish status: " + status + ", uri: " + this.request.getRequestURI() + ", message: " + this.message);
|
||||
messageClient.logger.log(Level.WARNING, "HttpMessageResponse.finish status: " + status + ", uri: " + this.request.getPath() + ", message: " + this.message);
|
||||
} else if (messageClient.logger.isLoggable(Level.FINEST)) {
|
||||
messageClient.logger.log(Level.FINEST, "HttpMessageResponse.finish status: " + status);
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ public class HttpSimpleRequestCoder implements MessageCoder<HttpSimpleRequest> {
|
||||
@Override
|
||||
public byte[] encode(HttpSimpleRequest data) {
|
||||
byte[] traceid = MessageCoder.getBytes(data.getTraceid());//short-string
|
||||
byte[] requestURI = MessageCoder.getBytes(data.getRequestURI()); //long-string
|
||||
byte[] path = MessageCoder.getBytes(data.getPath()); //short-string
|
||||
byte[] path = MessageCoder.getBytes(data.getPath()); //long-string
|
||||
byte[] contextPath = MessageCoder.getBytes(data.getContextPath()); //short-string
|
||||
byte[] method = MessageCoder.getBytes(data.getMethod());//short-string
|
||||
byte[] remoteAddr = MessageCoder.getBytes(data.getRemoteAddr());//short-string
|
||||
byte[] sessionid = MessageCoder.getBytes(data.getSessionid());//short-string
|
||||
@@ -56,8 +56,8 @@ public class HttpSimpleRequestCoder implements MessageCoder<HttpSimpleRequest> {
|
||||
+ 4 //reqConvertType
|
||||
+ 4 //respConvertType
|
||||
+ 2 + traceid.length
|
||||
+ 4 + requestURI.length
|
||||
+ 2 + path.length
|
||||
+ 4 + path.length
|
||||
+ 2 + contextPath.length
|
||||
+ 2 + method.length
|
||||
+ 2 + remoteAddr.length
|
||||
+ 2 + sessionid.length
|
||||
@@ -80,18 +80,18 @@ public class HttpSimpleRequestCoder implements MessageCoder<HttpSimpleRequest> {
|
||||
buffer.put(traceid);
|
||||
}
|
||||
|
||||
if (data.getRequestURI() == null) {
|
||||
if (data.getPath() == null) {
|
||||
buffer.putInt(-1);
|
||||
} else {
|
||||
buffer.putInt(requestURI.length);
|
||||
buffer.put(requestURI);
|
||||
buffer.putInt(path.length);
|
||||
buffer.put(path);
|
||||
}
|
||||
|
||||
if (data.getPath() == null) {
|
||||
if (data.getContextPath() == null) {
|
||||
buffer.putShort((short) -1);
|
||||
} else {
|
||||
buffer.putShort((short) path.length);
|
||||
buffer.put(path);
|
||||
buffer.putShort((short) contextPath.length);
|
||||
buffer.put(contextPath);
|
||||
}
|
||||
|
||||
if (data.getMethod() == null) {
|
||||
@@ -158,8 +158,8 @@ public class HttpSimpleRequestCoder implements MessageCoder<HttpSimpleRequest> {
|
||||
req.setRespConvertType(ConvertType.find(respformat));
|
||||
}
|
||||
req.setTraceid(MessageCoder.getSmallString(buffer));
|
||||
req.setRequestURI(MessageCoder.getBigString(buffer));
|
||||
req.setPath(MessageCoder.getSmallString(buffer));
|
||||
req.setPath(MessageCoder.getBigString(buffer));
|
||||
req.setContextPath(MessageCoder.getSmallString(buffer));
|
||||
req.setMethod(MessageCoder.getSmallString(buffer));
|
||||
req.setRemoteAddr(MessageCoder.getSmallString(buffer));
|
||||
req.setSessionid(MessageCoder.getSmallString(buffer));
|
||||
|
||||
@@ -310,7 +310,7 @@ public class HttpDispatcherServlet extends DispatcherServlet<String, HttpContext
|
||||
@Override
|
||||
public void execute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
try {
|
||||
final String uri = request.getRequestURI();
|
||||
final String uri = request.getPath();
|
||||
HttpServlet servlet;
|
||||
if (response.isAutoOptions() && HttpRequest.METHOD_OPTIONS.equals(request.getMethod())) {
|
||||
response.finish(200, null);
|
||||
@@ -446,7 +446,6 @@ public class HttpDispatcherServlet extends DispatcherServlet<String, HttpContext
|
||||
}
|
||||
} else if (mappingPath != null && !mappingPath.isEmpty()) {
|
||||
if (servlet._actionmap != null && servlet._actionmap.containsKey(mappingPath)) {
|
||||
//context.addRequestURINode(mappingpath);
|
||||
putMapping(mappingPath, new HttpServlet.HttpActionServlet(servlet._actionmap.get(mappingPath), servlet, mappingPath));
|
||||
} else {
|
||||
putMapping(mappingPath, servlet);
|
||||
|
||||
@@ -26,8 +26,8 @@ public abstract class HttpFilter extends Filter<HttpContext, HttpRequest, HttpRe
|
||||
request.setMethod(method);
|
||||
}
|
||||
|
||||
protected void setRequestURI(HttpRequest request, String requestURI) {
|
||||
request.setRequestURI(requestURI);
|
||||
protected void setPath(HttpRequest request, String path) {
|
||||
request.setPath(path);
|
||||
}
|
||||
|
||||
protected void setRemoteAddr(HttpRequest request, String remoteAddr) {
|
||||
|
||||
@@ -24,11 +24,11 @@ import static org.redkale.util.Utility.isEmpty;
|
||||
/**
|
||||
* Http请求包 与javax.servlet.http.HttpServletRequest 基本类似。 <br>
|
||||
* 同时提供json的解析接口: public Object getJsonParameter(Type type, String name) <br>
|
||||
* Redkale提倡带简单的参数的GET请求采用类似REST风格, 因此提供了 getRequstURIPath 系列接口。 <br>
|
||||
* Redkale提倡带简单的参数的GET请求采用类似REST风格, 因此提供了 getPathParam 系列接口。 <br>
|
||||
* 例如简单的翻页查询 <br>
|
||||
* /pipes/user/query/offset:0/limit:20 <br>
|
||||
* 获取页号: int offset = request.getRequstURIPath("offset:", 0); <br>
|
||||
* 获取行数: int limit = request.getRequstURIPath("limit:", 10); <br>
|
||||
* 获取页号: int offset = request.getPathParam("offset:", 0); <br>
|
||||
* 获取行数: int limit = request.getPathParam("limit:", 10); <br>
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
@@ -132,7 +132,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
|
||||
protected String protocol;
|
||||
|
||||
protected String requestURI;
|
||||
protected String path;
|
||||
|
||||
protected byte[] queryBytes;
|
||||
|
||||
@@ -152,9 +152,9 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
|
||||
protected String locale;
|
||||
|
||||
private String lastRequestURIString;
|
||||
private String lastPathString;
|
||||
|
||||
private byte[] lastRequestURIBytes;
|
||||
private byte[] lastPathBytes;
|
||||
|
||||
private final ByteArray array;
|
||||
|
||||
@@ -224,9 +224,9 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
this.remoteAddr = req.getRemoteAddr();
|
||||
this.locale = req.getLocale();
|
||||
if (needPath) {
|
||||
this.requestURI = (req.getPath() == null || req.getPath().isEmpty()) ? req.getRequestURI() : (req.getPath() + req.getRequestURI());
|
||||
this.path = req.requestPath();
|
||||
} else {
|
||||
this.requestURI = req.getRequestURI();
|
||||
this.path = req.getPath();
|
||||
}
|
||||
this.method = req.getMethod();
|
||||
if (req.getSessionid() != null && !req.getSessionid().isEmpty()) {
|
||||
@@ -236,7 +236,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpSimpleRequest createSimpleRequest(String prefix) {
|
||||
public HttpSimpleRequest createSimpleRequest(String prefixPath) {
|
||||
HttpSimpleRequest req = new HttpSimpleRequest();
|
||||
req.setBody(array.length() == 0 ? null : array.getBytes());
|
||||
if (!getHeaders().isEmpty()) {
|
||||
@@ -253,13 +253,13 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
req.setRemoteAddr(getRemoteAddr());
|
||||
req.setLocale(getLocale());
|
||||
req.setContentType(getContentType());
|
||||
req.setPath(prefix);
|
||||
req.setContextPath(prefixPath);
|
||||
req.setMethod(this.method);
|
||||
String uri = this.requestURI;
|
||||
if (prefix != null && !prefix.isEmpty() && uri.startsWith(prefix)) {
|
||||
uri = uri.substring(prefix.length());
|
||||
String path0 = this.path;
|
||||
if (prefixPath != null && !prefixPath.isEmpty() && path0.startsWith(prefixPath)) {
|
||||
path0 = path0.substring(prefixPath.length());
|
||||
}
|
||||
req.setRequestURI(uri);
|
||||
req.setPath(path0);
|
||||
req.setSessionid(getSessionid(false));
|
||||
req.setRpc(this.rpc);
|
||||
req.setTraceid(this.traceid);
|
||||
@@ -565,7 +565,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
}
|
||||
|
||||
//读uri
|
||||
if (this.requestURI == null) {
|
||||
if (this.path == null) {
|
||||
int qst = -1;//?的位置
|
||||
boolean decodeable = false;
|
||||
boolean latin1 = true;
|
||||
@@ -589,11 +589,11 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
}
|
||||
size = bytes.length();
|
||||
if (qst > 0) { //带?参数
|
||||
this.requestURI = decodeable ? toDecodeString(bytes, 0, qst, charset) : context.loadUriPath(bytes, qst, latin1, charset);// bytes.toString(latin1, 0, qst, charset);
|
||||
this.path = decodeable ? toDecodeString(bytes, 0, qst, charset) : context.loadUriPath(bytes, qst, latin1, charset);// bytes.toString(latin1, 0, qst, charset);
|
||||
int qlen = size - qst - 1;
|
||||
this.queryBytes = bytes.getBytes(qst + 1, qlen);
|
||||
this.lastRequestURIString = null;
|
||||
this.lastRequestURIBytes = null;
|
||||
this.lastPathString = null;
|
||||
this.lastPathBytes = null;
|
||||
try {
|
||||
addParameter(bytes, false, qst + 1, qlen);
|
||||
} catch (Exception e) {
|
||||
@@ -601,22 +601,22 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
}
|
||||
} else {
|
||||
if (decodeable) { //需要转义
|
||||
this.requestURI = toDecodeString(bytes, 0, bytes.length(), charset);
|
||||
this.lastRequestURIString = null;
|
||||
this.lastRequestURIBytes = null;
|
||||
this.path = toDecodeString(bytes, 0, bytes.length(), charset);
|
||||
this.lastPathString = null;
|
||||
this.lastPathBytes = null;
|
||||
} else if (context.lazyHeaders) {
|
||||
byte[] lastURIBytes = lastRequestURIBytes;
|
||||
byte[] lastURIBytes = lastPathBytes;
|
||||
if (lastURIBytes != null && lastURIBytes.length == size && bytes.deepEquals(lastURIBytes)) {
|
||||
this.requestURI = this.lastRequestURIString;
|
||||
this.path = this.lastPathString;
|
||||
} else {
|
||||
this.requestURI = context.loadUriPath(bytes, latin1, charset);// bytes.toString(latin1, charset);
|
||||
this.lastRequestURIString = this.requestURI;
|
||||
this.lastRequestURIBytes = bytes.getBytes();
|
||||
this.path = context.loadUriPath(bytes, latin1, charset);// bytes.toString(latin1, charset);
|
||||
this.lastPathString = this.path;
|
||||
this.lastPathBytes = bytes.getBytes();
|
||||
}
|
||||
} else {
|
||||
this.requestURI = context.loadUriPath(bytes, latin1, charset); //bytes.toString(latin1, charset);
|
||||
this.lastRequestURIString = null;
|
||||
this.lastRequestURIBytes = null;
|
||||
this.path = context.loadUriPath(bytes, latin1, charset); //bytes.toString(latin1, charset);
|
||||
this.lastPathString = null;
|
||||
this.lastPathBytes = null;
|
||||
}
|
||||
this.queryBytes = EMPTY_BYTES;
|
||||
}
|
||||
@@ -984,7 +984,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
this.method = null;
|
||||
this.getmethod = false;
|
||||
this.protocol = null;
|
||||
this.requestURI = null;
|
||||
this.path = null;
|
||||
this.queryBytes = null;
|
||||
this.boundary = false;
|
||||
this.bodyParsed = false;
|
||||
@@ -1045,8 +1045,8 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected HttpRequest setRequestURI(String requestURI) {
|
||||
this.requestURI = requestURI;
|
||||
protected HttpRequest setPath(String path) {
|
||||
this.path = path;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -1534,7 +1534,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
@Override
|
||||
public String toString() {
|
||||
parseBody();
|
||||
return this.getClass().getSimpleName() + "{\r\n method: " + this.method + ", \r\n requestURI: " + this.requestURI
|
||||
return this.getClass().getSimpleName() + "{\r\n method: " + this.method + ", \r\n path: " + this.path
|
||||
+ (this.reqConvertType != null ? (", \r\n reqConvertType: " + this.reqConvertType) : "")
|
||||
+ (this.respConvertType != null ? (", \r\n respConvertType: " + this.respConvertType) : "")
|
||||
+ (this.currentUserid != CURRUSERID_NIL ? (", \r\n currentUserid: " + (this.currentUserid == CURRUSERID_NIL ? null : this.currentUserid)) : "")
|
||||
@@ -1781,8 +1781,8 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
*
|
||||
* @return 请求的URL
|
||||
*/
|
||||
public String getRequestURI() {
|
||||
return requestURI;
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1795,29 +1795,29 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 截取getRequestURI最后的一个/后面的部分
|
||||
* 截取getPath最后的一个/后面的部分
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
@ConvertDisabled
|
||||
public String getRequstURILastPath() {
|
||||
if (requestURI == null) {
|
||||
public String getPathLastParam() {
|
||||
if (path == null) {
|
||||
return "";
|
||||
}
|
||||
return requestURI.substring(requestURI.lastIndexOf('/') + 1);
|
||||
return path.substring(path.lastIndexOf('/') + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的short值 <br>
|
||||
* 例如请求URL /pipes/user/query/2 <br>
|
||||
* 获取type参数: short type = request.getRequstURILastPath((short)0); //type = 2
|
||||
* 获取type参数: short type = request.getPathLastParam((short)0); //type = 2
|
||||
*
|
||||
* @param defvalue 默认short值
|
||||
*
|
||||
* @return short值
|
||||
*/
|
||||
public short getRequstURILastPath(short defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
public short getPathLastParam(short defvalue) {
|
||||
String val = getPathLastParam();
|
||||
if (val.isEmpty()) {
|
||||
return defvalue;
|
||||
}
|
||||
@@ -1831,15 +1831,15 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的short值 <br>
|
||||
* 例如请求URL /pipes/user/query/2 <br>
|
||||
* 获取type参数: short type = request.getRequstURILastPath(16, (short)0); //type = 2
|
||||
* 获取type参数: short type = request.getPathLastParam(16, (short)0); //type = 2
|
||||
*
|
||||
* @param radix 进制数
|
||||
* @param defvalue 默认short值
|
||||
*
|
||||
* @return short值
|
||||
*/
|
||||
public short getRequstURILastPath(int radix, short defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
public short getPathLastParam(int radix, short defvalue) {
|
||||
String val = getPathLastParam();
|
||||
if (val.isEmpty()) {
|
||||
return defvalue;
|
||||
}
|
||||
@@ -1853,14 +1853,14 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的int值 <br>
|
||||
* 例如请求URL /pipes/user/query/2 <br>
|
||||
* 获取type参数: int type = request.getRequstURILastPath(0); //type = 2
|
||||
* 获取type参数: int type = request.getPathLastParam(0); //type = 2
|
||||
*
|
||||
* @param defvalue 默认int值
|
||||
*
|
||||
* @return int值
|
||||
*/
|
||||
public int getRequstURILastPath(int defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
public int getPathLastParam(int defvalue) {
|
||||
String val = getPathLastParam();
|
||||
try {
|
||||
return val.isEmpty() ? defvalue : Integer.parseInt(val);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -1871,15 +1871,15 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的int值 <br>
|
||||
* 例如请求URL /pipes/user/query/2 <br>
|
||||
* 获取type参数: int type = request.getRequstURILastPath(16, 0); //type = 2
|
||||
* 获取type参数: int type = request.getPathLastParam(16, 0); //type = 2
|
||||
*
|
||||
* @param radix 进制数
|
||||
* @param defvalue 默认int值
|
||||
*
|
||||
* @return int值
|
||||
*/
|
||||
public int getRequstURILastPath(int radix, int defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
public int getPathLastParam(int radix, int defvalue) {
|
||||
String val = getPathLastParam();
|
||||
try {
|
||||
return val.isEmpty() ? defvalue : Integer.parseInt(val, radix);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -1890,14 +1890,14 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的float值 <br>
|
||||
* 例如请求URL /pipes/user/query/2 <br>
|
||||
* 获取type参数: float type = request.getRequstURILastPath(0.0f); //type = 2.0f
|
||||
* 获取type参数: float type = request.getPathLastParam(0.0f); //type = 2.0f
|
||||
*
|
||||
* @param defvalue 默认float值
|
||||
*
|
||||
* @return float值
|
||||
*/
|
||||
public float getRequstURILastPath(float defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
public float getPathLastParam(float defvalue) {
|
||||
String val = getPathLastParam();
|
||||
try {
|
||||
return val.isEmpty() ? defvalue : Float.parseFloat(val);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -1908,14 +1908,14 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的int值 <br>
|
||||
* 例如请求URL /pipes/user/query/2 <br>
|
||||
* 获取type参数: long type = request.getRequstURILastPath(0L); //type = 2
|
||||
* 获取type参数: long type = request.getPathLastParam(0L); //type = 2
|
||||
*
|
||||
* @param defvalue 默认long值
|
||||
*
|
||||
* @return long值
|
||||
*/
|
||||
public long getRequstURILastPath(long defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
public long getPathLastParam(long defvalue) {
|
||||
String val = getPathLastParam();
|
||||
try {
|
||||
return val.isEmpty() ? defvalue : Long.parseLong(val);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -1926,15 +1926,15 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的int值 <br>
|
||||
* 例如请求URL /pipes/user/query/2 <br>
|
||||
* 获取type参数: long type = request.getRequstURILastPath(16, 0L); //type = 2
|
||||
* 获取type参数: long type = request.getPathLastParam(16, 0L); //type = 2
|
||||
*
|
||||
* @param radix 进制数
|
||||
* @param defvalue 默认long值
|
||||
*
|
||||
* @return long值
|
||||
*/
|
||||
public long getRequstURILastPath(int radix, long defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
public long getPathLastParam(int radix, long defvalue) {
|
||||
String val = getPathLastParam();
|
||||
try {
|
||||
return val.isEmpty() ? defvalue : Long.parseLong(val, radix);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -1945,14 +1945,14 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL最后的一个/后面的部分的double值 <br>
|
||||
* 例如请求URL /pipes/user/query/2 <br>
|
||||
* 获取type参数: double type = request.getRequstURILastPath(0.0); //type = 2.0
|
||||
* 获取type参数: double type = request.getPathLastParam(0.0); //type = 2.0
|
||||
*
|
||||
* @param defvalue 默认double值
|
||||
*
|
||||
* @return double值
|
||||
*/
|
||||
public double getRequstURILastPath(double defvalue) {
|
||||
String val = getRequstURILastPath();
|
||||
public double getPathLastParam(double defvalue) {
|
||||
String val = getPathLastParam();
|
||||
try {
|
||||
return val.isEmpty() ? defvalue : Double.parseDouble(val);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -1962,38 +1962,38 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
|
||||
/**
|
||||
*
|
||||
* 从prefix之后截取getRequestURI再对"/"进行分隔
|
||||
* 从prefix之后截取getPath再对"/"进行分隔
|
||||
* <p>
|
||||
* @param prefix 前缀
|
||||
*
|
||||
* @return String[]
|
||||
*/
|
||||
public String[] getRequstURIPaths(String prefix) {
|
||||
if (requestURI == null || prefix == null) {
|
||||
public String[] getPathParams(String prefix) {
|
||||
if (path == null || prefix == null) {
|
||||
return new String[0];
|
||||
}
|
||||
return requestURI.substring(requestURI.indexOf(prefix) + prefix.length() + (prefix.endsWith("/") ? 0 : 1)).split("/");
|
||||
return path.substring(path.indexOf(prefix) + prefix.length() + (prefix.endsWith("/") ? 0 : 1)).split("/");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求URL分段中含prefix段的值 <br>
|
||||
* 例如请求URL /pipes/user/query/name:hello <br>
|
||||
* 获取name参数: String name = request.getRequstURIPath("name:", "none");
|
||||
* 获取name参数: String name = request.getPathParam("name:", "none");
|
||||
*
|
||||
* @param prefix prefix段前缀
|
||||
* @param defvalue 默认值
|
||||
*
|
||||
* @return prefix截断后的值
|
||||
*/
|
||||
public String getRequstURIPath(String prefix, String defvalue) {
|
||||
if (requestURI == null || prefix == null || prefix.isEmpty()) {
|
||||
public String getPathParam(String prefix, String defvalue) {
|
||||
if (path == null || prefix == null || prefix.isEmpty()) {
|
||||
return defvalue;
|
||||
}
|
||||
int pos = requestURI.indexOf(prefix);
|
||||
int pos = path.indexOf(prefix);
|
||||
if (pos < 0) {
|
||||
return defvalue;
|
||||
}
|
||||
String sub = requestURI.substring(pos + prefix.length());
|
||||
String sub = path.substring(pos + prefix.length());
|
||||
pos = sub.indexOf('/');
|
||||
return pos < 0 ? sub : sub.substring(0, pos);
|
||||
}
|
||||
@@ -2001,15 +2001,15 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL分段中含prefix段的short值 <br>
|
||||
* 例如请求URL /pipes/user/query/type:10 <br>
|
||||
* 获取type参数: short type = request.getRequstURIPath("type:", (short)0);
|
||||
* 获取type参数: short type = request.getPathParam("type:", (short)0);
|
||||
*
|
||||
* @param prefix prefix段前缀
|
||||
* @param defvalue 默认short值
|
||||
*
|
||||
* @return short值
|
||||
*/
|
||||
public short getRequstURIPath(String prefix, short defvalue) {
|
||||
String val = getRequstURIPath(prefix, null);
|
||||
public short getPathParam(String prefix, short defvalue) {
|
||||
String val = getPathParam(prefix, null);
|
||||
try {
|
||||
return val == null ? defvalue : Short.parseShort(val);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -2020,7 +2020,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL分段中含prefix段的short值 <br>
|
||||
* 例如请求URL /pipes/user/query/type:a <br>
|
||||
* 获取type参数: short type = request.getRequstURIPath(16, "type:", (short)0); //type = 10
|
||||
* 获取type参数: short type = request.getPathParam(16, "type:", (short)0); //type = 10
|
||||
*
|
||||
* @param radix 进制数
|
||||
* @param prefix prefix段前缀
|
||||
@@ -2028,8 +2028,8 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
*
|
||||
* @return short值
|
||||
*/
|
||||
public short getRequstURIPath(int radix, String prefix, short defvalue) {
|
||||
String val = getRequstURIPath(prefix, null);
|
||||
public short getPathParam(int radix, String prefix, short defvalue) {
|
||||
String val = getPathParam(prefix, null);
|
||||
try {
|
||||
return val == null ? defvalue : Short.parseShort(val, radix);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -2040,16 +2040,16 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL分段中含prefix段的int值 <br>
|
||||
* 例如请求URL /pipes/user/query/offset:0/limit:50 <br>
|
||||
* 获取offset参数: int offset = request.getRequstURIPath("offset:", 0); <br>
|
||||
* 获取limit参数: int limit = request.getRequstURIPath("limit:", 20); <br>
|
||||
* 获取offset参数: int offset = request.getPathParam("offset:", 0); <br>
|
||||
* 获取limit参数: int limit = request.getPathParam("limit:", 20); <br>
|
||||
*
|
||||
* @param prefix prefix段前缀
|
||||
* @param defvalue 默认int值
|
||||
*
|
||||
* @return int值
|
||||
*/
|
||||
public int getRequstURIPath(String prefix, int defvalue) {
|
||||
String val = getRequstURIPath(prefix, null);
|
||||
public int getPathParam(String prefix, int defvalue) {
|
||||
String val = getPathParam(prefix, null);
|
||||
try {
|
||||
return val == null ? defvalue : Integer.parseInt(val);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -2060,8 +2060,8 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL分段中含prefix段的int值 <br>
|
||||
* 例如请求URL /pipes/user/query/offset:0/limit:50 <br>
|
||||
* 获取offset参数: int offset = request.getRequstURIPath("offset:", 0); <br>
|
||||
* 获取limit参数: int limit = request.getRequstURIPath(16, "limit:", 20); // limit = 16 <br>
|
||||
* 获取offset参数: int offset = request.getPathParam("offset:", 0); <br>
|
||||
* 获取limit参数: int limit = request.getPathParam(16, "limit:", 20); // limit = 16 <br>
|
||||
*
|
||||
* @param radix 进制数
|
||||
* @param prefix prefix段前缀
|
||||
@@ -2069,8 +2069,8 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
*
|
||||
* @return int值
|
||||
*/
|
||||
public int getRequstURIPath(int radix, String prefix, int defvalue) {
|
||||
String val = getRequstURIPath(prefix, null);
|
||||
public int getPathParam(int radix, String prefix, int defvalue) {
|
||||
String val = getPathParam(prefix, null);
|
||||
try {
|
||||
return val == null ? defvalue : Integer.parseInt(val, radix);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -2081,15 +2081,15 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL分段中含prefix段的float值 <br>
|
||||
* 例如请求URL /pipes/user/query/point:40.0 <br>
|
||||
* 获取time参数: float point = request.getRequstURIPath("point:", 0.0f);
|
||||
* 获取time参数: float point = request.getPathParam("point:", 0.0f);
|
||||
*
|
||||
* @param prefix prefix段前缀
|
||||
* @param defvalue 默认float值
|
||||
*
|
||||
* @return float值
|
||||
*/
|
||||
public float getRequstURIPath(String prefix, float defvalue) {
|
||||
String val = getRequstURIPath(prefix, null);
|
||||
public float getPathParam(String prefix, float defvalue) {
|
||||
String val = getPathParam(prefix, null);
|
||||
try {
|
||||
return val == null ? defvalue : Float.parseFloat(val);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -2100,15 +2100,15 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL分段中含prefix段的long值 <br>
|
||||
* 例如请求URL /pipes/user/query/time:1453104341363/id:40 <br>
|
||||
* 获取time参数: long time = request.getRequstURIPath("time:", 0L);
|
||||
* 获取time参数: long time = request.getPathParam("time:", 0L);
|
||||
*
|
||||
* @param prefix prefix段前缀
|
||||
* @param defvalue 默认long值
|
||||
*
|
||||
* @return long值
|
||||
*/
|
||||
public long getRequstURIPath(String prefix, long defvalue) {
|
||||
String val = getRequstURIPath(prefix, null);
|
||||
public long getPathParam(String prefix, long defvalue) {
|
||||
String val = getPathParam(prefix, null);
|
||||
try {
|
||||
return val == null ? defvalue : Long.parseLong(val);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -2119,7 +2119,7 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL分段中含prefix段的long值 <br>
|
||||
* 例如请求URL /pipes/user/query/time:1453104341363/id:40 <br>
|
||||
* 获取time参数: long time = request.getRequstURIPath(16, "time:", 0L);
|
||||
* 获取time参数: long time = request.getPathParam(16, "time:", 0L);
|
||||
*
|
||||
* @param radix 进制数
|
||||
* @param prefix prefix段前缀
|
||||
@@ -2127,8 +2127,8 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
*
|
||||
* @return long值
|
||||
*/
|
||||
public long getRequstURIPath(int radix, String prefix, long defvalue) {
|
||||
String val = getRequstURIPath(prefix, null);
|
||||
public long getPathParam(int radix, String prefix, long defvalue) {
|
||||
String val = getPathParam(prefix, null);
|
||||
try {
|
||||
return val == null ? defvalue : Long.parseLong(val, radix);
|
||||
} catch (NumberFormatException e) {
|
||||
@@ -2139,15 +2139,15 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
/**
|
||||
* 获取请求URL分段中含prefix段的double值 <br>
|
||||
* 例如请求URL /pipes/user/query/point:40.0 <br>
|
||||
* 获取time参数: double point = request.getRequstURIPath("point:", 0.0);
|
||||
* 获取time参数: double point = request.getPathParam("point:", 0.0);
|
||||
*
|
||||
* @param prefix prefix段前缀
|
||||
* @param defvalue 默认double值
|
||||
*
|
||||
* @return double值
|
||||
*/
|
||||
public double getRequstURIPath(String prefix, double defvalue) {
|
||||
String val = getRequstURIPath(prefix, null);
|
||||
public double getPathParam(String prefix, double defvalue) {
|
||||
String val = getPathParam(prefix, null);
|
||||
try {
|
||||
return val == null ? defvalue : Double.parseDouble(val);
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
@@ -212,7 +212,7 @@ public class HttpResourceServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
public void execute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
String uri = request.getRequestURI();
|
||||
String uri = request.getPath();
|
||||
if (uri.contains("../")) {
|
||||
if (logger.isLoggable(Level.FINEST)) {
|
||||
logger.log(Level.FINEST, "Not found resource (404) be " + uri + ", request = " + request);
|
||||
@@ -254,7 +254,7 @@ public class HttpResourceServlet extends HttpServlet {
|
||||
}
|
||||
if (entry == null) {
|
||||
if (logger.isLoggable(Level.FINER)) {
|
||||
logger.log(Level.FINER, "Not found resource (404), url = " + request.getRequestURI());
|
||||
logger.log(Level.FINER, "Not found resource (404), url = " + request.getPath());
|
||||
}
|
||||
finish404(request, response);
|
||||
} else {
|
||||
|
||||
@@ -66,7 +66,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
||||
}
|
||||
}
|
||||
if (entry.cacheSeconds > 0) {//有缓存设置
|
||||
CacheEntry ce = entry.modeOneCache ? entry.oneCache : entry.cache.get(request.getRequestURI());
|
||||
CacheEntry ce = entry.modeOneCache ? entry.oneCache : entry.cache.get(request.getPath());
|
||||
if (ce != null && ce.time + entry.cacheSeconds * 1000 > System.currentTimeMillis()) { //缓存有效
|
||||
response.setStatus(ce.status);
|
||||
response.setContentType(ce.contentType);
|
||||
@@ -125,7 +125,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
||||
return;
|
||||
}
|
||||
for (Map.Entry<String, ActionEntry> en : mappings) {
|
||||
if (request.getRequestURI().startsWith(en.getKey())) {
|
||||
if (request.getPath().startsWith(en.getKey())) {
|
||||
ActionEntry entry = en.getValue();
|
||||
if (!entry.checkMethod(request.getMethod())) {
|
||||
//response.finishJson(new RetResult(RET_METHOD_ERROR, "Method(" + request.getMethod() + ") Error"));
|
||||
@@ -146,7 +146,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
||||
}
|
||||
}
|
||||
finish404(request, response);
|
||||
//throw new IOException(this.getClass().getName() + " not found method for URI(" + request.getRequestURI() + ")");
|
||||
//throw new IOException(this.getClass().getName() + " not found method for URI(" + request.getPath() + ")");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -411,7 +411,7 @@ public class HttpServlet extends Servlet<HttpContext, HttpRequest, HttpResponse>
|
||||
return;
|
||||
}
|
||||
CacheEntry ce = new CacheEntry(response.getStatus(), response.getContentType(), content);
|
||||
cache.put(response.getRequest().getRequestURI(), ce);
|
||||
cache.put(response.getRequest().getPath(), ce);
|
||||
} : null;
|
||||
} else { //单一url
|
||||
this.modeOneCache = true;
|
||||
|
||||
@@ -297,7 +297,7 @@ public class HttpSimpleClient extends Client<HttpSimpleConnection, HttpSimpleReq
|
||||
// final AsyncIOGroup asyncGroup = new AsyncIOGroup(8192, 16);
|
||||
// asyncGroup.start();
|
||||
// String url = "http://redkale.org";
|
||||
// HttpSimpleClient client = HttpSimpleClient.create(asyncGroup);
|
||||
// HttpSimpleClient client = HttpSimpleClient.createPath(asyncGroup);
|
||||
// System.out.println(client.getAsync(url).join());
|
||||
// }
|
||||
//
|
||||
|
||||
@@ -51,12 +51,12 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
protected String method;
|
||||
|
||||
@ConvertColumn(index = 7)
|
||||
@Comment("请求的URI")
|
||||
protected String requestURI;
|
||||
@Comment("请求的Path")
|
||||
protected String path;
|
||||
|
||||
@ConvertColumn(index = 8)
|
||||
@Comment("请求的前缀")
|
||||
protected String path;
|
||||
protected String contextPath;
|
||||
|
||||
@ConvertColumn(index = 9)
|
||||
@Comment("客户端IP")
|
||||
@@ -74,7 +74,7 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
@Comment("Content-Type")
|
||||
protected String contentType;
|
||||
|
||||
@ConvertColumn(index = 13) //@since 2.5.0 由int改成Serializable, 具体数据类型只能是int、long、String
|
||||
@ConvertColumn(index = 13) //@since 2.5.0 由int改成Serializable, 具体数据类型只能是int、long、BigInteger、String
|
||||
protected Serializable currentUserid;
|
||||
|
||||
@ConvertColumn(index = 14)
|
||||
@@ -89,12 +89,12 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
@Comment("http body信息")
|
||||
protected byte[] body; //对应HttpRequest.array
|
||||
|
||||
public static HttpSimpleRequest create(String requestURI) {
|
||||
return new HttpSimpleRequest().requestURI(requestURI).method("POST").traceid(Traces.currentTraceid());
|
||||
public static HttpSimpleRequest createPath(String path) {
|
||||
return new HttpSimpleRequest().path(path).method("POST").traceid(Traces.currentTraceid());
|
||||
}
|
||||
|
||||
public static HttpSimpleRequest create(String requestURI, Object... params) {
|
||||
HttpSimpleRequest req = new HttpSimpleRequest().requestURI(requestURI).method("POST").traceid(Traces.currentTraceid());
|
||||
public static HttpSimpleRequest createPath(String path, Object... params) {
|
||||
HttpSimpleRequest req = new HttpSimpleRequest().path(path).method("POST").traceid(Traces.currentTraceid());
|
||||
int len = params.length / 2;
|
||||
for (int i = 0; i < len; i++) {
|
||||
req.param(params[i * 2].toString(), params[i * 2 + 1]);
|
||||
@@ -102,13 +102,13 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
return req;
|
||||
}
|
||||
|
||||
public static HttpSimpleRequest create(String requestURI, HttpHeaders header) {
|
||||
return new HttpSimpleRequest().requestURI(requestURI).method("POST").headers(header).traceid(Traces.currentTraceid());
|
||||
public static HttpSimpleRequest createPath(String path, HttpHeaders header) {
|
||||
return new HttpSimpleRequest().path(path).method("POST").headers(header).traceid(Traces.currentTraceid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(ClientConnection conn, ByteArray array) {
|
||||
array.put((method.toUpperCase() + " " + requestURI + " HTTP/1.1\r\n"
|
||||
array.put((method.toUpperCase() + " " + path + " HTTP/1.1\r\n"
|
||||
+ Rest.REST_HEADER_TRACEID + ": " + traceid + "\r\n"
|
||||
+ "Content-Length: " + (body == null ? 0 : body.length) + "\r\n").getBytes(StandardCharsets.UTF_8));
|
||||
if (headers != null) {
|
||||
@@ -139,6 +139,13 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String requestPath() {
|
||||
if (this.contextPath == null) {
|
||||
return this.path;
|
||||
}
|
||||
return this.contextPath + this.path;
|
||||
}
|
||||
|
||||
public HttpSimpleRequest formUrlencoded() {
|
||||
this.headers.set("Content-Type", "x-www-form-urlencoded");
|
||||
return this;
|
||||
@@ -151,7 +158,7 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
|
||||
public HttpSimpleRequest traceid(String traceid) {
|
||||
if (traceid != null) {
|
||||
if (traceid.indexOf('\r') >= 0 || traceid.indexOf('\n') >= 0) {
|
||||
if (traceid.indexOf(' ') >= 0 || traceid.indexOf('\r') >= 0 || traceid.indexOf('\n') >= 0) {
|
||||
throw new RedkaleException("http-traceid(" + traceid + ") is illegal");
|
||||
}
|
||||
}
|
||||
@@ -159,14 +166,6 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpSimpleRequest requestURI(String requestURI) {
|
||||
if (requestURI.indexOf(' ') >= 0 || requestURI.indexOf('\r') >= 0 || requestURI.indexOf('\n') >= 0) {
|
||||
throw new RedkaleException("http-uri(" + requestURI + ") is illegal");
|
||||
}
|
||||
this.requestURI = requestURI;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpSimpleRequest path(String path) {
|
||||
if (path.indexOf(' ') >= 0 || path.indexOf('\r') >= 0 || path.indexOf('\n') >= 0) {
|
||||
throw new RedkaleException("http-path(" + path + ") is illegal");
|
||||
@@ -175,6 +174,14 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpSimpleRequest contextPath(String contextPath) {
|
||||
if (contextPath.indexOf(' ') >= 0 || contextPath.indexOf('\r') >= 0 || contextPath.indexOf('\n') >= 0) {
|
||||
throw new RedkaleException("http-context-path(" + contextPath + ") is illegal");
|
||||
}
|
||||
this.contextPath = contextPath;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HttpSimpleRequest bothConvertType(ConvertType convertType) {
|
||||
this.reqConvertType = convertType;
|
||||
this.respConvertType = convertType;
|
||||
@@ -383,14 +390,6 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
public String getRequestURI() {
|
||||
return requestURI;
|
||||
}
|
||||
|
||||
public void setRequestURI(String requestURI) {
|
||||
this.requestURI = requestURI;
|
||||
}
|
||||
|
||||
public String getPath() {
|
||||
return path;
|
||||
}
|
||||
@@ -399,6 +398,14 @@ public class HttpSimpleRequest extends ClientRequest implements java.io.Serializ
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
public String getContextPath() {
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
public void setContextPath(String contextPath) {
|
||||
this.contextPath = contextPath;
|
||||
}
|
||||
|
||||
public String getSessionid() {
|
||||
return sessionid;
|
||||
}
|
||||
|
||||
@@ -1304,9 +1304,9 @@ public final class Rest {
|
||||
if (annfile != null) {
|
||||
comment = annfile.comment();
|
||||
}
|
||||
RestURI annuri = param.getAnnotation(RestURI.class);
|
||||
if (annuri != null) {
|
||||
comment = annuri.comment();
|
||||
RestPath annpath = param.getAnnotation(RestPath.class);
|
||||
if (annpath != null) {
|
||||
comment = annpath.comment();
|
||||
}
|
||||
RestUserid userid = param.getAnnotation(RestUserid.class);
|
||||
|
||||
@@ -1348,9 +1348,9 @@ public final class Rest {
|
||||
} //n maybe is null
|
||||
|
||||
java.lang.reflect.Type paramtype = TypeToken.getGenericType(param.getParameterizedType(), serviceType);
|
||||
paramlist.add(new Object[]{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annlocale, annhead, anncookie, annbody, annfile, annuri, userid, annheaders, annparams, paramtype});
|
||||
paramlist.add(new Object[]{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annlocale, annhead, anncookie, annbody, annfile, annpath, userid, annheaders, annparams, paramtype});
|
||||
}
|
||||
for (Object[] ps : paramlist) { //{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annlocale, annhead, anncookie, annbody, annfile, annuri, annuserid, annheaders, annparams, paramtype}
|
||||
for (Object[] ps : paramlist) { //{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annlocale, annhead, anncookie, annbody, annfile, annpath, annuserid, annheaders, annparams, paramtype}
|
||||
final boolean isuserid = ((RestUserid) ps[headIndex + 5]) != null; //是否取userid
|
||||
if ((ps[1] != null && ps[1].toString().indexOf('&') >= 0) || isuserid) {
|
||||
continue; //@RestUserid 不需要生成 @HttpParam
|
||||
@@ -1381,7 +1381,7 @@ public final class Rest {
|
||||
RestCookie anncookie = (RestCookie) ps[headIndex + 1];
|
||||
RestBody annbody = (RestBody) ps[headIndex + 2];
|
||||
RestUploadFile annfile = (RestUploadFile) ps[headIndex + 3];
|
||||
RestURI annuri = (RestURI) ps[headIndex + 4];
|
||||
RestPath annpath = (RestPath) ps[headIndex + 4];
|
||||
RestUserid annuserid = (RestUserid) ps[headIndex + 5];
|
||||
boolean annheaders = (Boolean) ps[headIndex + 6];
|
||||
boolean annparams = (Boolean) ps[headIndex + 7];
|
||||
@@ -1392,9 +1392,9 @@ public final class Rest {
|
||||
} else if (annlocale != null) { //HttpRequest.getLocale
|
||||
} else if (annbody != null) { //HttpRequest.getBodyUTF8 / HttpRequest.getBody
|
||||
} else if (annfile != null) { //MultiContext.partsFirstBytes / HttpRequest.partsFirstFile / HttpRequest.partsFiles
|
||||
} else if (annuri != null) { //HttpRequest.getRequestURI
|
||||
} else if (annpath != null) { //HttpRequest.getPath
|
||||
} else if (annuserid != null) { //HttpRequest.currentUserid
|
||||
} else if (pname != null && pname.charAt(0) == '#') { //从request.getRequstURIPath 中去参数
|
||||
} else if (pname != null && pname.charAt(0) == '#') { //从request.getPathParam 中去参数
|
||||
} else if ("#".equals(pname)) { //从request.getRequstURI 中取参数
|
||||
} else if ("&".equals(pname) && ptype == userType) { //当前用户对象的类名
|
||||
} else if ("^".equals(pname) && annheaders) { //HttpRequest.getHeaders Http头信息
|
||||
@@ -1431,7 +1431,7 @@ public final class Rest {
|
||||
RestLocale rl = field.getAnnotation(RestLocale.class);
|
||||
RestBody rb = field.getAnnotation(RestBody.class);
|
||||
RestUploadFile ru = field.getAnnotation(RestUploadFile.class);
|
||||
RestURI ri = field.getAnnotation(RestURI.class);
|
||||
RestPath ri = field.getAnnotation(RestPath.class);
|
||||
if (rh == null && rc == null && ra == null && rl == null && rb == null && rs == null && ru == null && ri == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -2097,33 +2097,33 @@ public final class Rest {
|
||||
comment = annfile.comment();
|
||||
}
|
||||
|
||||
RestURI annuri = param.getAnnotation(RestURI.class);
|
||||
if (annuri != null) {
|
||||
RestPath annpath = param.getAnnotation(RestPath.class);
|
||||
if (annpath != null) {
|
||||
if (annhead != null) {
|
||||
throw new RestException("@RestURI and @RestHeader cannot on the same Parameter in " + method);
|
||||
throw new RestException("@RestPath and @RestHeader cannot on the same Parameter in " + method);
|
||||
}
|
||||
if (anncookie != null) {
|
||||
throw new RestException("@RestURI and @RestCookie cannot on the same Parameter in " + method);
|
||||
throw new RestException("@RestPath and @RestCookie cannot on the same Parameter in " + method);
|
||||
}
|
||||
if (annsid != null) {
|
||||
throw new RestException("@RestURI and @RestSessionid cannot on the same Parameter in " + method);
|
||||
throw new RestException("@RestPath and @RestSessionid cannot on the same Parameter in " + method);
|
||||
}
|
||||
if (annaddr != null) {
|
||||
throw new RestException("@RestURI and @RestAddress cannot on the same Parameter in " + method);
|
||||
throw new RestException("@RestPath and @RestAddress cannot on the same Parameter in " + method);
|
||||
}
|
||||
if (annlocale != null) {
|
||||
throw new RestException("@RestURI and @RestLocale cannot on the same Parameter in " + method);
|
||||
throw new RestException("@RestPath and @RestLocale cannot on the same Parameter in " + method);
|
||||
}
|
||||
if (annbody != null) {
|
||||
throw new RestException("@RestURI and @RestBody cannot on the same Parameter in " + method);
|
||||
throw new RestException("@RestPath and @RestBody cannot on the same Parameter in " + method);
|
||||
}
|
||||
if (annfile != null) {
|
||||
throw new RestException("@RestURI and @RestUploadFile cannot on the same Parameter in " + method);
|
||||
throw new RestException("@RestPath and @RestUploadFile cannot on the same Parameter in " + method);
|
||||
}
|
||||
if (ptype != String.class) {
|
||||
throw new RestException("@RestURI must on String Parameter in " + method);
|
||||
throw new RestException("@RestPath must on String Parameter in " + method);
|
||||
}
|
||||
comment = annuri.comment();
|
||||
comment = annpath.comment();
|
||||
}
|
||||
|
||||
RestUserid userid = param.getAnnotation(RestUserid.class);
|
||||
@@ -2283,7 +2283,7 @@ public final class Rest {
|
||||
} while ((loop = loop.getSuperclass()) != Object.class);
|
||||
}
|
||||
java.lang.reflect.Type paramtype = TypeToken.getGenericType(param.getParameterizedType(), serviceType);
|
||||
paramlist.add(new Object[]{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annlocale, annhead, anncookie, annbody, annfile, annuri, userid, annheaders, annparams, paramtype});
|
||||
paramlist.add(new Object[]{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annlocale, annhead, anncookie, annbody, annfile, annpath, userid, annheaders, annparams, paramtype});
|
||||
}
|
||||
|
||||
Map<String, Object> mappingMap = new LinkedHashMap<>();
|
||||
@@ -2406,7 +2406,7 @@ public final class Rest {
|
||||
av0 = mv.visitAnnotation(httpParamsDesc, true);
|
||||
AnnotationVisitor av1 = av0.visitArray("value");
|
||||
//设置 HttpParam
|
||||
for (Object[] ps : paramlist) { //{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annlocale, annhead, anncookie, annbody, annfile, annuri, annuserid, annheaders, annparams, paramtype}
|
||||
for (Object[] ps : paramlist) { //{param, n, ptype, radix, comment, required, annpara, annsid, annaddr, annlocale, annhead, anncookie, annbody, annfile, annpath, annuserid, annheaders, annparams, paramtype}
|
||||
String n = ps[1].toString();
|
||||
final boolean isuserid = ((RestUserid) ps[headIndex + 5]) != null; //是否取userid
|
||||
if (n.indexOf('&') >= 0 || isuserid) {
|
||||
@@ -2514,7 +2514,7 @@ public final class Rest {
|
||||
RestCookie anncookie = (RestCookie) ps[headIndex + 1];
|
||||
RestBody annbody = (RestBody) ps[headIndex + 2];
|
||||
RestUploadFile annfile = (RestUploadFile) ps[headIndex + 3];
|
||||
RestURI annuri = (RestURI) ps[headIndex + 4];
|
||||
RestPath annpath = (RestPath) ps[headIndex + 4];
|
||||
RestUserid userid = (RestUserid) ps[headIndex + 5];
|
||||
boolean annheaders = (Boolean) ps[headIndex + 6];
|
||||
boolean annparams = (Boolean) ps[headIndex + 7];
|
||||
@@ -2596,9 +2596,9 @@ public final class Rest {
|
||||
mv.visitVarInsn(ALOAD, 4);
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
varInsns.add(new int[]{ALOAD, maxLocals});
|
||||
} else if (annuri != null) { //HttpRequest.getRequestURI
|
||||
} else if (annpath != null) { //HttpRequest.getPath
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequestURI", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPath", "()Ljava/lang/String;", false);
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
varInsns.add(new int[]{ALOAD, maxLocals});
|
||||
} else if (userid != null) { //HttpRequest.currentUserid
|
||||
@@ -2626,47 +2626,47 @@ public final class Rest {
|
||||
} else if ("#".equals(pname)) { //从request.getRequstURI 中取参数
|
||||
if (ptype == boolean.class) {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURILastPath", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathLastParam", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "parseBoolean", "(Ljava/lang/String;)Z", false);
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
varInsns.add(new int[]{ILOAD, maxLocals});
|
||||
} else if (ptype == byte.class) {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURILastPath", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathLastParam", "()Ljava/lang/String;", false);
|
||||
mv.visitIntInsn(BIPUSH, radix);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "parseByte", "(Ljava/lang/String;I)B", false);
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
varInsns.add(new int[]{ILOAD, maxLocals});
|
||||
} else if (ptype == short.class) {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURILastPath", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathLastParam", "()Ljava/lang/String;", false);
|
||||
mv.visitIntInsn(BIPUSH, radix);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "parseShort", "(Ljava/lang/String;I)S", false);
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
varInsns.add(new int[]{ILOAD, maxLocals});
|
||||
} else if (ptype == char.class) {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURILastPath", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathLastParam", "()Ljava/lang/String;", false);
|
||||
mv.visitInsn(ICONST_0);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "charAt", "(I)C", false);
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
varInsns.add(new int[]{ILOAD, maxLocals});
|
||||
} else if (ptype == int.class) {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURILastPath", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathLastParam", "()Ljava/lang/String;", false);
|
||||
mv.visitIntInsn(BIPUSH, radix);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/String;I)I", false);
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
varInsns.add(new int[]{ILOAD, maxLocals});
|
||||
} else if (ptype == float.class) {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURILastPath", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathLastParam", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "parseFloat", "(Ljava/lang/String;)F", false);
|
||||
mv.visitVarInsn(FSTORE, maxLocals);
|
||||
varInsns.add(new int[]{FLOAD, maxLocals});
|
||||
} else if (ptype == long.class) {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURILastPath", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathLastParam", "()Ljava/lang/String;", false);
|
||||
mv.visitIntInsn(BIPUSH, radix);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "parseLong", "(Ljava/lang/String;I)J", false);
|
||||
mv.visitVarInsn(LSTORE, maxLocals);
|
||||
@@ -2674,25 +2674,25 @@ public final class Rest {
|
||||
maxLocals++;
|
||||
} else if (ptype == double.class) {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURILastPath", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathLastParam", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "parseDouble", "(Ljava/lang/String;)D", false);
|
||||
mv.visitVarInsn(DSTORE, maxLocals);
|
||||
varInsns.add(new int[]{DLOAD, maxLocals});
|
||||
maxLocals++;
|
||||
} else if (ptype == String.class) {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURILastPath", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathLastParam", "()Ljava/lang/String;", false);
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
varInsns.add(new int[]{ALOAD, maxLocals});
|
||||
} else {
|
||||
throw new RestException(method + " only " + RestParam.class.getSimpleName() + "(#) to Type(primitive class or String)");
|
||||
}
|
||||
} else if (pname.charAt(0) == '#') { //从request.getRequstURIPath 中去参数
|
||||
} else if (pname.charAt(0) == '#') { //从request.getPathParam 中去参数
|
||||
if (ptype == boolean.class) {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitLdcInsn(pname.substring(1));
|
||||
mv.visitLdcInsn("false");
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURIPath", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathParam", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "parseBoolean", "(Ljava/lang/String;)Z", false);
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
varInsns.add(new int[]{ILOAD, maxLocals});
|
||||
@@ -2700,7 +2700,7 @@ public final class Rest {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitLdcInsn(pname.substring(1));
|
||||
mv.visitLdcInsn("0");
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURIPath", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathParam", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitIntInsn(BIPUSH, radix);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "parseByte", "(Ljava/lang/String;I)B", false);
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
@@ -2709,7 +2709,7 @@ public final class Rest {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitLdcInsn(pname.substring(1));
|
||||
mv.visitLdcInsn("0");
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURIPath", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathParam", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitIntInsn(BIPUSH, radix);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "parseShort", "(Ljava/lang/String;I)S", false);
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
@@ -2718,7 +2718,7 @@ public final class Rest {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitLdcInsn(pname.substring(1));
|
||||
mv.visitLdcInsn("0");
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURIPath", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathParam", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitInsn(ICONST_0);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "charAt", "(I)C", false);
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
@@ -2727,7 +2727,7 @@ public final class Rest {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitLdcInsn(pname.substring(1));
|
||||
mv.visitLdcInsn("0");
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURIPath", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathParam", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitIntInsn(BIPUSH, radix);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "parseInt", "(Ljava/lang/String;I)I", false);
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
@@ -2736,7 +2736,7 @@ public final class Rest {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitLdcInsn(pname.substring(1));
|
||||
mv.visitLdcInsn("0");
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURIPath", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathParam", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "parseFloat", "(Ljava/lang/String;)F", false);
|
||||
mv.visitVarInsn(FSTORE, maxLocals);
|
||||
varInsns.add(new int[]{FLOAD, maxLocals});
|
||||
@@ -2744,7 +2744,7 @@ public final class Rest {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitLdcInsn(pname.substring(1));
|
||||
mv.visitLdcInsn("0");
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURIPath", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathParam", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitIntInsn(BIPUSH, radix);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "parseLong", "(Ljava/lang/String;I)J", false);
|
||||
mv.visitVarInsn(LSTORE, maxLocals);
|
||||
@@ -2754,7 +2754,7 @@ public final class Rest {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitLdcInsn(pname.substring(1));
|
||||
mv.visitLdcInsn("0");
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURIPath", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathParam", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "parseDouble", "(Ljava/lang/String;)D", false);
|
||||
mv.visitVarInsn(DSTORE, maxLocals);
|
||||
varInsns.add(new int[]{DLOAD, maxLocals});
|
||||
@@ -2763,7 +2763,7 @@ public final class Rest {
|
||||
mv.visitVarInsn(ALOAD, 1);
|
||||
mv.visitLdcInsn(pname.substring(1));
|
||||
mv.visitLdcInsn("");
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequstURIPath", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPathParam", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;", false);
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
varInsns.add(new int[]{ALOAD, maxLocals});
|
||||
} else {
|
||||
@@ -2903,7 +2903,7 @@ public final class Rest {
|
||||
RestLocale rl = field.getAnnotation(RestLocale.class);
|
||||
RestBody rb = field.getAnnotation(RestBody.class);
|
||||
RestUploadFile ru = field.getAnnotation(RestUploadFile.class);
|
||||
RestURI ri = field.getAnnotation(RestURI.class);
|
||||
RestPath ri = field.getAnnotation(RestPath.class);
|
||||
if (rh == null && rc == null && ra == null && rl == null && rb == null && rs == null && ru == null && ri == null) {
|
||||
continue;
|
||||
}
|
||||
@@ -2930,7 +2930,7 @@ public final class Rest {
|
||||
}
|
||||
|
||||
if (ri != null && field.getType() != String.class) {
|
||||
throw new RestException("@RestURI must on String Field in " + field);
|
||||
throw new RestException("@RestPath must on String Field in " + field);
|
||||
}
|
||||
org.redkale.util.Attribute attr = org.redkale.util.Attribute.create(loop, field);
|
||||
String attrFieldName;
|
||||
@@ -3026,7 +3026,7 @@ public final class Rest {
|
||||
} else if (en.getKey().contains("_locale_")) {
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getLocale", "()Ljava/lang/String;", false);
|
||||
} else if (en.getKey().contains("_uri_")) {
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getRequestURI", "()Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getPath", "()Ljava/lang/String;", false);
|
||||
} else if (en.getKey().contains("_bodystring_")) {
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, reqInternalName, "getBodyUTF8", "()Ljava/lang/String;", false);
|
||||
} else if (en.getKey().contains("_bodybytes_")) {
|
||||
|
||||
@@ -12,7 +12,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
/**
|
||||
* 只能注解于Service类的方法的String参数或参数内的String字段
|
||||
* <p>
|
||||
* 用于获取HTTP请求URL HttpRequest.getRequestURI
|
||||
* 用于获取HTTP请求URL HttpRequest.getPath
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
@@ -22,7 +22,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
@Documented
|
||||
@Target({PARAMETER, FIELD})
|
||||
@Retention(RUNTIME)
|
||||
public @interface RestURI {
|
||||
public @interface RestPath {
|
||||
|
||||
/**
|
||||
* 备注描述, 对应@HttpParam.comment
|
||||
@@ -48,7 +48,8 @@ public class ObjectPool<T> implements Supplier<T>, Consumer<T> {
|
||||
//true表示unsafeThread不为空且当前为非线程安全版且parent为线程安全版
|
||||
protected final boolean safeCombine;
|
||||
|
||||
protected ObjectPool(ObjectPool<T> parent, LongAdder creatCounter, LongAdder cycleCounter, Thread unsafeThread, int max, Creator<T> creator, Consumer<T> prepare, Predicate<T> recycler, Queue<T> queue) {
|
||||
protected ObjectPool(ObjectPool<T> parent, LongAdder creatCounter, LongAdder cycleCounter,
|
||||
Thread unsafeThread, int max, Creator<T> creator, Consumer<T> prepare, Predicate<T> recycler, Queue<T> queue) {
|
||||
this.parent = parent;
|
||||
this.creatCounter = creatCounter;
|
||||
this.cycleCounter = cycleCounter;
|
||||
@@ -89,12 +90,14 @@ public class ObjectPool<T> implements Supplier<T>, Consumer<T> {
|
||||
}
|
||||
|
||||
//非线程安全版
|
||||
public static <T> ObjectPool<T> createUnsafePool(LongAdder creatCounter, LongAdder cycleCounter, int max, Supplier<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
public static <T> ObjectPool<T> createUnsafePool(LongAdder creatCounter, LongAdder cycleCounter,
|
||||
int max, Supplier<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
return createUnsafePool(creatCounter, cycleCounter, max, c -> creator.get(), prepare, recycler);
|
||||
}
|
||||
|
||||
//非线程安全版
|
||||
public static <T> ObjectPool<T> createUnsafePool(LongAdder creatCounter, LongAdder cycleCounter, int max, Creator<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
public static <T> ObjectPool<T> createUnsafePool(LongAdder creatCounter, LongAdder cycleCounter,
|
||||
int max, Creator<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
return createUnsafePool(null, creatCounter, cycleCounter, max, creator, prepare, recycler);
|
||||
}
|
||||
|
||||
@@ -124,25 +127,29 @@ public class ObjectPool<T> implements Supplier<T>, Consumer<T> {
|
||||
}
|
||||
|
||||
//非线程安全版
|
||||
public static <T> ObjectPool<T> createUnsafePool(ObjectPool<T> parent, LongAdder creatCounter, LongAdder cycleCounter, int max, Supplier<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
public static <T> ObjectPool<T> createUnsafePool(ObjectPool<T> parent, LongAdder creatCounter, LongAdder cycleCounter,
|
||||
int max, Supplier<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
return createUnsafePool(parent, creatCounter, cycleCounter, max, c -> creator.get(), prepare, recycler);
|
||||
}
|
||||
|
||||
//非线程安全版
|
||||
public static <T> ObjectPool<T> createUnsafePool(ObjectPool<T> parent, LongAdder creatCounter, LongAdder cycleCounter, int max, Creator<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
public static <T> ObjectPool<T> createUnsafePool(ObjectPool<T> parent, LongAdder creatCounter, LongAdder cycleCounter,
|
||||
int max, Creator<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
return new ObjectPool(parent, creatCounter, cycleCounter, null, Math.max(Utility.cpus(), max),
|
||||
creator, prepare, recycler, new ArrayDeque<>(Math.max(Utility.cpus(), max)));
|
||||
}
|
||||
|
||||
//非线程安全版
|
||||
public static <T> ObjectPool<T> createUnsafePool(ObjectPool<T> parent, LongAdder creatCounter, LongAdder cycleCounter, Thread unsafeThread, int max, Creator<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
public static <T> ObjectPool<T> createUnsafePool(ObjectPool<T> parent, LongAdder creatCounter, LongAdder cycleCounter,
|
||||
Thread unsafeThread, int max, Creator<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
return new ObjectPool(parent, creatCounter, cycleCounter, unsafeThread, Math.max(Utility.cpus(), max),
|
||||
creator, prepare, recycler, new ArrayDeque<>(Math.max(Utility.cpus(), max)));
|
||||
}
|
||||
|
||||
//非线程安全版
|
||||
public static <T> ObjectPool<T> createUnsafePool(Thread unsafeThread, int max, ObjectPool<T> safePool) {
|
||||
return createUnsafePool(safePool, safePool.getCreatCounter(), safePool.getCycleCounter(), unsafeThread, max, safePool.getCreator(), safePool.getPrepare(), safePool.getRecycler());
|
||||
return createUnsafePool(safePool, safePool.getCreatCounter(), safePool.getCycleCounter(),
|
||||
unsafeThread, max, safePool.getCreator(), safePool.getPrepare(), safePool.getRecycler());
|
||||
}
|
||||
|
||||
//线程安全版
|
||||
@@ -171,12 +178,14 @@ public class ObjectPool<T> implements Supplier<T>, Consumer<T> {
|
||||
}
|
||||
|
||||
//线程安全版
|
||||
public static <T> ObjectPool<T> createSafePool(LongAdder creatCounter, LongAdder cycleCounter, int max, Supplier<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
public static <T> ObjectPool<T> createSafePool(LongAdder creatCounter, LongAdder cycleCounter,
|
||||
int max, Supplier<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
return createSafePool(creatCounter, cycleCounter, max, c -> creator.get(), prepare, recycler);
|
||||
}
|
||||
|
||||
//线程安全版
|
||||
public static <T> ObjectPool<T> createSafePool(LongAdder creatCounter, LongAdder cycleCounter, int max, Creator<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
public static <T> ObjectPool<T> createSafePool(LongAdder creatCounter, LongAdder cycleCounter,
|
||||
int max, Creator<T> creator, Consumer<T> prepare, Predicate<T> recycler) {
|
||||
return new ObjectPool(null, creatCounter, cycleCounter, null, Math.max(Utility.cpus(), max),
|
||||
creator, prepare, recycler, new LinkedBlockingQueue<>(Math.max(Utility.cpus(), max)));
|
||||
}
|
||||
@@ -219,7 +228,7 @@ public class ObjectPool<T> implements Supplier<T>, Consumer<T> {
|
||||
if (unsafeThread == null) {
|
||||
unsafeThread = Thread.currentThread();
|
||||
} else if (unsafeThread != Thread.currentThread()) {
|
||||
throw new IllegalCallerException("unsafeThread is " + unsafeThread + ", but currentThread is " + Thread.currentThread());
|
||||
throw new RedkaleException("unsafeThread is " + unsafeThread + ", but currentThread is " + Thread.currentThread());
|
||||
}
|
||||
}
|
||||
T result = queue.poll();
|
||||
@@ -254,7 +263,7 @@ public class ObjectPool<T> implements Supplier<T>, Consumer<T> {
|
||||
if (unsafeThread == null) {
|
||||
unsafeThread = Thread.currentThread();
|
||||
} else if (unsafeThread != Thread.currentThread()) {
|
||||
throw new IllegalCallerException("unsafeThread is " + unsafeThread + ", but currentThread is " + Thread.currentThread());
|
||||
throw new RedkaleException("unsafeThread is " + unsafeThread + ", but currentThread is " + Thread.currentThread());
|
||||
}
|
||||
}
|
||||
if (recycler.test(e)) {
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.TimeZone;
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public abstract class Times {
|
||||
public final class Times {
|
||||
|
||||
private static final int ZONE_RAW_OFFSET = TimeZone.getDefault().getRawOffset();
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.function.Supplier;
|
||||
* @author zhangjx
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public class Traces {
|
||||
public final class Traces {
|
||||
|
||||
private static final boolean ENABLE = !Boolean.getBoolean("redkale.trace.disable");
|
||||
|
||||
@@ -27,6 +27,10 @@ public class Traces {
|
||||
|
||||
private static final ThreadLocal<String> localTrace = new ThreadLocal<>();
|
||||
|
||||
private Traces() {
|
||||
//do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否开启了trace功能
|
||||
*
|
||||
|
||||
@@ -28,7 +28,7 @@ public class RequestCoderTest {
|
||||
|
||||
@Test
|
||||
public void run1() throws Exception {
|
||||
HttpSimpleRequest req1 = HttpSimpleRequest.create("/aaa");
|
||||
HttpSimpleRequest req1 = HttpSimpleRequest.createPath("/aaa");
|
||||
System.out.println("simpleRequest1: " + req1);
|
||||
byte[] bytes = HttpSimpleRequestCoder.getInstance().encode(req1);
|
||||
HttpSimpleRequest req2 = HttpSimpleRequestCoder.getInstance().decode(bytes);
|
||||
@@ -41,7 +41,7 @@ public class RequestCoderTest {
|
||||
|
||||
@Test
|
||||
public void run2() throws Exception {
|
||||
HttpSimpleRequest req1 = HttpSimpleRequest.create("/aaa");
|
||||
HttpSimpleRequest req1 = HttpSimpleRequest.createPath("/aaa");
|
||||
req1.addHeader("X-aaa", "aaa");
|
||||
req1.param("bean", "{}");
|
||||
System.out.println("simpleRequest1: " + req1);
|
||||
@@ -56,7 +56,7 @@ public class RequestCoderTest {
|
||||
|
||||
@Test
|
||||
public void run3() throws Exception {
|
||||
HttpSimpleRequest req1 = HttpSimpleRequest.create("/aaa");
|
||||
HttpSimpleRequest req1 = HttpSimpleRequest.createPath("/aaa");
|
||||
req1.addHeader("X-aaa", "aaa");
|
||||
req1.addHeader("X-bbb", "bbb1");
|
||||
req1.addHeader("X-bbb", "bbb2");
|
||||
|
||||
@@ -17,7 +17,7 @@ public class UploadTestServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
public void execute(HttpRequest request, HttpResponse response) throws IOException {
|
||||
if (request.getRequestURI().contains("/uploadtest/send")) {
|
||||
if (request.getPath().contains("/uploadtest/send")) {
|
||||
send(request, response);
|
||||
} else {
|
||||
form(request, response);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class HelloEntity {
|
||||
@RestAddress
|
||||
private String clientaddr;
|
||||
|
||||
@RestURI
|
||||
@RestPath
|
||||
private String uri;
|
||||
|
||||
public HelloEntity() {
|
||||
|
||||
@@ -74,7 +74,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
@HttpMapping(url = "/hello/delete/", auth = false)
|
||||
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
service.deleteHello(id);
|
||||
resp.finishJson(RetResult.success());
|
||||
}
|
||||
@@ -129,7 +129,7 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
@HttpMapping(url = "/hello/find/", auth = false)
|
||||
public void find(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
HelloEntity bean = service.findHello(id);
|
||||
resp.finishJson(bean);
|
||||
}
|
||||
@@ -137,21 +137,21 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
@HttpMapping(url = "/hello/asyncfind/", auth = false)
|
||||
public void asyncfind(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
resp.finishJson(service.asyncFindHello(id));
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/hello/asyncfind2/", auth = false)
|
||||
public void asyncfind2(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
service.asyncFindHello(resp.createAsyncHandler(), id);
|
||||
}
|
||||
|
||||
@HttpMapping(url = "/hello/asyncfind3/", auth = false)
|
||||
public void asyncfind3(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
service.asyncFindHello(resp.createAsyncHandler(HelloAsyncHandler.class), id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
@HttpParam(name = "#", type = int.class, comment = "Hello对象id")
|
||||
public void delete(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
service.deleteHello(id);
|
||||
resp.finishJson(RetResult.success());
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class _DynHelloRestServlet2 extends SimpleRestServlet {
|
||||
@HttpParam(name = "#", type = int.class, comment = "Hello对象id")
|
||||
public void find(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService2 service = _redkale_servicemap == null ? _redkale_service : _redkale_servicemap.get(req.getHeader(Rest.REST_HEADER_RESNAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
int id = Integer.parseInt(req.getPathLastParam());
|
||||
HelloEntity bean = service.findHello(id);
|
||||
resp.finishJson(bean);
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ public class VideoWebSocketServlet extends WebSocketServlet {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<String> onOpen(final HttpRequest request) {
|
||||
String uri = request.getRequestURI();
|
||||
String uri = request.getPath();
|
||||
int pos = uri.indexOf("/listen/");
|
||||
uri = uri.substring(pos + "/listen/".length());
|
||||
this.repeat = sessions.get(uri) != null;
|
||||
|
||||
Reference in New Issue
Block a user