├── src ├── test │ ├── resources │ │ ├── application-dev.yml │ │ ├── 404.html │ │ ├── index.html │ │ ├── templates │ │ │ ├── index.peb │ │ │ └── index.html │ │ └── application.yml │ └── java │ │ └── example │ │ ├── bean │ │ ├── User2.java │ │ └── User3.java │ │ ├── route │ │ └── IndexRoute.java │ │ ├── Main.java │ │ ├── config │ │ ├── UserConfig.java │ │ └── ConfigProperty.java │ │ ├── advice │ │ └── NullAdvice.java │ │ └── ws │ │ ├── WebSocketClient.java │ │ └── WebSocketActionWrapper.java └── main │ ├── resources │ └── logback.xml │ └── java │ └── org │ └── aquiver │ ├── ViewHandlerType.java │ ├── mvc │ ├── router │ │ ├── views │ │ │ ├── ViewType.java │ │ │ ├── HTMLView.java │ │ │ └── PebbleHTMLView.java │ │ ├── Router.java │ │ ├── session │ │ │ └── Session.java │ │ └── PathVarMatcher.java │ ├── http │ │ ├── HttpMethod.java │ │ ├── HttpConst.java │ │ ├── Header.java │ │ ├── Headers.java │ │ └── Cookies.java │ ├── interceptor │ │ ├── InterceptorChain.java │ │ ├── Interceptor.java │ │ └── AspectInterceptor.java │ ├── argument │ │ ├── TypeArgumentGetter.java │ │ ├── AnnotationArgumentGetter.java │ │ ├── ArgumentGetter.java │ │ ├── BodyArgumentGetter.java │ │ ├── GetterResolver.java │ │ ├── RequestContextArgumentGetter.java │ │ ├── ResponseArgumentGetter.java │ │ ├── SessionArgumentGetter.java │ │ ├── RequestArgumentGetter.java │ │ ├── PathVarArgumentGetter.java │ │ ├── WebSocketContextArgumentGetter.java │ │ ├── ThrowableArgumentGetter.java │ │ ├── MultipartFileArgumentGetter.java │ │ ├── CookiesArgumentGetter.java │ │ ├── HeaderArgumentGetter.java │ │ ├── ArgumentContext.java │ │ ├── FileUploadArgumentGetter.java │ │ ├── ParamArgumentGetter.java │ │ └── MultiFileUploadArgumentGetter.java │ ├── handler │ │ ├── RouteAdviceHandler.java │ │ └── RouteAdviceHandlerResolver.java │ ├── annotation │ │ ├── JSON.java │ │ ├── RestPath.java │ │ ├── bind │ │ │ ├── Cookies.java │ │ │ ├── PathVar.java │ │ │ ├── Body.java │ │ │ ├── Header.java │ │ │ ├── FileUpload.java │ │ │ ├── MultiFileUpload.java │ │ │ └── Param.java │ │ ├── RouteAdvice.java │ │ ├── View.java │ │ ├── Status.java │ │ ├── HandleAdvice.java │ │ ├── Path.java │ │ ├── Get.java │ │ ├── Put.java │ │ ├── Head.java │ │ ├── Post.java │ │ ├── Delete.java │ │ ├── Patch.java │ │ ├── Trace.java │ │ └── Options.java │ ├── result │ │ ├── view │ │ │ ├── RedirectViewHandler.java │ │ │ ├── CssDataViewHandler.java │ │ │ ├── XmlDataViewHandler.java │ │ │ ├── HtmlDataViewHandler.java │ │ │ ├── AbstractDataViewHandler.java │ │ │ ├── PebbleTemplateViewHandler.java │ │ │ ├── AbstractTemplateViewHandler.java │ │ │ └── HtmlTemplateViewHandler.java │ │ ├── VoidResultHandler.java │ │ ├── ModelAndViewResultHandler.java │ │ └── JsonResultHandler.java │ ├── cors │ │ └── ConstantValueSupplier.java │ └── RequestResult.java │ ├── common │ ├── banner │ │ ├── Banner.java │ │ ├── BannerFont.java │ │ ├── BannerTemplate.java │ │ └── SimpleBanner.java │ ├── ansi │ │ ├── AnsiElement.java │ │ ├── logback │ │ │ ├── ProcessIdClassicConverter.java │ │ │ └── LogBackAnsiConverter.java │ │ ├── AnsiColor.java │ │ └── AnsiBackground.java │ └── watcher │ │ ├── WatcherListener.java │ │ └── GlobalEnvListener.java │ ├── urls │ └── BypassRequestUrls.java │ ├── ResultHandler.java │ ├── RequestHandler.java │ ├── websocket │ ├── WebSocketChannel.java │ ├── action │ │ ├── OnError.java │ │ ├── OnClose.java │ │ ├── OnConnect.java │ │ └── OnMessage.java │ └── WebSocket.java │ ├── ViewHandler.java │ ├── RequestChannel.java │ ├── NoRouteFoundException.java │ ├── server │ ├── Server.java │ └── netty │ │ └── NettyThreadFactory.java │ ├── Response.java │ ├── ReflectionHelper.java │ ├── ModelAndView.java │ ├── RouteRepeatException.java │ └── Request.java ├── .gitignore ├── code-style.xml ├── .github └── workflows │ └── maven.yml ├── LICENSE └── README.md /src/test/resources/application-dev.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8081 -------------------------------------------------------------------------------- /src/test/resources/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Document 5 | 6 | 7 | 404 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Document 5 | 6 | 7 | index {{name}} 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/templates/index.peb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Document 5 | 6 | 7 | index peb 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Document 5 | 6 | 7 | index templates 8 | 9 | -------------------------------------------------------------------------------- /src/test/resources/application.yml: -------------------------------------------------------------------------------- 1 | config: 2 | test: 3 | age: 1 4 | name: wangyi 5 | height: 180 6 | weight: 190 7 | list[0]: /root 8 | list[1]: /home/user1 9 | list[2]: /home/user2 10 | list[3]: /home/user3 11 | map: 12 | key1: value1 13 | key2: value2 14 | key3: value3 15 | key4: value4 16 | key5: ${key1}/${key2} 17 | 18 | server: 19 | profile: test -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.nar 17 | *.ear 18 | *.zip 19 | *.tar.gz 20 | *.rar 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | /target/ 25 | /aquiver.iml 26 | /.idea/ 27 | -------------------------------------------------------------------------------- /code-style.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ${{ matrix.os }} 8 | strategy: 9 | matrix: 10 | os: [ubuntu-latest, windows-latest, macOS-latest] 11 | 12 | steps: 13 | - uses: actions/checkout@v1 14 | - name: Set up JDK 1.8 15 | uses: actions/setup-java@v1 16 | with: 17 | java-version: 1.8 18 | - name: Build with Maven 19 | run: | 20 | git clone https://github.com/AquiverV/apex.git 21 | cd ./apex 22 | mvn install 23 | git clone https://github.com/AquiverV/aquiver.git 24 | cd ./aquiver 25 | mvn install 26 | cd ../ 27 | mvn package -DskipTests=true 28 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 8 | 9 | 10 | 12 | 13 | 14 | 15 | ${org.aquiver.logger.console.pattern:-${STDOUT_PATTERN}} 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 1619kHz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/ViewHandlerType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver; 25 | 26 | /** 27 | * @author i1619kHz 28 | */ 29 | public enum ViewHandlerType { 30 | TEMPLATE_VIEW, DATA_VIEW 31 | } -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/router/views/ViewType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.router.views; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2020/6/17 29 | */ 30 | public enum ViewType { 31 | JSON, TEXT, HTML 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/http/HttpMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.http; 25 | 26 | public enum HttpMethod { 27 | GET, 28 | HEAD, 29 | POST, 30 | PUT, 31 | PATCH, 32 | DELETE, 33 | OPTIONS, 34 | TRACE 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/common/banner/Banner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.common.banner; 25 | 26 | import java.io.PrintStream; 27 | 28 | public interface Banner { 29 | void printBanner(PrintStream printStream, String bannerText, String bannerFont); 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/interceptor/InterceptorChain.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.interceptor; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2020/8/26 29 | */ 30 | public interface InterceptorChain { 31 | void invoke() throws Throwable; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/common/ansi/AnsiElement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.common.ansi; 25 | 26 | /** 27 | * @author WangYi 28 | * @version 1.0 29 | * @since 2019/1/16 30 | */ 31 | public interface AnsiElement { 32 | 33 | @Override 34 | String toString(); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/TypeArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2020/8/26 29 | */ 30 | public interface TypeArgumentGetter extends ArgumentGetter { 31 | boolean support(Class cls); 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/AnnotationArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2020/8/26 29 | */ 30 | public interface AnnotationArgumentGetter { 31 | Object get(ArgumentContext context) throws Exception; 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/urls/BypassRequestUrls.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.urls; 25 | 26 | import org.aquiver.Request; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/8/17 31 | */ 32 | public interface BypassRequestUrls { 33 | boolean accept(Request request, String path); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/handler/RouteAdviceHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.handler; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2020/8/29 29 | */ 30 | @FunctionalInterface 31 | public interface RouteAdviceHandler { 32 | void handle(Throwable throwable) throws Exception; 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/common/watcher/WatcherListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.common.watcher; 25 | 26 | import java.nio.file.Path; 27 | 28 | public interface WatcherListener { 29 | 30 | void onCreate(Path file); 31 | 32 | void onModify(Path file); 33 | 34 | void onDelete(Path file); 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/ArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/8/26 31 | */ 32 | public interface ArgumentGetter { 33 | T get(RequestContext context) throws Exception; 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/example/bean/User2.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package example.bean; 25 | 26 | import org.apex.annotation.Singleton; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/6/22 31 | */ 32 | @Singleton 33 | public class User2 { 34 | private String aa = "aaa"; 35 | 36 | public String getAa() { 37 | return aa; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Aquiver 2 | 3 |

