针对http请求前置处理优化.

This commit is contained in:
aoshiguchen
2022-07-23 12:35:13 +08:00
parent 7d8f7d1480
commit dfa5a61258
9 changed files with 120 additions and 5 deletions
@@ -37,6 +37,7 @@ import fun.asgc.neutrino.core.web.annotation.RequestMapping;
import fun.asgc.neutrino.core.web.annotation.RestController;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.util.List;
@@ -234,9 +235,13 @@ public class DefaultHttpRouter implements HttpRouter {
ApplicationConfig.StaticResource staticResource = applicationConfig.getHttp().getStaticResource();
if (null != staticResource && CollectionUtil.notEmpty(staticResource.getLocations())) {
for (String location : staticResource.getLocations()) {
try (InputStream in = FileUtil.getInputStream(location + httpRouteParam.getUrl())){
String path = location + httpRouteParam.getUrl();
if (path.endsWith("/")) {
path += "index.html";
}
try (InputStream in = FileUtil.getInputStream(path)){
if (null != in) {
addRoute(httpRouteParam.getUrl(), location + httpRouteParam.getUrl());
addRoute(httpRouteParam.getUrl(), path);
httpRouteInfo = routeCache.get(identity);
break;
}
@@ -40,7 +40,7 @@ public class JdbcTemplateTestForSqlite {
{
DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:sqlite:sqlite.db");
dataSource.setUrl("jdbc:sqlite:" + JdbcTemplateTestForSqlite.class.getResource("/sqlite.db").getPath());
dataSource.setDriverClassName("org.sqlite.JDBC");
jdbcTemplate = new JdbcTemplate(dataSource);
}
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2022 aoshiguchen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package fun.asgc.neutrino.core.util;
import org.junit.Test;
import java.io.File;
import java.net.MalformedURLException;
/**
*
* @author: wen.y
* @date: 2022/7/23
*/
public class FileUtilTest {
@Test
public void test1() throws MalformedURLException {
// URL url = FileUtilTest.class.getResource("/tpl/AsgcProxy.tpl");
File url = new File("jar:file:/Users/yangwen/tmp/neutrino-core-1.0-SNAPSHOT.jar!/tpl/AsgcProxy.tpl");
System.out.println(url);
}
@Test
public void test2() {
System.out.println(FileUtilTest.class.getResource("").getProtocol());
}
}
@@ -0,0 +1,39 @@
/**
* Copyright (c) 2022 aoshiguchen
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package fun.asgc.neutrino.core.web.test1;
import fun.asgc.neutrino.core.annotation.NeutrinoApplication;
import fun.asgc.neutrino.core.context.NeutrinoLauncher;
/**
*
* @author: aoshiguchen
* @date: 2022/7/23
*/
@NeutrinoApplication
public class Launcher {
public static void main(String[] args) {
NeutrinoLauncher.runSync(Launcher.class, args);
}
}
@@ -1,2 +1,12 @@
application:
name: neutrino-core-test
neutrino:
application:
name: neutrino-proxy-server
http:
enable: true
port: 8080
context-path: /test
max-content-length-desc: 128K
static-resource:
locations:
- "classpath:/static/"
- "classpath:/template/"
Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

@@ -0,0 +1,3 @@
function hello() {
alert("hello");
}
@@ -0,0 +1,12 @@
<html>
<head>
<title>测试页面</title>
<script type="application/javascript" src="js/test.js"></script>
<script type="application/javascript">
hello();
</script>
</head>
<body>
<h2>hello,欢迎来到<span stype="color:red;">中微子代理</span></h2>
</body>
</html>