Skip to content

Commit b8846b0

Browse files
author
litongjava
committed
add tio.http.request.printUrl
1 parent 85c5e26 commit b8846b0

File tree

6 files changed

+31
-101
lines changed

6 files changed

+31
-101
lines changed

src/main/java/com/litongjava/tio/boot/constatns/ConfigKeys.java renamed to src/main/java/com/litongjava/tio/boot/constatns/TioBootConfigKeys.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.litongjava.tio.boot.constatns;
22

3-
public class ConfigKeys {
3+
public class TioBootConfigKeys {
44
// server
55
public static final String DEFAULT_CONFIG_FILE_NAME = "app.properties";
66
public static final String SERVER_ADDRESS = "server.address";
@@ -22,6 +22,7 @@ public class ConfigKeys {
2222
// tio
2323
public static final String TIO_DEV_MODE = "tio.dev.mode";
2424
public static final String TIO_NO_SERVER = "tio.no.server";
25+
public static final String TIO_HTTP_REQUEST_PRINT_URL ="tio.http.request.printUrl";
2526

2627
// app
2728
public static final String APP_ENV = "app.env";

src/main/java/com/litongjava/tio/boot/context/TioApplicationContext.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import com.litongjava.jfinal.aop.process.BeforeStartConfigurationProcess;
1212
import com.litongjava.jfinal.aop.process.ComponentAnnotation;
1313
import com.litongjava.jfinal.aop.scaner.ComponentScanner;
14-
import com.litongjava.tio.boot.constatns.ConfigKeys;
14+
import com.litongjava.tio.boot.constatns.TioBootConfigKeys;
1515
import com.litongjava.tio.boot.http.handler.AopControllerFactory;
1616
import com.litongjava.tio.boot.http.handler.DefaultHttpRequestHandlerDispather;
1717
import com.litongjava.tio.boot.http.handler.TioServerSessionRateLimiter;
@@ -64,7 +64,7 @@ public Context run(Class<?>[] primarySources, String[] args) {
6464
List<Class<?>> scannedClasses = null;
6565
// 添加自定义组件注解
6666
ComponentAnnotation.addComponentAnnotation(RequestPath.class);
67-
boolean printScannedClasses = EnvironmentUtils.getBoolean(ConfigKeys.AOP_PRINT_SCANNED_CLASSSES, false);
67+
boolean printScannedClasses = EnvironmentUtils.getBoolean(TioBootConfigKeys.AOP_PRINT_SCANNED_CLASSSES, false);
6868
// 执行组件扫描
6969
try {
7070
scannedClasses = ComponentScanner.scan(primarySources, printScannedClasses);
@@ -92,15 +92,15 @@ public Context run(Class<?>[] primarySources, String[] args) {
9292
serverListener.boforeStart(primarySources, args);
9393
}
9494
// 启动端口
95-
int port = EnvironmentUtils.getInt(ConfigKeys.SERVER_PORT, 80);
96-
String contextPath = EnvironmentUtils.get(ConfigKeys.SERVER_CONTEXT_PATH);
95+
int port = EnvironmentUtils.getInt(TioBootConfigKeys.SERVER_PORT, 80);
96+
String contextPath = EnvironmentUtils.get(TioBootConfigKeys.SERVER_CONTEXT_PATH);
9797
// http request routes
9898
TioBootHttpRoutes tioBootHttpRoutes = new TioBootHttpRoutes();
9999
// 添加到aop容器
100100
tioBootServer.setTioBootHttpRoutes(tioBootHttpRoutes);
101101

102102
// 根据参数判断是否启动服务器,默认启动服务器
103-
if (!EnvironmentUtils.getBoolean(ConfigKeys.TIO_NO_SERVER, false)) {
103+
if (!EnvironmentUtils.getBoolean(TioBootConfigKeys.TIO_NO_SERVER, false)) {
104104
configAndStartServer(primarySources, args, port, contextPath, tioBootHttpRoutes);
105105
}
106106

@@ -112,7 +112,7 @@ public Context run(Class<?>[] primarySources, String[] args) {
112112

113113
long routeStartTime = System.currentTimeMillis();
114114
// 根据参数判断是否初始化路由,默认初始化路由
115-
if (!EnvironmentUtils.getBoolean(ConfigKeys.TIO_NO_SERVER, false)) {
115+
if (!EnvironmentUtils.getBoolean(TioBootConfigKeys.TIO_NO_SERVER, false)) {
116116
if (tioBootHttpRoutes != null) {
117117
ControllerFactory aopFactory = new AopControllerFactory();
118118
tioBootHttpRoutes.addRoutes(scannedClasses, aopFactory);
@@ -124,7 +124,7 @@ public Context run(Class<?>[] primarySources, String[] args) {
124124
scanClassEndTime - scanClassStartTime, serverEndTime - serverStartTime, configEndTimeTime - configStartTime,
125125
routeEndTime - routeStartTime);
126126

127-
if (!EnvironmentUtils.getBoolean(ConfigKeys.TIO_NO_SERVER, false)) {
127+
if (!EnvironmentUtils.getBoolean(TioBootConfigKeys.TIO_NO_SERVER, false)) {
128128
printUrl(port, contextPath);
129129
}
130130

@@ -162,7 +162,7 @@ private void configAndStartServer(Class<?>[] primarySources, String[] args, int
162162
TioBootHttpRoutes tioBootHttpRoutes) {
163163
TioBootServer tioBootServer = TioBootServer.me();
164164
HttpConfig httpConfig = configHttp(port, contextPath);
165-
httpConfig.setBindIp(EnvironmentUtils.get(ConfigKeys.SERVER_ADDRESS));
165+
httpConfig.setBindIp(EnvironmentUtils.get(TioBootConfigKeys.SERVER_ADDRESS));
166166

167167
// 第二个参数也可以是数组,自动配置扫描handler的路径
168168
ConcurrentMapCacheFactory cacheFactory = ConcurrentMapCacheFactory.INSTANCE;
@@ -298,7 +298,7 @@ public TioServer getServer() {
298298

299299
private HttpConfig configHttp(int port, String contextPath) {
300300
// html/css/js等的根目录,支持classpath:,也支持绝对路径
301-
String pageRoot = EnvironmentUtils.get(ConfigKeys.SERVER_RESOURCES_STATIC_LOCATIONS, "classpath:/pages");
301+
String pageRoot = EnvironmentUtils.get(TioBootConfigKeys.SERVER_RESOURCES_STATIC_LOCATIONS, "classpath:/pages");
302302
// httpConfig
303303
HttpConfig httpConfig = new HttpConfig(port, null, contextPath, null);
304304

@@ -309,9 +309,9 @@ private HttpConfig configHttp(int port, String contextPath) {
309309
}
310310

311311
// maxLiveTimeOfStaticRes
312-
Integer maxLiveTimeOfStaticRes = EnvironmentUtils.getInt(ConfigKeys.HTTP_MAX_LIVE_TIME_OF_STATIC_RES);
313-
String page404 = EnvironmentUtils.get(ConfigKeys.SERVER_404);
314-
String page500 = EnvironmentUtils.get(ConfigKeys.SERVER_500);
312+
Integer maxLiveTimeOfStaticRes = EnvironmentUtils.getInt(TioBootConfigKeys.HTTP_MAX_LIVE_TIME_OF_STATIC_RES);
313+
String page404 = EnvironmentUtils.get(TioBootConfigKeys.SERVER_404);
314+
String page500 = EnvironmentUtils.get(TioBootConfigKeys.SERVER_500);
315315
if (maxLiveTimeOfStaticRes != null) {
316316
httpConfig.setMaxLiveTimeOfStaticRes(maxLiveTimeOfStaticRes);
317317
}
@@ -322,23 +322,23 @@ private HttpConfig configHttp(int port, String contextPath) {
322322
httpConfig.setPage500(page500);
323323
});
324324

325-
httpConfig.setUseSession(EnvironmentUtils.getBoolean(ConfigKeys.HTTP_ENABLE_SESSION, true));
326-
httpConfig.setCheckHost(EnvironmentUtils.getBoolean(ConfigKeys.HTTP_CHECK_HOST, false));
325+
httpConfig.setUseSession(EnvironmentUtils.getBoolean(TioBootConfigKeys.HTTP_ENABLE_SESSION, true));
326+
httpConfig.setCheckHost(EnvironmentUtils.getBoolean(TioBootConfigKeys.HTTP_CHECK_HOST, false));
327327
// httpMultipartMaxRequestZize
328-
Integer httpMultipartMaxRequestZize = EnvironmentUtils.getInt(ConfigKeys.HTTP_MULTIPART_MAX_REQUEST_SIZE);
328+
Integer httpMultipartMaxRequestZize = EnvironmentUtils.getInt(TioBootConfigKeys.HTTP_MULTIPART_MAX_REQUEST_SIZE);
329329
Optional.ofNullable(httpMultipartMaxRequestZize).ifPresent((t) -> {
330330
httpConfig.setMaxLengthOfPostBody(httpMultipartMaxRequestZize);
331331
log.info("set httpMultipartMaxRequestZize:{}", httpMultipartMaxRequestZize);
332332
});
333333

334334
// httpMultipartMaxFileZize
335-
Integer httpMultipartMaxFileZize = EnvironmentUtils.getInt(ConfigKeys.HTTP_MULTIPART_MAX_FILE_ZIZE);
335+
Integer httpMultipartMaxFileZize = EnvironmentUtils.getInt(TioBootConfigKeys.HTTP_MULTIPART_MAX_FILE_ZIZE);
336336
Optional.ofNullable(httpMultipartMaxFileZize).ifPresent((t) -> {
337337
httpConfig.setMaxLengthOfMultiBody(httpMultipartMaxFileZize);
338338
log.info("set httpMultipartMaxFileZize:{}", httpMultipartMaxFileZize);
339339
});
340340

341-
if (EnvironmentUtils.getBoolean(ConfigKeys.HTTP_ENABLE_REQUEST_LIMIT, true)) {
341+
if (EnvironmentUtils.getBoolean(TioBootConfigKeys.HTTP_ENABLE_REQUEST_LIMIT, true)) {
342342
httpConfig.setSessionRateLimiter(new TioServerSessionRateLimiter());
343343
}
344344
return httpConfig;

src/main/java/com/litongjava/tio/boot/http/handler/DefaultHttpRequestHandlerDispather.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.apache.commons.io.monitor.FileAlterationObserver;
1616

1717
import com.esotericsoftware.reflectasm.MethodAccess;
18+
import com.litongjava.tio.boot.constatns.TioBootConfigKeys;
1819
import com.litongjava.tio.boot.exception.TioBootExceptionHandler;
1920
import com.litongjava.tio.boot.http.TioControllerContext;
2021
import com.litongjava.tio.boot.http.interceptor.DefaultHttpServerInterceptorDispatcher;
@@ -321,6 +322,10 @@ public HttpResponse handler(HttpRequest request) throws Exception {
321322
return resp500(request, requestLine, e);// Resps.html(request, "500--服务器出了点故障", httpConfig.getCharset());
322323
} finally {
323324
TioControllerContext.release();
325+
// print url
326+
if (EnvironmentUtils.getBoolean(TioBootConfigKeys.TIO_HTTP_REQUEST_PRINT_URL)) {
327+
System.out.println(path);
328+
}
324329
try {
325330
long time = SystemTimer.currTime;
326331
long iv = time - start; // 本次请求消耗的时间,单位:毫秒
@@ -676,8 +681,8 @@ private boolean statTokenPath(HttpRequest request, HttpResponse response, String
676681
private void logError(HttpRequest request, RequestLine requestLine, Throwable e) {
677682
TioBootExceptionHandler exceptionHandler = TioBootServer.me().getExceptionHandler();
678683
if (exceptionHandler != null) {
679-
exceptionHandler.handler(request,e);
680-
}else {
684+
exceptionHandler.handler(request, e);
685+
} else {
681686
StringBuilder sb = new StringBuilder();
682687
sb.append(SysConst.CRLF).append("remote :").append(request.getClientIp());
683688
sb.append(SysConst.CRLF).append("request :").append(requestLine.toString());

src/main/java/com/litongjava/tio/boot/http/handler/FileChangeListener.java

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,3 @@
1-
/*
2-
* Apache License Version 2.0, January 2004 http://www.apache.org/licenses/
3-
*
4-
* TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
5-
*
6-
* 1. Definitions.
7-
*
8-
* "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
9-
*
10-
* "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
11-
*
12-
* "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
13-
*
14-
* "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
15-
*
16-
* "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
17-
*
18-
* "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
19-
*
20-
* "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
21-
*
22-
* "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
23-
*
24-
* "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
25-
*
26-
* "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
27-
*
28-
* 2. Grant of Copyright License.
29-
*
30-
* Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
31-
*
32-
* 3. Grant of Patent License.
33-
*
34-
* Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
35-
*
36-
* 4. Redistribution.
37-
*
38-
* You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
39-
*
40-
* You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works,
41-
* if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
42-
*
43-
* 5. Submission of Contributions.
44-
*
45-
* Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
46-
*
47-
* 6. Trademarks.
48-
*
49-
* This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
50-
*
51-
* 7. Disclaimer of Warranty.
52-
*
53-
* Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
54-
*
55-
* 8. Limitation of Liability.
56-
*
57-
* In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
58-
*
59-
* 9. Accepting Warranty or Additional Liability.
60-
*
61-
* While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
62-
*
63-
* END OF TERMS AND CONDITIONS
64-
*
65-
* APPENDIX: How to apply the Apache License to your work
66-
*
67-
* To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
68-
*
69-
* Copyright 2020 t-io
70-
*
71-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
72-
*
73-
* http://www.apache.org/licenses/LICENSE-2.0
74-
*
75-
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
76-
*/
771
package com.litongjava.tio.boot.http.handler;
782

793
import java.io.File;

src/main/java/com/litongjava/tio/boot/http/handler/TioServerSessionRateLimiter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.util.concurrent.atomic.AtomicInteger;
44

5-
import com.litongjava.tio.boot.constatns.ConfigKeys;
5+
import com.litongjava.tio.boot.constatns.TioBootConfigKeys;
66
import com.litongjava.tio.http.common.HttpRequest;
77
import com.litongjava.tio.http.common.HttpResponse;
88
import com.litongjava.tio.http.common.session.limiter.SessionRateLimiter;
@@ -12,7 +12,7 @@
1212

1313
public class TioServerSessionRateLimiter implements SessionRateLimiter {
1414

15-
private static final int MAX_REQUESTS_PER_SECOND = EnvironmentUtils.getInt(ConfigKeys.HTTP_MAX_REQUESTS_PER_SECOND,
15+
private static final int MAX_REQUESTS_PER_SECOND = EnvironmentUtils.getInt(TioBootConfigKeys.HTTP_MAX_REQUESTS_PER_SECOND,
1616
10);
1717

1818
@Override

0 commit comments

Comments
 (0)