Aquiver是一个基于Java8和Netty的MVC框架

4 |

5 | Build Status 6 | Build Status 7 | 8 | 9 | 10 | Downloads 11 | 12 |

13 | 14 | ### 快速开始 15 | 16 | 通过 `Maven` 或 `Gradle` 创建项目,因为还未上传到Maven中心仓库,所以目前暂时通过clone代码进行安装 17 | 18 | ```git 19 | git clone https://github.com/AquiverV/apex.git 20 | 21 | cd apex 22 | 23 | mvn clean install 24 | 25 | git clone https://github.com/AquiverV/aquiver.git 26 | 27 | cd aquiver 28 | 29 | mvn clean install 30 | ``` 31 | 32 | 在 `Maven` 中使用: 33 | 34 | ```xml 35 | 36 | org.aquiver 37 | aquiver 38 | 1.0.3.BETA 39 | 40 | ``` 41 | 42 | #### 尝试 43 | 44 | ```java 45 | public class Main { 46 | public static void main(String[] args) { 47 | Aquiver.of().bind(9999).get("/", ctx -> { 48 | Object username = ctx.param("username"); 49 | System.out.println(paramName); 50 | }).start(Main.class, args); 51 | } 52 | } 53 | ``` 54 | 在浏览器打开:`http://localhost:9999/?username=1619kHz` 查看效果 55 | 56 | ## License 57 | [MIT](https://opensource.org/licenses/MIT "MIT") 58 | 59 | Copyright (c) 2020-present, Yi (Ever) Wang 60 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/common/banner/BannerFont.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.common.banner; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2019/5/24 29 | */ 30 | public interface BannerFont { 31 | String FONT_3_D = "3-D"; 32 | String FONT_3D_ASCII = "3D-ASCII"; 33 | String FONT_3D_DIAGONAL = "3D_Diagonal"; 34 | String FONT_DEFAULT = "Standard"; 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/ResultHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver; 25 | 26 | import org.aquiver.mvc.RequestResult; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/8/22 31 | */ 32 | public interface ResultHandler { 33 | boolean support(RequestResult requestResult); 34 | 35 | void handle(RequestContext ctx, RequestResult result) throws Exception; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/interceptor/Interceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.interceptor; 25 | 26 | import org.aquiver.RequestContext; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/8/26 31 | */ 32 | public interface Interceptor { 33 | void initialize(); 34 | 35 | void intercept(RequestContext ctx, InterceptorChain chain) throws Throwable; 36 | 37 | void destroy(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/RequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2020/6/12 29 | */ 30 | public interface RequestHandler { 31 | /** 32 | * Handling routing 33 | * 34 | * @param context Request context 35 | * @throws Exception Exceptions that may be thrown 36 | */ 37 | void handle(RequestContext context) throws Exception; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/JSON.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | @Target({ElementType.METHOD}) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Documented 35 | public @interface JSON { 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/websocket/WebSocketChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.websocket; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2020/7/11 29 | */ 30 | public interface WebSocketChannel { 31 | void onConnect(WebSocketContext webSocketContext); 32 | 33 | void onMessage(WebSocketContext webSocketContext); 34 | 35 | void onClose(WebSocketContext webSocketContext); 36 | 37 | void onError(WebSocketContext webSocketContext); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/ViewHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2020/8/22 29 | */ 30 | public interface ViewHandler { 31 | String getType(); 32 | 33 | void render(RequestContext ctx, String viewPathName) throws Exception; 34 | 35 | default String getSuffix() { 36 | return null; 37 | } 38 | 39 | default ViewHandlerType getHandlerType() { 40 | return ViewHandlerType.DATA_VIEW; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/example/route/IndexRoute.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package example.route; 25 | 26 | import org.aquiver.mvc.annotation.Get; 27 | import org.aquiver.mvc.annotation.RestPath; 28 | 29 | /** 30 | * @author WangYi 31 | * @since 2020/6/22 32 | */ 33 | @RestPath("/index") 34 | public class IndexRoute { 35 | 36 | @Get("/index") 37 | public String index() { 38 | return "index"; 39 | } 40 | 41 | 42 | @Get 43 | public String get() { 44 | return "get"; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/example/Main.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package example; 25 | 26 | import org.aquiver.Aquiver; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/6/16 31 | */ 32 | public class Main { 33 | public static void main(String[] args) { 34 | Aquiver.of().bind(9999) 35 | .get("/", ctx -> { 36 | Object paramName = ctx.param("paramName"); 37 | System.out.println(paramName); 38 | }) 39 | .start(Main.class, args); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/RestPath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | @Target({ElementType.TYPE}) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Documented 35 | public @interface RestPath { 36 | String value() default ""; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/bind/Cookies.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation.bind; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | @Target(ElementType.PARAMETER) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Documented 35 | public @interface Cookies { 36 | String value() default ""; 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/router/Router.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.router; 25 | 26 | import org.aquiver.RequestHandler; 27 | import org.aquiver.mvc.http.HttpMethod; 28 | 29 | /** 30 | * @author WangYi 31 | * @since 2020/8/28 32 | */ 33 | public interface Router { 34 | void registerRoute(String path, Object object) throws Exception; 35 | 36 | void registerRoute(String path, RequestHandler handler, HttpMethod httpMethod) throws Exception; 37 | 38 | RouteInfo lookup(String url); 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/bind/PathVar.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation.bind; 25 | 26 | 27 | import java.lang.annotation.Documented; 28 | import java.lang.annotation.ElementType; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.RetentionPolicy; 31 | import java.lang.annotation.Target; 32 | 33 | @Target(ElementType.PARAMETER) 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @Documented 36 | public @interface PathVar { 37 | String value() default ""; 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/bind/Body.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation.bind; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | 33 | @Target(ElementType.PARAMETER) 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @Documented 36 | public @interface Body { 37 | 38 | String value() default ""; 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/RouteAdvice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/7/1 35 | */ 36 | @Target(ElementType.TYPE) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface RouteAdvice {} 40 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/View.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/6/16 35 | */ 36 | @Target(ElementType.METHOD) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface View { 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/websocket/action/OnError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.websocket.action; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/7/11 35 | */ 36 | @Target({ElementType.METHOD}) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface OnError { 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/BodyArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/8/26 31 | */ 32 | public final class BodyArgumentGetter implements AnnotationArgumentGetter { 33 | 34 | @Override 35 | public Object get(ArgumentContext context) throws Exception { 36 | RequestContext requestContext = context.getContext(); 37 | return requestContext.body(context.getParameter().getType()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/websocket/action/OnClose.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.websocket.action; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/7/11 35 | */ 36 | @Target({ElementType.METHOD}) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface OnClose { 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/websocket/action/OnConnect.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.websocket.action; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/7/11 35 | */ 36 | @Target({ElementType.METHOD}) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface OnConnect { 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/websocket/action/OnMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.websocket.action; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/7/11 35 | */ 36 | @Target({ElementType.METHOD}) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface OnMessage { 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/RequestChannel.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * MIT License 4 | * 5 | * Copyright (c) 2019 1619kHz 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy 8 | * of this software and associated documentation files (the "Software"), to deal 9 | * in the Software without restriction, including without limitation the rights 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | * copies of the Software, and to permit persons to whom the Software is 12 | * furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included in all 15 | * copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | * SOFTWARE. 24 | */ 25 | package org.aquiver; 26 | 27 | import io.netty.channel.ChannelHandlerContext; 28 | 29 | /** 30 | * @author WangYi 31 | * @since 2020/10/20 32 | */ 33 | public interface RequestChannel { 34 | ChannelHandlerContext nettyContext(); 35 | 36 | void closeChannel(); 37 | 38 | boolean isOpen(); 39 | 40 | boolean isRegistered(); 41 | 42 | boolean isActive(); 43 | 44 | boolean isWritable(); 45 | 46 | long bytesBeforeUnwritable(); 47 | 48 | long bytesBeforeWritable(); 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/common/ansi/logback/ProcessIdClassicConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.common.ansi.logback; 25 | 26 | import ch.qos.logback.classic.pattern.ClassicConverter; 27 | import ch.qos.logback.classic.spi.ILoggingEvent; 28 | 29 | import java.lang.management.ManagementFactory; 30 | 31 | public class ProcessIdClassicConverter extends ClassicConverter { 32 | 33 | @Override 34 | public String convert(ILoggingEvent iLoggingEvent) { 35 | return ManagementFactory.getRuntimeMXBean().getName().split("@")[0]; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/GetterResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.apex.ApexContext; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/8/26 31 | */ 32 | public interface GetterResolver { 33 | void init(); 34 | 35 | void registerArgumentGetter(Class bindClass, Class argumentClass); 36 | 37 | R lookup(Class bindClass) throws IllegalAccessException, InstantiationException; 38 | 39 | default ApexContext apexContext() { 40 | return ApexContext.of(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/websocket/WebSocket.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.websocket; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/7/11 35 | */ 36 | @Target({ElementType.TYPE}) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface WebSocket { 40 | String value() default ""; 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/Status.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/8/22 35 | */ 36 | @Target({ElementType.METHOD}) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface Status { 40 | int value() default 200; 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/http/HttpConst.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.http; 25 | 26 | import io.netty.handler.codec.http.HttpHeaderNames; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/10/20 31 | */ 32 | public interface HttpConst { 33 | String ACCEPT = HttpHeaderNames.ACCEPT.toString(); 34 | String USER_AGENT = HttpHeaderNames.USER_AGENT.toString(); 35 | String REFERER = HttpHeaderNames.REFERER.toString(); 36 | String CONNECTION = HttpHeaderNames.CONNECTION.toString(); 37 | String HOST = HttpHeaderNames.HOST.toString(); 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/NoRouteFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2020/5/29 29 | */ 30 | public class NoRouteFoundException extends RuntimeException { 31 | /** 32 | * Constructor for NoRouteFoundException. 33 | * 34 | * @param httpMethod the HTTP method 35 | * @param requestURL the HTTP request URL 36 | */ 37 | public NoRouteFoundException(String httpMethod, String requestURL) { 38 | super(String.format("No handler found for %s %s", httpMethod, requestURL)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/bind/Header.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation.bind; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | 33 | @Target(ElementType.PARAMETER) 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @Documented 36 | public @interface Header { 37 | 38 | String value() default ""; 39 | 40 | boolean required() default true; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/result/view/RedirectViewHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.result.view; 25 | 26 | import org.aquiver.RequestContext; 27 | import org.aquiver.ViewHandler; 28 | 29 | /** 30 | * @author WangYi 31 | * @since 2020/8/22 32 | */ 33 | public final class RedirectViewHandler implements ViewHandler { 34 | 35 | @Override 36 | public String getType() { 37 | return "redirect"; 38 | } 39 | 40 | @Override 41 | public void render(RequestContext ctx, String viewPathName) { 42 | ctx.redirect(viewPathName); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/HandleAdvice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/7/1 35 | */ 36 | @Target(ElementType.METHOD) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface HandleAdvice { 40 | Class value(); 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/bind/FileUpload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation.bind; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/6/14 35 | */ 36 | @Target(ElementType.PARAMETER) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface FileUpload { 40 | String value() default ""; 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/RequestContextArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/8/26 31 | */ 32 | public final class RequestContextArgumentGetter implements TypeArgumentGetter { 33 | @Override 34 | public RequestContext get(RequestContext context) { 35 | return context; 36 | } 37 | 38 | @Override 39 | public boolean support(Class cls) { 40 | return cls.isAssignableFrom(RequestContext.class); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/bind/MultiFileUpload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation.bind; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/6/14 35 | */ 36 | @Target(ElementType.PARAMETER) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | public @interface MultiFileUpload { 40 | String value() default ""; 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/bind/Param.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation.bind; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.ElementType; 28 | import java.lang.annotation.Retention; 29 | import java.lang.annotation.RetentionPolicy; 30 | import java.lang.annotation.Target; 31 | 32 | @Target(ElementType.PARAMETER) 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Documented 35 | public @interface Param { 36 | String value() default ""; 37 | 38 | String defaultValue() default ""; 39 | 40 | boolean required() default true; 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/ResponseArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | import org.aquiver.Response; 28 | 29 | /** 30 | * @author WangYi 31 | * @since 2020/8/26 32 | */ 33 | public final class ResponseArgumentGetter implements TypeArgumentGetter { 34 | @Override 35 | public Response get(RequestContext context) { 36 | return context.response(); 37 | } 38 | 39 | @Override 40 | public boolean support(Class cls) { 41 | return cls.isAssignableFrom(Response.class); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/Path.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import org.aquiver.mvc.http.HttpMethod; 27 | 28 | import java.lang.annotation.Documented; 29 | import java.lang.annotation.ElementType; 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.RetentionPolicy; 32 | import java.lang.annotation.Target; 33 | 34 | @Target({ElementType.TYPE, ElementType.METHOD}) 35 | @Retention(RetentionPolicy.RUNTIME) 36 | @Documented 37 | public @interface Path { 38 | String value() default ""; 39 | 40 | HttpMethod method() default HttpMethod.GET; 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/SessionArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | import org.aquiver.mvc.router.session.Session; 28 | 29 | /** 30 | * @author WangYi 31 | * @since 2020/8/26 32 | */ 33 | public final class SessionArgumentGetter implements TypeArgumentGetter { 34 | @Override 35 | public Session get(RequestContext context) { 36 | return context.request().session(); 37 | } 38 | 39 | @Override 40 | public boolean support(Class cls) { 41 | return cls.isAssignableFrom(Session.class); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/interceptor/AspectInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.interceptor; 25 | 26 | import org.aquiver.RequestContext; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/8/26 31 | */ 32 | public abstract class AspectInterceptor implements Interceptor { 33 | protected abstract void before(RequestContext context); 34 | 35 | protected abstract void after(RequestContext context); 36 | 37 | @Override 38 | public void intercept(RequestContext ctx, InterceptorChain chain) throws Throwable { 39 | before(ctx); 40 | chain.invoke(); 41 | after(ctx); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/router/views/HTMLView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.router.views; 25 | 26 | import java.io.IOException; 27 | import java.util.Map; 28 | 29 | /** 30 | * @author WangYi 31 | * @since 2020/6/16 32 | */ 33 | public interface HTMLView { 34 | /** 35 | * Get the content of the returned view 36 | * 37 | * @param htmlPath html path 38 | * @param viewParams view render params 39 | * @return the content of the returned view 40 | * @throws IOException io exception 41 | */ 42 | String renderView(String htmlPath, Map viewParams) throws IOException; 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/Get.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import org.aquiver.mvc.http.HttpMethod; 27 | 28 | import java.lang.annotation.Documented; 29 | import java.lang.annotation.ElementType; 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.RetentionPolicy; 32 | import java.lang.annotation.Target; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/5/25 37 | */ 38 | @Target(ElementType.METHOD) 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Documented 41 | @Path(method = HttpMethod.GET) 42 | public @interface Get { 43 | String value() default ""; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/Put.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import org.aquiver.mvc.http.HttpMethod; 27 | 28 | import java.lang.annotation.Documented; 29 | import java.lang.annotation.ElementType; 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.RetentionPolicy; 32 | import java.lang.annotation.Target; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/5/25 37 | */ 38 | @Target(ElementType.METHOD) 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Documented 41 | @Path(method = HttpMethod.PUT) 42 | public @interface Put { 43 | String value() default ""; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/Head.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import org.aquiver.mvc.http.HttpMethod; 27 | 28 | import java.lang.annotation.Documented; 29 | import java.lang.annotation.ElementType; 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.RetentionPolicy; 32 | import java.lang.annotation.Target; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/5/25 37 | */ 38 | @Target(ElementType.METHOD) 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Documented 41 | @Path(method = HttpMethod.HEAD) 42 | public @interface Head { 43 | String value() default ""; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/Post.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import org.aquiver.mvc.http.HttpMethod; 27 | 28 | import java.lang.annotation.Documented; 29 | import java.lang.annotation.ElementType; 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.RetentionPolicy; 32 | import java.lang.annotation.Target; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/5/25 37 | */ 38 | @Target(ElementType.METHOD) 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Documented 41 | @Path(method = HttpMethod.POST) 42 | public @interface Post { 43 | String value() default ""; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/Delete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import org.aquiver.mvc.http.HttpMethod; 27 | 28 | import java.lang.annotation.Documented; 29 | import java.lang.annotation.ElementType; 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.RetentionPolicy; 32 | import java.lang.annotation.Target; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/5/25 37 | */ 38 | @Target(ElementType.METHOD) 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Documented 41 | @Path(method = HttpMethod.DELETE) 42 | public @interface Delete { 43 | String value() default ""; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/Patch.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import org.aquiver.mvc.http.HttpMethod; 27 | 28 | import java.lang.annotation.Documented; 29 | import java.lang.annotation.ElementType; 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.RetentionPolicy; 32 | import java.lang.annotation.Target; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/5/25 37 | */ 38 | @Target(ElementType.METHOD) 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Documented 41 | @Path(method = HttpMethod.PATCH) 42 | public @interface Patch { 43 | String value() default ""; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/Trace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import org.aquiver.mvc.http.HttpMethod; 27 | 28 | import java.lang.annotation.Documented; 29 | import java.lang.annotation.ElementType; 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.RetentionPolicy; 32 | import java.lang.annotation.Target; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/5/25 37 | */ 38 | @Target(ElementType.METHOD) 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Documented 41 | @Path(method = HttpMethod.TRACE) 42 | public @interface Trace { 43 | String value() default ""; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/RequestArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.Request; 27 | import org.aquiver.RequestContext; 28 | import org.aquiver.mvc.http.HttpRequest; 29 | 30 | /** 31 | * @author WangYi 32 | * @since 2020/8/26 33 | */ 34 | public final class RequestArgumentGetter implements TypeArgumentGetter { 35 | 36 | @Override 37 | public Request get(RequestContext context) { 38 | return context.request(); 39 | } 40 | 41 | @Override 42 | public boolean support(Class cls) { 43 | return cls.isAssignableFrom(HttpRequest.class); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/annotation/Options.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.annotation; 25 | 26 | import org.aquiver.mvc.http.HttpMethod; 27 | 28 | import java.lang.annotation.Documented; 29 | import java.lang.annotation.ElementType; 30 | import java.lang.annotation.Retention; 31 | import java.lang.annotation.RetentionPolicy; 32 | import java.lang.annotation.Target; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/5/25 37 | */ 38 | @Target(ElementType.METHOD) 39 | @Retention(RetentionPolicy.RUNTIME) 40 | @Documented 41 | @Path(method = HttpMethod.OPTIONS) 42 | public @interface Options { 43 | String value() default ""; 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/PathVarArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | import org.aquiver.mvc.router.PathVarMatcher; 28 | 29 | /** 30 | * @author WangYi 31 | * @since 2020/8/26 32 | */ 33 | public final class PathVarArgumentGetter implements AnnotationArgumentGetter { 34 | 35 | @Override 36 | public Object get(ArgumentContext context) { 37 | RequestContext requestContext = context.getContext(); 38 | return PathVarMatcher.getPathVariable(requestContext.uri(), 39 | requestContext.routeInfo().getUrl(), context.getParameter().getName()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/common/ansi/AnsiColor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.common.ansi; 25 | 26 | /** 27 | * @author WangYi 28 | * @version 1.0 29 | * @since 2019/1/16 30 | */ 31 | public enum AnsiColor { 32 | RESET("\u001B[0m"), 33 | BLACK("\u001B[30m"), 34 | RED("\u001B[31m"), 35 | GREEN("\u001B[32m"), 36 | YELLOW("\u001B[33m"), 37 | BLUE("\u001B[34m"), 38 | PURPLE("\u001B[35m"), 39 | CYAN("\u001B[36m"), 40 | WHITE("\u001B[37m"); 41 | 42 | private final String code; 43 | 44 | AnsiColor(String code) { 45 | this.code = code; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return this.code; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/WebSocketContextArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | import org.aquiver.websocket.WebSocketContext; 28 | 29 | /** 30 | * @author WangYi 31 | * @since 2020/8/26 32 | */ 33 | public final class WebSocketContextArgumentGetter implements TypeArgumentGetter { 34 | @Override 35 | public WebSocketContext get(RequestContext requestContext) { 36 | return (WebSocketContext) requestContext; 37 | } 38 | 39 | @Override 40 | public boolean support(Class cls) { 41 | return cls.isAssignableFrom(WebSocketContext.class); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/cors/ConstantValueSupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.cors; 25 | 26 | import java.util.function.Supplier; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/10/7 31 | */ 32 | class ConstantValueSupplier implements Supplier { 33 | 34 | static final ConstantValueSupplier ZERO = new ConstantValueSupplier("0"); 35 | 36 | private final Object value; 37 | 38 | ConstantValueSupplier(Object value) { 39 | this.value = value; 40 | } 41 | 42 | @Override 43 | public Object get() { 44 | return value; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return String.valueOf(value); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/server/Server.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.server; 25 | 26 | import org.aquiver.Aquiver; 27 | 28 | /** 29 | * Abstract the common methods of the server in 30 | * order to implement different http servers. 31 | * 32 | * @author WangYi 33 | * @since 2020/6/25 34 | */ 35 | public interface Server { 36 | /** 37 | * start server and init setting 38 | * 39 | * @param aquiver Aquiver 40 | * @throws Exception Common Exception 41 | */ 42 | void start(Aquiver aquiver) throws Exception; 43 | 44 | /** 45 | * stop http server 46 | */ 47 | void stop(); 48 | 49 | /** 50 | * join http server 51 | */ 52 | void join(); 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/example/config/UserConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package example.config; 25 | 26 | import example.bean.User3; 27 | import org.apex.annotation.Bean; 28 | import org.apex.annotation.ConfigBean; 29 | 30 | /** 31 | * @author WangYi 32 | * @since 2020/7/24 33 | */ 34 | @ConfigBean 35 | public class UserConfig { 36 | 37 | @Bean 38 | public User3 user3() { 39 | User3 user = new User3(); 40 | user.setPassword("111"); 41 | user.setUsername("admin"); 42 | return user; 43 | } 44 | 45 | @Bean 46 | public User3 user4() { 47 | User3 user = new User3(); 48 | user.setPassword("111"); 49 | user.setUsername("admin"); 50 | return user; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/router/session/Session.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.router.session; 25 | 26 | import io.netty.channel.ChannelHandlerContext; 27 | 28 | import java.util.List; 29 | 30 | /** 31 | * @author WangYi 32 | * @since 2020/6/19 33 | */ 34 | public interface Session { 35 | ChannelHandlerContext channelHandlerContext(); 36 | 37 | long getCreationTime(); 38 | 39 | String getId(); 40 | 41 | String getIp(); 42 | 43 | long getLastAccessedTime(); 44 | 45 | Object getAttribute(String key); 46 | 47 | List getAttributeNames(); 48 | 49 | void setAttribute(String key, Object value); 50 | 51 | void removeAttribute(String key); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/ThrowableArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/8/26 31 | */ 32 | public final class ThrowableArgumentGetter implements TypeArgumentGetter { 33 | @Override 34 | public Throwable get(RequestContext requestContext) { 35 | return requestContext.throwable(); 36 | } 37 | 38 | @Override 39 | public boolean support(Class cls) { 40 | try { 41 | return cls.newInstance() instanceof Throwable; 42 | } catch (InstantiationException | IllegalAccessException e) { 43 | return false; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/result/view/CssDataViewHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.result.view; 25 | 26 | import org.aquiver.Request; 27 | import org.aquiver.ViewHandlerType; 28 | import org.aquiver.mvc.http.MediaType; 29 | 30 | /** 31 | * @author WangYi 32 | * @since 2020/8/22 33 | */ 34 | public final class CssDataViewHandler extends AbstractDataViewHandler { 35 | 36 | @Override 37 | public String getMimeType(Request request) { 38 | return MediaType.TEXT_CSS_VALUE; 39 | } 40 | 41 | @Override 42 | public String getType() { 43 | return "css"; 44 | } 45 | 46 | @Override 47 | public ViewHandlerType getHandlerType() { 48 | return ViewHandlerType.DATA_VIEW; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/result/view/XmlDataViewHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.result.view; 25 | 26 | import org.aquiver.Request; 27 | import org.aquiver.ViewHandlerType; 28 | import org.aquiver.mvc.http.MediaType; 29 | 30 | /** 31 | * @author WangYi 32 | * @since 2020/8/22 33 | */ 34 | public final class XmlDataViewHandler extends AbstractDataViewHandler { 35 | 36 | @Override 37 | public String getMimeType(Request request) { 38 | return MediaType.TEXT_XML_VALUE; 39 | } 40 | 41 | @Override 42 | public String getType() { 43 | return "xml"; 44 | } 45 | 46 | @Override 47 | public ViewHandlerType getHandlerType() { 48 | return ViewHandlerType.DATA_VIEW; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/result/view/HtmlDataViewHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.result.view; 25 | 26 | import org.aquiver.Request; 27 | import org.aquiver.ViewHandlerType; 28 | import org.aquiver.mvc.http.MediaType; 29 | 30 | /** 31 | * @author WangYi 32 | * @since 2020/8/22 33 | */ 34 | public final class HtmlDataViewHandler extends AbstractDataViewHandler { 35 | 36 | @Override 37 | public String getMimeType(Request request) { 38 | return MediaType.TEXT_HTML_VALUE; 39 | } 40 | 41 | @Override 42 | public String getType() { 43 | return "html"; 44 | } 45 | 46 | @Override 47 | public ViewHandlerType getHandlerType() { 48 | return ViewHandlerType.DATA_VIEW; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/common/ansi/AnsiBackground.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.common.ansi; 25 | 26 | /** 27 | * @author WangYi 28 | * @version 1.0 29 | * @since 2019/1/16 30 | */ 31 | public enum AnsiBackground implements AnsiElement { 32 | BLACK_BACKGROUND("\u001B[40m"), 33 | RED_BACKGROUND("\u001B[41m"), 34 | GREEN_BACKGROUND("\u001B[42m"), 35 | YELLOW_BACKGROUND("\u001B[43m"), 36 | BLUE_BACKGROUND("\u001B[44m"), 37 | PURPLE_BACKGROUND("\u001B[45m"), 38 | CYAN_BACKGROUND("\u001B[46m"), 39 | WHITE_BACKGROUND("\u001B[47m"); 40 | 41 | private final String code; 42 | 43 | AnsiBackground(String code) { 44 | this.code = code; 45 | } 46 | 47 | @Override 48 | public String toString() { 49 | return this.code; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/MultipartFileArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | import org.aquiver.mvc.router.multipart.MultipartFile; 28 | 29 | /** 30 | * @author WangYi 31 | * @since 2020/8/26 32 | */ 33 | public final class MultipartFileArgumentGetter implements TypeArgumentGetter { 34 | 35 | @Override 36 | public MultipartFile get(RequestContext context) { 37 | final MultipartFile multipartFile = new MultipartFile(); 38 | multipartFile.channelContext(context.nettyContext()); 39 | return multipartFile; 40 | } 41 | 42 | @Override 43 | public boolean support(Class cls) { 44 | return cls.isAssignableFrom(MultipartFile.class); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/common/watcher/GlobalEnvListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.common.watcher; 25 | 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | import java.nio.file.Path; 30 | 31 | public class GlobalEnvListener implements WatcherListener { 32 | 33 | private static final Logger log = LoggerFactory.getLogger(GlobalEnvTask.class); 34 | 35 | @Override 36 | public void onCreate(Path file) { 37 | log.info(file.getFileName() + " has been created"); 38 | } 39 | 40 | @Override 41 | public void onModify(Path file) { 42 | log.info(file.getFileName() + " has been modify"); 43 | } 44 | 45 | @Override 46 | public void onDelete(Path file) { 47 | log.info(file.getFileName() + " has been deleted"); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/CookiesArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | import org.aquiver.mvc.http.Cookie; 28 | 29 | import java.lang.reflect.Parameter; 30 | import java.util.Map; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/8/26 35 | */ 36 | public final class CookiesArgumentGetter implements AnnotationArgumentGetter { 37 | 38 | @Override 39 | public Object get(ArgumentContext context) { 40 | RequestContext requestContext = context.getContext(); 41 | Map cookies = requestContext.request().cookies(); 42 | Parameter parameter = context.getParameter(); 43 | return parameter.getType().cast(cookies.get(parameter.getName()).getValue()); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/example/advice/NullAdvice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package example.advice; 25 | 26 | import org.aquiver.RequestContext; 27 | import org.aquiver.mvc.annotation.HandleAdvice; 28 | import org.aquiver.mvc.annotation.RouteAdvice; 29 | import org.slf4j.Logger; 30 | import org.slf4j.LoggerFactory; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/7/1 35 | */ 36 | @RouteAdvice 37 | public class NullAdvice { 38 | private static final Logger log = LoggerFactory.getLogger(NullAdvice.class); 39 | 40 | @HandleAdvice(NullPointerException.class) 41 | public String nullExceptionHandler(NullPointerException exception, RequestContext requestContext) { 42 | log.info("nullExceptionHandler..."); 43 | log.info("request url {}", requestContext.uri()); 44 | return exception.getMessage(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/test/java/example/bean/User3.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package example.bean; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2020/7/29 29 | */ 30 | public class User3 { 31 | private String username; 32 | private String password; 33 | private String ext; 34 | 35 | public String getUsername() { 36 | return username; 37 | } 38 | 39 | public User3 setUsername(String username) { 40 | this.username = username; 41 | return this; 42 | } 43 | 44 | public String getPassword() { 45 | return password; 46 | } 47 | 48 | public User3 setPassword(String password) { 49 | this.password = password; 50 | return this; 51 | } 52 | 53 | public String getExt() { 54 | return ext; 55 | } 56 | 57 | public User3 setExt(String ext) { 58 | this.ext = ext; 59 | return this; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/result/VoidResultHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.result; 25 | 26 | import io.netty.handler.codec.http.FullHttpResponse; 27 | import org.aquiver.RequestContext; 28 | import org.aquiver.ResponseBuilder; 29 | import org.aquiver.ResultHandler; 30 | import org.aquiver.mvc.RequestResult; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/8/22 35 | */ 36 | public final class VoidResultHandler implements ResultHandler { 37 | 38 | @Override 39 | public boolean support(RequestResult requestResult) { 40 | return Void.TYPE.isAssignableFrom(requestResult.getResultType()); 41 | } 42 | 43 | @Override 44 | public void handle(RequestContext ctx, RequestResult result) { 45 | FullHttpResponse voidResponse = ResponseBuilder.builder().build(); 46 | ctx.tryPush(voidResponse); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/HeaderArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | import org.aquiver.mvc.http.Header; 28 | 29 | import java.lang.reflect.Parameter; 30 | import java.util.Objects; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/8/26 35 | */ 36 | public final class HeaderArgumentGetter implements AnnotationArgumentGetter { 37 | 38 | @Override 39 | public Object get(ArgumentContext context) { 40 | RequestContext requestContext = context.getContext(); 41 | Parameter parameter = context.getParameter(); 42 | Header header = requestContext.header(parameter.getName()); 43 | if(Objects.isNull(header) || Objects.isNull(header.getValue())){ 44 | return null; 45 | } 46 | return parameter.getType().cast(header.getValue()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/http/Header.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.http; 25 | 26 | import org.apache.commons.lang3.Validate; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/10/19 31 | */ 32 | public class Header { 33 | private final String key; 34 | private final Object value; 35 | 36 | private Header(String key, String value) { 37 | Validate.notNull(key, "Header key can't be null"); 38 | Validate.notNull(value, "Header value can't be null"); 39 | this.key = key; 40 | this.value = value; 41 | } 42 | 43 | protected static Header init(String key, String value) { 44 | return new Header(key, value); 45 | } 46 | 47 | public String getKey() { 48 | return key; 49 | } 50 | 51 | public Object getValue() { 52 | return value; 53 | } 54 | 55 | public String getString() { 56 | return String.valueOf(value); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/http/Headers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.http; 25 | 26 | import io.netty.handler.codec.http.HttpHeaders; 27 | 28 | import java.util.HashMap; 29 | import java.util.Map; 30 | 31 | /** 32 | * @author WangYi 33 | * @since 2020/10/20 34 | */ 35 | public class Headers { 36 | private static final Map headerMap = new HashMap<>(); 37 | 38 | public static Map parse(HttpHeaders headers) { 39 | if (headers.isEmpty()){ 40 | return Headers.headerMap; 41 | } 42 | for (Map.Entry header : headers) { 43 | final String key = header.getKey(); 44 | final String value = header.getValue(); 45 | if (key.equals("Cookie")) { 46 | continue; 47 | } 48 | Headers.headerMap.put(key, Header.init(key, value)); 49 | } 50 | return Headers.headerMap; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/common/banner/BannerTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.common.banner; 25 | 26 | import org.aquiver.ServerSpec; 27 | 28 | import java.io.PrintStream; 29 | 30 | /** 31 | * @author WangYi 32 | * @since 2019/5/13 33 | */ 34 | public abstract class BannerTemplate implements Banner { 35 | 36 | public abstract void prePrintBannerText(PrintStream printStream, String bannerText, String bannerFont); 37 | 38 | public abstract String setUpPadding(Integer strapLineSize); 39 | 40 | public abstract void printTextAndVersion(PrintStream printStream, String padding); 41 | 42 | @Override 43 | public void printBanner(PrintStream printStream, String bannerText, String bannerFont) { 44 | this.prePrintBannerText(printStream, bannerText, bannerFont); 45 | final String padding = setUpPadding(ServerSpec.STRAP_LINE_SIZE); 46 | this.printTextAndVersion(printStream, padding); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/RequestResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc; 25 | 26 | import java.lang.reflect.Method; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/8/22 31 | */ 32 | public class RequestResult { 33 | private final Class resultType; 34 | private final Object resultObject; 35 | private final Method method; 36 | 37 | public RequestResult(Object resultObject, Method method) { 38 | this(resultObject.getClass(), resultObject, method); 39 | } 40 | 41 | public RequestResult(Class resultType, Object resultObject, Method method) { 42 | this.resultType = resultType; 43 | this.resultObject = resultObject; 44 | this.method = method; 45 | } 46 | 47 | public Class getResultType() { 48 | return resultType; 49 | } 50 | 51 | public Object getResultObject() { 52 | return resultObject; 53 | } 54 | 55 | public Method getMethod() { 56 | return method; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/test/java/example/config/ConfigProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package example.config; 25 | 26 | import org.apex.annotation.PropertyBean; 27 | import org.apex.annotation.Singleton; 28 | 29 | import java.util.List; 30 | import java.util.Map; 31 | 32 | /** 33 | * @author WangYi 34 | * @since 2020/8/4 35 | */ 36 | @Singleton 37 | @PropertyBean(value = "config.test") 38 | public class ConfigProperty { 39 | private List list; 40 | private Map map; 41 | 42 | private String age; 43 | private String name; 44 | private String height; 45 | private String weight; 46 | 47 | @Override 48 | public String toString() { 49 | return "ConfigProperty{" + 50 | "list=" + list + 51 | ", map=" + map + 52 | ", age='" + age + '\'' + 53 | ", name='" + name + '\'' + 54 | ", height='" + height + '\'' + 55 | ", weight='" + weight + '\'' + 56 | '}'; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/ArgumentContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.aquiver.RequestContext; 27 | 28 | import java.lang.annotation.Annotation; 29 | import java.lang.reflect.Parameter; 30 | 31 | /** 32 | * @author WangYi 33 | * @since 2020/8/27 34 | */ 35 | public final class ArgumentContext { 36 | private final Parameter parameter; 37 | private final Annotation annotation; 38 | private final RequestContext context; 39 | 40 | public ArgumentContext(Parameter parameter, Annotation annotation, RequestContext requestContext) { 41 | this.parameter = parameter; 42 | this.annotation = annotation; 43 | this.context = requestContext; 44 | } 45 | 46 | public Parameter getParameter() { 47 | return parameter; 48 | } 49 | 50 | public Annotation getAnnotation() { 51 | return annotation; 52 | } 53 | 54 | public RequestContext getContext() { 55 | return context; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/common/ansi/logback/LogBackAnsiConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.common.ansi.logback; 25 | 26 | import ch.qos.logback.classic.Level; 27 | import ch.qos.logback.classic.spi.ILoggingEvent; 28 | import ch.qos.logback.core.pattern.color.ANSIConstants; 29 | import ch.qos.logback.core.pattern.color.ForegroundCompositeConverterBase; 30 | 31 | public class LogBackAnsiConverter extends ForegroundCompositeConverterBase { 32 | 33 | @Override 34 | protected String getForegroundColorCode(ILoggingEvent iLoggingEvent) { 35 | switch (iLoggingEvent.getLevel().toInt()) { 36 | case Level.ERROR_INT: 37 | return ANSIConstants.RED_FG; 38 | case Level.WARN_INT: 39 | return ANSIConstants.YELLOW_FG; 40 | case Level.INFO_INT: 41 | return ANSIConstants.GREEN_FG; 42 | case Level.DEBUG_INT: 43 | return ANSIConstants.MAGENTA_FG; 44 | default: 45 | return null; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/result/view/AbstractDataViewHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.result.view; 25 | 26 | import io.netty.handler.codec.http.DefaultHttpHeaders; 27 | import io.netty.handler.codec.http.HttpHeaderNames; 28 | import io.netty.handler.codec.http.HttpHeaders; 29 | import org.aquiver.Request; 30 | import org.aquiver.RequestContext; 31 | import org.aquiver.ResponseBuilder; 32 | import org.aquiver.ViewHandler; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/8/22 37 | */ 38 | public abstract class AbstractDataViewHandler implements ViewHandler { 39 | public abstract String getMimeType(Request request); 40 | 41 | @Override 42 | public void render(RequestContext ctx, String viewPathName) { 43 | final HttpHeaders httpHeaders = new DefaultHttpHeaders(); 44 | httpHeaders.add(HttpHeaderNames.CONTENT_TYPE, getMimeType(ctx.request())); 45 | ctx.tryPush(ResponseBuilder.builder(). 46 | header(httpHeaders).body(viewPathName).build()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/test/java/example/ws/WebSocketClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package example.ws; 25 | 26 | import org.aquiver.websocket.WebSocket; 27 | import org.aquiver.websocket.WebSocketChannel; 28 | import org.aquiver.websocket.WebSocketContext; 29 | 30 | /** 31 | * @author WangYi 32 | * @since 2020/7/6 33 | */ 34 | @WebSocket(value = "/websocket") 35 | public class WebSocketClient implements WebSocketChannel { 36 | 37 | @Override 38 | public void onConnect(WebSocketContext webSocketContext) { 39 | System.out.println("websocket open connect"); 40 | } 41 | 42 | @Override 43 | public void onMessage(WebSocketContext webSocketContext) { 44 | System.out.println(webSocketContext.getMessage()); 45 | webSocketContext.message("测试消息回应"); 46 | } 47 | 48 | @Override 49 | public void onClose(WebSocketContext webSocketContext) { 50 | System.out.println("关闭连接:" + webSocketContext.session().getId()); 51 | } 52 | 53 | @Override 54 | public void onError(WebSocketContext webSocketContext) { 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/server/netty/NettyThreadFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.server.netty; 25 | 26 | import java.util.concurrent.ThreadFactory; 27 | import java.util.concurrent.atomic.LongAdder; 28 | 29 | /** 30 | * @author WangYi 31 | * @since 2019/6/14 32 | */ 33 | public class NettyThreadFactory implements ThreadFactory { 34 | 35 | private final String prefix; 36 | private final LongAdder threadNumber = new LongAdder(); 37 | 38 | public NettyThreadFactory(String prefix) { 39 | this.threadNumber.add(1); 40 | this.prefix = prefix; 41 | } 42 | 43 | /** 44 | * Constructs a new {@code Thread}. Implementations may also initialize 45 | * priority, name, daemon status, {@code ThreadGroup}, etc. 46 | * 47 | * @param runnable a runnable to be executed by new thread instance 48 | * @return constructed thread, or {@code null} if the request to 49 | * create a thread is rejected 50 | */ 51 | @Override 52 | public Thread newThread(Runnable runnable) { 53 | return new Thread(runnable, prefix + "thread-" + threadNumber.intValue()); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/Response.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver; 25 | 26 | import io.netty.channel.ChannelFuture; 27 | import io.netty.channel.ChannelPromise; 28 | import io.netty.handler.codec.http.FullHttpResponse; 29 | 30 | /** 31 | * @author WangYi 32 | * @since 2020/10/19 33 | */ 34 | public interface Response { 35 | void cookie(String key, String value); 36 | 37 | void removeCookie(String key); 38 | 39 | void header(String key, String value); 40 | 41 | void removeHeader(String key); 42 | 43 | void tryPush(FullHttpResponse response); 44 | 45 | ChannelFuture tryPush(Object msg); 46 | 47 | ChannelFuture tryPush(Object msg, ChannelPromise promise); 48 | 49 | ChannelFuture tryWrite(Object msg); 50 | 51 | ChannelFuture tryWrite(Object msg, ChannelPromise promise); 52 | 53 | void redirect(String redirectUrl); 54 | 55 | void json(T t); 56 | 57 | void text(String text); 58 | 59 | void render(String renderTemplate); 60 | 61 | void html(String htmlTemplate); 62 | 63 | void status(int httpStatus); 64 | 65 | void notFound(); 66 | 67 | void badRequest(); 68 | 69 | void serverInternalError(); 70 | 71 | void error(int status, String errorMsg); 72 | } 73 | -------------------------------------------------------------------------------- /src/test/java/example/ws/WebSocketActionWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package example.ws; 25 | 26 | import org.aquiver.mvc.annotation.bind.Param; 27 | import org.aquiver.websocket.WebSocket; 28 | import org.aquiver.websocket.WebSocketContext; 29 | import org.aquiver.websocket.action.OnClose; 30 | import org.aquiver.websocket.action.OnConnect; 31 | import org.aquiver.websocket.action.OnError; 32 | import org.aquiver.websocket.action.OnMessage; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/7/13 37 | */ 38 | @WebSocket("/wrapper") 39 | public class WebSocketActionWrapper { 40 | 41 | @OnConnect 42 | public void onConnect(WebSocketContext webSocketContext, @Param String name) { 43 | System.out.println("websocket open connect:" + name); 44 | } 45 | 46 | @OnMessage 47 | public void onMessage(WebSocketContext webSocketContext) { 48 | System.out.println(webSocketContext.getMessage()); 49 | webSocketContext.message("测试消息回应"); 50 | } 51 | 52 | @OnClose 53 | public void onClose(WebSocketContext webSocketContext) { 54 | System.out.println("关闭连接:" + webSocketContext.session().getId()); 55 | } 56 | 57 | @OnError 58 | public void onError(WebSocketContext webSocketContext) { 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/router/views/PebbleHTMLView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.router.views; 25 | 26 | import com.mitchellbosecke.pebble.PebbleEngine; 27 | import com.mitchellbosecke.pebble.template.PebbleTemplate; 28 | 29 | import java.io.IOException; 30 | import java.io.StringWriter; 31 | import java.io.Writer; 32 | import java.util.Map; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/6/17 37 | */ 38 | public class PebbleHTMLView implements HTMLView { 39 | private final PebbleEngine engine; 40 | 41 | public PebbleHTMLView() { 42 | this.engine = new PebbleEngine.Builder().build(); 43 | } 44 | 45 | /** 46 | * Get the content of the returned view 47 | * 48 | * @param htmlPath html path 49 | * @param viewParams view render params 50 | * @return the content of the returned view 51 | * @throws IOException io exception 52 | */ 53 | @Override 54 | public String renderView(String htmlPath, Map viewParams) throws IOException { 55 | final PebbleTemplate compiledTemplate = engine.getTemplate(htmlPath); 56 | final Writer writer = new StringWriter(); 57 | compiledTemplate.evaluate(writer, viewParams); 58 | return writer.toString(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/ReflectionHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver; 25 | 26 | import java.lang.reflect.Method; 27 | import java.lang.reflect.Modifier; 28 | import java.lang.reflect.Parameter; 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | 32 | public class ReflectionHelper { 33 | private ReflectionHelper() {} 34 | 35 | public static boolean isInterface(Class clazz) { 36 | return clazz.isInterface(); 37 | } 38 | 39 | public static boolean isAbstract(Class clazz) { 40 | int modifiers = clazz.getModifiers(); 41 | return Modifier.isAbstract(modifiers); 42 | } 43 | 44 | public static boolean isEnum(Class clazz) { 45 | return clazz.isEnum(); 46 | } 47 | 48 | public static boolean isNormal(Class clazz) { 49 | return !isAbstract(clazz) && !isInterface(clazz) && !isEnum(clazz); 50 | } 51 | 52 | public static String[] getMethodParamName(Method method) { 53 | Parameter[] parameters = method.getParameters(); 54 | List nameList = new ArrayList<>(); 55 | for (Parameter param : parameters) { 56 | String name = param.getName(); 57 | nameList.add(name); 58 | } 59 | return nameList.toArray(new String[0]); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/FileUploadArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import io.netty.handler.codec.http.multipart.FileUpload; 27 | import org.aquiver.RequestContext; 28 | import org.aquiver.mvc.router.multipart.MultipartFile; 29 | import org.aquiver.mvc.router.multipart.MultipartFileUtils; 30 | 31 | import java.lang.reflect.Parameter; 32 | import java.util.Map; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/8/26 37 | */ 38 | public final class FileUploadArgumentGetter implements AnnotationArgumentGetter { 39 | @Override 40 | public Object get(ArgumentContext context) throws Exception { 41 | RequestContext requestContext = context.getContext(); 42 | Map fileUploads = requestContext.request().fileUploads(); 43 | Parameter parameter = context.getParameter(); 44 | String name = parameter.getName(); 45 | if (MultipartFile.class.isAssignableFrom(parameter.getType()) && fileUploads.containsKey(name)) { 46 | io.netty.handler.codec.http.multipart.FileUpload fileUpload = fileUploads.get(name); 47 | return MultipartFileUtils.createMultipartFile(fileUpload, requestContext.nettyContext()); 48 | } 49 | return null; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/ModelAndView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver; 25 | 26 | import java.util.Map; 27 | 28 | /** 29 | * @author WangYi 30 | * @since 2020/6/17 31 | */ 32 | public class ModelAndView { 33 | private Map params; 34 | private String htmlPath; 35 | private String redirectUrl; 36 | 37 | public ModelAndView() { 38 | } 39 | 40 | public ModelAndView(Map params, String htmlPath) { 41 | this.params = params; 42 | this.htmlPath = htmlPath; 43 | } 44 | 45 | public Map params() { 46 | return params; 47 | } 48 | 49 | public void params(Map params) { 50 | this.params = params; 51 | } 52 | 53 | public String htmlPath() { 54 | return htmlPath; 55 | } 56 | 57 | public void htmlPath(String htmlPath) { 58 | this.htmlPath = htmlPath; 59 | } 60 | 61 | public String redirectUrl() { 62 | return redirectUrl; 63 | } 64 | 65 | public void redirect(String redirectUrl) { 66 | this.redirectUrl = redirectUrl; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "ModelAndView{" + 72 | "params=" + params + 73 | ", htmlPath='" + htmlPath + '\'' + 74 | '}'; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/common/banner/SimpleBanner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.common.banner; 25 | 26 | import io.leego.banana.BananaUtils; 27 | import org.aquiver.ServerSpec; 28 | import org.aquiver.common.ansi.AnsiColor; 29 | import org.aquiver.common.ansi.AnsiOutput; 30 | 31 | import java.io.PrintStream; 32 | 33 | /** 34 | * @author WangYi 35 | * @since 2019/5/13 36 | */ 37 | public class SimpleBanner extends BannerTemplate { 38 | 39 | @Override 40 | public void prePrintBannerText(PrintStream printStream, String bannerText, String bannerFont) { 41 | printStream.println(BananaUtils.bananaify(bannerText, bannerFont)); 42 | } 43 | 44 | @Override 45 | public String setUpPadding(Integer strapLineSize) { 46 | final StringBuilder padding = new StringBuilder(); 47 | while (padding.length() < strapLineSize - (ServerSpec.AQUIVER_VERSION.length() + ServerSpec.AQUIVER_FRAMEWORK.length())) { 48 | padding.append(ServerSpec.SPACE); 49 | } 50 | return padding.toString(); 51 | } 52 | 53 | @Override 54 | public void printTextAndVersion(PrintStream printStream, String padding) { 55 | printStream.println(AnsiOutput.toString(AnsiColor.GREEN, ServerSpec.AQUIVER_FRAMEWORK, 56 | AnsiColor.RESET, padding, ServerSpec.AQUIVER_VERSION)); 57 | printStream.println(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/ParamArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import org.apache.commons.lang3.StringUtils; 27 | import org.aquiver.RequestContext; 28 | import org.aquiver.mvc.annotation.bind.Param; 29 | 30 | /** 31 | * @author WangYi 32 | * @since 2020/8/26 33 | */ 34 | public final class ParamArgumentGetter implements AnnotationArgumentGetter { 35 | 36 | @Override 37 | public Object get(ArgumentContext context) { 38 | RequestContext requestContext = context.getContext(); 39 | Param param = (Param) context.getAnnotation(); 40 | String paramKey = context.getParameter().getName(); 41 | if (!"".equals(param.value())) { 42 | paramKey = param.value(); 43 | } 44 | String requestParam = requestContext.param(paramKey); 45 | if (StringUtils.isEmpty(requestParam) || "null".equals(requestParam)) { 46 | if (!"".equals(param.defaultValue())) { 47 | return context.getParameter().getType().cast(param.defaultValue()); 48 | } else{ 49 | if (param.required()) { 50 | throw new IllegalArgumentException("This parameter is required: " 51 | + context.getParameter().getName()); 52 | } 53 | } 54 | } else { 55 | return context.getParameter().getType().cast(requestParam); 56 | } 57 | return null; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/argument/MultiFileUploadArgumentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.argument; 25 | 26 | import io.netty.handler.codec.http.multipart.FileUpload; 27 | import org.aquiver.RequestContext; 28 | import org.aquiver.mvc.router.multipart.MultipartFile; 29 | import org.aquiver.mvc.router.multipart.MultipartFileUtils; 30 | 31 | import java.lang.reflect.Parameter; 32 | import java.util.ArrayList; 33 | import java.util.List; 34 | import java.util.Map; 35 | 36 | /** 37 | * @author WangYi 38 | * @since 2020/8/26 39 | */ 40 | public final class MultiFileUploadArgumentGetter implements AnnotationArgumentGetter { 41 | 42 | @Override 43 | public Object get(ArgumentContext context) throws Exception { 44 | RequestContext requestContext = context.getContext(); 45 | Map fileUploads = requestContext.request().fileUploads(); 46 | List multipartFiles = new ArrayList<>(); 47 | Parameter parameter = context.getParameter(); 48 | if (List.class.isAssignableFrom(parameter.getType())) { 49 | for (Map.Entry entry : fileUploads.entrySet()) { 50 | FileUpload value = entry.getValue(); 51 | MultipartFile multipartFile = MultipartFileUtils.createMultipartFile( 52 | value, requestContext.nettyContext()); 53 | multipartFiles.add(multipartFile); 54 | } 55 | } 56 | return multipartFiles; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/result/ModelAndViewResultHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.result; 25 | 26 | import org.apex.Apex; 27 | import org.apex.ApexContext; 28 | import org.apex.Environment; 29 | import org.aquiver.ModelAndView; 30 | import org.aquiver.RequestContext; 31 | import org.aquiver.ResultHandler; 32 | import org.aquiver.ViewHandler; 33 | import org.aquiver.ViewHandlerResolver; 34 | import org.aquiver.mvc.RequestResult; 35 | import org.aquiver.ServerSpec; 36 | 37 | /** 38 | * @author WangYi 39 | * @since 2020/8/25 40 | */ 41 | public final class ModelAndViewResultHandler implements ResultHandler { 42 | private final ApexContext context = ApexContext.of(); 43 | private final Environment environment = Apex.of().environment(); 44 | private final ViewHandlerResolver viewHandlerResolver = context.getBean(ViewHandlerResolver.class); 45 | 46 | @Override 47 | public boolean support(RequestResult requestResult) { 48 | return ModelAndView.class.isAssignableFrom(requestResult.getResultType()); 49 | } 50 | 51 | @Override 52 | public void handle(RequestContext ctx, RequestResult result) throws Exception { 53 | ModelAndView modelAndView = (ModelAndView) result.getResultObject(); 54 | String suffix = this.environment.get(ServerSpec.PATH_SERVER_VIEW_SUFFIX, ServerSpec.SERVER_VIEW_SUFFIX); 55 | ViewHandler lookup = this.viewHandlerResolver.lookup(suffix); 56 | lookup.render(ctx, modelAndView.htmlPath()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/http/Cookies.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.http; 25 | 26 | import io.netty.handler.codec.http.HttpHeaders; 27 | import io.netty.handler.codec.http.cookie.ServerCookieDecoder; 28 | import org.apache.commons.lang3.StringUtils; 29 | 30 | import java.time.LocalDateTime; 31 | import java.util.HashMap; 32 | import java.util.Map; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/10/20 37 | */ 38 | public class Cookies { 39 | private static final Map cookies = new HashMap<>(); 40 | 41 | protected static Map parse(HttpHeaders headers) { 42 | String cookie = headers.get("Cookie"); 43 | if(StringUtils.isNotBlank(cookie)){ 44 | ServerCookieDecoder.LAX.decode(cookie).forEach(Cookies::parseCookie); 45 | } 46 | return cookies; 47 | } 48 | 49 | /** 50 | * Parse netty cookie to {@link Cookie}. 51 | * 52 | * @param nettyCookie netty raw cookie instance 53 | */ 54 | private static void parseCookie(io.netty.handler.codec.http.cookie.Cookie nettyCookie) { 55 | Cookie cookie = new Cookie(nettyCookie.name(), nettyCookie.value()); 56 | cookie.setDomain(nettyCookie.domain()); 57 | cookie.setExpires(LocalDateTime.now()); 58 | cookie.setHttpOnly(nettyCookie.isHttpOnly()); 59 | cookie.setMaxAge(nettyCookie.maxAge()); 60 | cookie.setPath(nettyCookie.path()); 61 | cookie.setSecure(nettyCookie.isSecure()); 62 | Cookies.cookies.put(cookie.getName(), cookie); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/result/view/PebbleTemplateViewHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.result.view; 25 | 26 | import io.netty.handler.codec.http.FullHttpResponse; 27 | import org.aquiver.RequestContext; 28 | import org.aquiver.ResponseBuilder; 29 | import org.aquiver.ServerSpec; 30 | import org.aquiver.ViewHandlerType; 31 | import org.aquiver.mvc.router.views.HTMLView; 32 | import org.aquiver.mvc.router.views.PebbleHTMLView; 33 | 34 | import java.io.IOException; 35 | import java.util.HashMap; 36 | 37 | /** 38 | * @author WangYi 39 | * @since 2020/8/23 40 | */ 41 | public final class PebbleTemplateViewHandler extends AbstractTemplateViewHandler { 42 | private final HTMLView htmlView = new PebbleHTMLView(); 43 | 44 | @Override 45 | public String getPrefix() { 46 | return environment.get(ServerSpec.PATH_SERVER_VIEW_PREFIX, ""); 47 | } 48 | 49 | @Override 50 | protected void doRender(RequestContext ctx, String viewPathName) throws IOException { 51 | String renderView = this.htmlView.renderView(viewPathName, new HashMap<>()); 52 | final FullHttpResponse responseView = ResponseBuilder.builder().body(renderView).build(); 53 | ctx.tryPush(responseView); 54 | } 55 | 56 | @Override 57 | public String getSuffix() { 58 | return ".peb"; 59 | } 60 | 61 | @Override 62 | public String getType() { 63 | return "peb"; 64 | } 65 | 66 | @Override 67 | public ViewHandlerType getHandlerType() { 68 | return ViewHandlerType.TEMPLATE_VIEW; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/result/JsonResultHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.result; 25 | 26 | import com.alibaba.fastjson.JSONObject; 27 | import io.netty.handler.codec.http.DefaultHttpHeaders; 28 | import io.netty.handler.codec.http.FullHttpResponse; 29 | import io.netty.handler.codec.http.HttpHeaders; 30 | import org.aquiver.RequestContext; 31 | import org.aquiver.ResponseBuilder; 32 | import org.aquiver.ResultHandler; 33 | import org.aquiver.mvc.RequestResult; 34 | import org.aquiver.mvc.annotation.JSON; 35 | 36 | import java.lang.reflect.Method; 37 | 38 | import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE; 39 | import static org.aquiver.mvc.http.MediaType.APPLICATION_JSON_VALUE; 40 | 41 | /** 42 | * @author WangYi 43 | * @since 2020/8/31 44 | */ 45 | public final class JsonResultHandler implements ResultHandler { 46 | 47 | @Override 48 | public boolean support(RequestResult requestResult) { 49 | Method method = requestResult.getMethod(); 50 | return method.isAnnotationPresent(JSON.class); 51 | } 52 | 53 | @Override 54 | public void handle(RequestContext ctx, RequestResult result) { 55 | String jsonString = JSONObject.toJSONString(result.getResultObject()); 56 | HttpHeaders httpHeaders = new DefaultHttpHeaders(); 57 | httpHeaders.add(CONTENT_TYPE, APPLICATION_JSON_VALUE); 58 | final FullHttpResponse jsonResponse = ResponseBuilder.builder() 59 | .header(httpHeaders).body(jsonString).build(); 60 | ctx.tryPush(jsonResponse); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/result/view/AbstractTemplateViewHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.result.view; 25 | 26 | import org.apex.Environment; 27 | import org.aquiver.Aquiver; 28 | import org.aquiver.RequestContext; 29 | import org.aquiver.ResponseBuilder; 30 | import org.aquiver.ViewHandler; 31 | import org.aquiver.ServerSpec; 32 | 33 | import java.io.File; 34 | import java.net.URL; 35 | import java.util.Objects; 36 | 37 | /** 38 | * @author WangYi 39 | * @since 2020/8/22 40 | */ 41 | public abstract class AbstractTemplateViewHandler implements ViewHandler { 42 | protected final Environment environment = Aquiver.of().environment(); 43 | 44 | public abstract String getPrefix(); 45 | 46 | @Override 47 | public void render(RequestContext ctx, String viewPathName) throws Exception { 48 | String viewPath = viewPathName; 49 | if (!getPrefix().equals("")) { 50 | viewPath = "/" + getPrefix() + viewPath; 51 | } 52 | 53 | viewPath = ServerSpec.SERVER_TEMPLATES_FOLDER + File.separator + viewPath; 54 | if (!viewPath.endsWith(getSuffix())) { 55 | viewPath = viewPath + "." + getSuffix(); 56 | } 57 | URL viewUrl = Thread.currentThread().getContextClassLoader().getResource(viewPath); 58 | if (Objects.isNull(viewUrl)) { 59 | ctx.tryPush(ResponseBuilder.builder().body(viewPathName).build()); 60 | } else { 61 | doRender(ctx, viewPath); 62 | } 63 | } 64 | 65 | protected abstract void doRender(RequestContext ctx, String viewPathName) throws Exception; 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/handler/RouteAdviceHandlerResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.handler; 25 | 26 | import org.apache.commons.lang3.Validate; 27 | import org.apex.ApexContext; 28 | import org.aquiver.RequestContext; 29 | import org.aquiver.mvc.http.HttpStatus; 30 | 31 | import java.util.HashMap; 32 | import java.util.Map; 33 | 34 | /** 35 | * @author WangYi 36 | * @since 2020/7/3 37 | */ 38 | public class RouteAdviceHandlerResolver { 39 | private final Map, RouteAdviceHandler> exceptionHandlerMap = new HashMap<>(); 40 | 41 | public void registerAdviceHandler(Class throwableCls, RouteAdviceHandler routeAdviceHandler) { 42 | Validate.notNull(throwableCls, "throwableCls can' be null"); 43 | Validate.notNull(routeAdviceHandler, "errorHandler can' be null"); 44 | this.exceptionHandlerMap.put(throwableCls, routeAdviceHandler); 45 | } 46 | 47 | public void handleException(Throwable throwable, RequestContext requestContext) { 48 | if (exceptionHandlerMap.isEmpty() || !exceptionHandlerMap.containsKey(throwable.getClass())) { 49 | requestContext.error(HttpStatus.INTERNAL_SERVER_ERROR, throwable.getLocalizedMessage()); 50 | } 51 | try { 52 | final RouteAdviceHandler routeAdviceHandler = exceptionHandlerMap.get(throwable.getClass()); 53 | if (null != routeAdviceHandler) { 54 | routeAdviceHandler.handle(throwable); 55 | } 56 | } catch (Exception e) { 57 | handleException(e, requestContext); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/router/PathVarMatcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.router; 25 | 26 | /** 27 | * @author WangYi 28 | * @since 2020/5/29 29 | */ 30 | public class PathVarMatcher { 31 | private PathVarMatcher() { 32 | } 33 | 34 | public static boolean checkMatch(String[] lookupPathSplit, String... mappingUrlSplit) { 35 | for (int i = 0; i < lookupPathSplit.length; i++) { 36 | if (lookupPathSplit[i].equals(mappingUrlSplit[i])) { 37 | continue; 38 | } 39 | if (!mappingUrlSplit[i].startsWith("{")) { 40 | return false; 41 | } 42 | } 43 | return true; 44 | } 45 | 46 | public static String getMatch(String url) { 47 | StringBuilder matcher = new StringBuilder(128); 48 | for (char c : url.toCharArray()) { 49 | if (c == '{') { 50 | break; 51 | } 52 | matcher.append(c); 53 | } 54 | return matcher.toString(); 55 | } 56 | 57 | public static String getPathVariable(String url, String mappingUrl, String name) { 58 | String[] urlSplit = url.split("/"); 59 | String[] mappingUrlSplit = mappingUrl.split("/"); 60 | for (int i = 0; i < mappingUrlSplit.length; i++) { 61 | if (mappingUrlSplit[i].equals("{" + name + "}")) { 62 | if (urlSplit[i].contains("?")) { 63 | return urlSplit[i].split("[?]")[0]; 64 | } 65 | if (urlSplit[i].contains("&")) { 66 | return urlSplit[i].split("&")[0]; 67 | } 68 | return urlSplit[i]; 69 | } 70 | } 71 | return null; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/RouteRepeatException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver; 25 | 26 | /** 27 | * This exception is thrown when the route is added repeatedly 28 | * 29 | * @author WangYi 30 | * @since 2020/5/26 31 | */ 32 | public class RouteRepeatException extends RuntimeException { 33 | 34 | /** 35 | * Constructs a new runtime exception with the specified detail message. 36 | * The cause is not initialized, and may subsequently be initialized by a 37 | * call to {@link #initCause}. 38 | * 39 | * @param message the detail message. The detail message is saved for 40 | * later retrieval by the {@link #getMessage()} method. 41 | */ 42 | public RouteRepeatException(String message) { 43 | super(message); 44 | } 45 | 46 | /** 47 | * Constructs a new runtime exception with the specified detail message and 48 | * cause.

