diff --git a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/router/DefaultHttpRouter.java b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/router/DefaultHttpRouter.java index fb532b54..184b9b26 100644 --- a/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/router/DefaultHttpRouter.java +++ b/neutrino-core/src/main/java/fun/asgc/neutrino/core/web/router/DefaultHttpRouter.java @@ -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; } diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTestForSqlite.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTestForSqlite.java index 4af1102e..146ba19e 100644 --- a/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTestForSqlite.java +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/db/template/JdbcTemplateTestForSqlite.java @@ -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); } diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/util/FileUtilTest.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/util/FileUtilTest.java new file mode 100644 index 00000000..1f3adc04 --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/util/FileUtilTest.java @@ -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()); + } +} diff --git a/neutrino-core/src/test/java/fun/asgc/neutrino/core/web/test1/Launcher.java b/neutrino-core/src/test/java/fun/asgc/neutrino/core/web/test1/Launcher.java new file mode 100644 index 00000000..a2293018 --- /dev/null +++ b/neutrino-core/src/test/java/fun/asgc/neutrino/core/web/test1/Launcher.java @@ -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); + } + +} diff --git a/neutrino-core/src/test/resources/application.yml b/neutrino-core/src/test/resources/application.yml index b8898cc2..8b4c35e4 100644 --- a/neutrino-core/src/test/resources/application.yml +++ b/neutrino-core/src/test/resources/application.yml @@ -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/" diff --git a/neutrino-core/sqlite.db b/neutrino-core/src/test/resources/sqlite.db similarity index 100% rename from neutrino-core/sqlite.db rename to neutrino-core/src/test/resources/sqlite.db diff --git a/neutrino-core/src/test/resources/static/favicon.ico b/neutrino-core/src/test/resources/static/favicon.ico new file mode 100644 index 00000000..474afb8c Binary files /dev/null and b/neutrino-core/src/test/resources/static/favicon.ico differ diff --git a/neutrino-core/src/test/resources/static/js/test.js b/neutrino-core/src/test/resources/static/js/test.js new file mode 100644 index 00000000..37b5d1e4 --- /dev/null +++ b/neutrino-core/src/test/resources/static/js/test.js @@ -0,0 +1,3 @@ +function hello() { + alert("hello"); +} diff --git a/neutrino-core/src/test/resources/template/index.html b/neutrino-core/src/test/resources/template/index.html new file mode 100644 index 00000000..0450a6c8 --- /dev/null +++ b/neutrino-core/src/test/resources/template/index.html @@ -0,0 +1,12 @@ + +
+