Note that the detail message associated with 49 | * {@code cause} is not automatically incorporated in 50 | * this runtime exception's detail message. 51 | * 52 | * @param message the detail message (which is saved for later retrieval 53 | * by the {@link #getMessage()} method). 54 | * @param cause the cause (which is saved for later retrieval by the 55 | * {@link #getCause()} method). (A {@code null} value is 56 | * permitted, and indicates that the cause is nonexistent or 57 | * unknown.) 58 | * @since 1.4 59 | */ 60 | public RouteRepeatException(String message, Throwable cause) { 61 | super(message, cause); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/mvc/result/view/HtmlTemplateViewHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver.mvc.result.view; 25 | 26 | import io.netty.handler.codec.http.FullHttpResponse; 27 | import org.apex.io.FileBaseResource; 28 | import org.apex.io.Resource; 29 | import org.aquiver.RequestContext; 30 | import org.aquiver.ResponseBuilder; 31 | import org.aquiver.ServerSpec; 32 | import org.aquiver.ViewHandlerType; 33 | 34 | import java.net.URL; 35 | import java.nio.file.Files; 36 | import java.nio.file.Paths; 37 | 38 | /** 39 | * @author WangYi 40 | * @since 2020/8/27 41 | */ 42 | public final class HtmlTemplateViewHandler extends AbstractTemplateViewHandler { 43 | 44 | @Override 45 | public String getPrefix() { 46 | return environment.get(ServerSpec.PATH_SERVER_VIEW_PREFIX, ""); 47 | } 48 | 49 | @Override 50 | public String getSuffix() { 51 | return ServerSpec.SERVER_VIEW_SUFFIX; 52 | } 53 | 54 | @Override 55 | protected void doRender(RequestContext ctx, String viewPathName) throws Exception { 56 | URL viewUrl = this.getClass().getClassLoader().getResource(viewPathName); 57 | Resource resource = new FileBaseResource(Paths.get(viewUrl.toURI())); 58 | String htmlContent = new String(Files.readAllBytes(resource.getPath())); 59 | FullHttpResponse response = ResponseBuilder.builder().body(htmlContent).build(); 60 | ctx.tryPush(response); 61 | } 62 | 63 | @Override 64 | public String getType() { 65 | return "html"; 66 | } 67 | 68 | @Override 69 | public ViewHandlerType getHandlerType() { 70 | return ViewHandlerType.TEMPLATE_VIEW; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/org/aquiver/Request.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MIT License 3 | * 4 | * Copyright (c) 2019 1619kHz 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in all 14 | * copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | * SOFTWARE. 23 | */ 24 | package org.aquiver; 25 | 26 | import io.netty.buffer.ByteBuf; 27 | import io.netty.handler.codec.http.multipart.FileUpload; 28 | import org.aquiver.mvc.http.Cookie; 29 | import org.aquiver.mvc.http.Header; 30 | import org.aquiver.mvc.router.session.Session; 31 | 32 | import java.util.Map; 33 | import java.util.Set; 34 | 35 | /** 36 | * @author WangYi 37 | * @since 2020/10/17 38 | */ 39 | public interface Request { 40 | Map fileUploads(); 41 | 42 | FileUpload fileUploads(String fileKey); 43 | 44 | Boolean isMultipart(); 45 | 46 | ByteBuf body(); 47 | 48 | T body(Class type); 49 | 50 | Session session(); 51 | 52 | String method(); 53 | 54 | String protocol(); 55 | 56 | Integer minorVersion(); 57 | 58 | Integer majorVersion(); 59 | 60 | Header header(String key); 61 | 62 | String param(String key); 63 | 64 | Set paramNames(); 65 | 66 | Set headerNames(); 67 | 68 | String uri(); 69 | 70 | String path(); 71 | 72 | String rawPath(); 73 | 74 | String rawQuery(); 75 | 76 | Integer port(); 77 | 78 | String remoteAddress(); 79 | 80 | String host(); 81 | 82 | String accept(); 83 | 84 | String connection(); 85 | 86 | Map cookies(); 87 | 88 | Cookie cookie(String key); 89 | 90 | String sessionKey(); 91 | 92 | String referer(); 93 | 94 | String userAgent(); 95 | 96 | Map header(); 97 | 98 | Boolean isKeepAlive(); 99 | 100 | Boolean is100ContinueExpected(); 101 | } 102 | --------------------------------------------------------------------------------