├── .circleci └── config.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── NOTICE ├── README.md ├── kernel ├── LICENSE ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── adeptj │ │ └── runtime │ │ └── kernel │ │ ├── AbstractServer.java │ │ ├── ConfigProvider.java │ │ ├── Constants.java │ │ ├── FilterInfo.java │ │ ├── SciInfo.java │ │ ├── Server.java │ │ ├── ServerMode.java │ │ ├── ServerPostStopTask.java │ │ ├── ServerRuntime.java │ │ ├── ServerShutdownHook.java │ │ ├── ServletDeployment.java │ │ ├── ServletInfo.java │ │ ├── UserManager.java │ │ ├── exception │ │ ├── RuntimeInitializationException.java │ │ └── ServerException.java │ │ ├── osgi │ │ └── PackageExportsProvider.java │ │ ├── security │ │ └── DefaultUserManager.java │ │ ├── servlet │ │ └── FaviconServlet.java │ │ └── util │ │ ├── ClasspathResource.java │ │ ├── Configs.java │ │ ├── Environment.java │ │ ├── IOUtils.java │ │ ├── KeyStores.java │ │ ├── MVStoreUtil.java │ │ ├── PasswordEncoder.java │ │ ├── RequestUtil.java │ │ ├── ResponseUtil.java │ │ ├── SslContextFactory.java │ │ └── Times.java │ └── resources │ ├── i18n │ └── kernel.properties │ └── reference.conf ├── main ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── adeptj │ │ │ └── runtime │ │ │ ├── common │ │ │ ├── BridgeServletConfigHolder.java │ │ │ ├── BundleContextHolder.java │ │ │ ├── Constants.java │ │ │ ├── LogbackManagerHolder.java │ │ │ ├── OSGiUtil.java │ │ │ ├── ServerMode.java │ │ │ ├── ServletContextHolder.java │ │ │ └── Servlets.java │ │ │ ├── core │ │ │ ├── DefaultStartupAware.java │ │ │ ├── Launcher.java │ │ │ ├── LoggerCleanupTask.java │ │ │ ├── RuntimeInitializer.java │ │ │ ├── ServerBootstrapper.java │ │ │ └── StartupAware.java │ │ │ ├── exception │ │ │ ├── RuntimeInitializationException.java │ │ │ └── ServerException.java │ │ │ ├── html │ │ │ ├── I18nSupport.java │ │ │ ├── TemplateEngine.java │ │ │ ├── TemplateEngineContext.java │ │ │ └── TemplateProcessingException.java │ │ │ ├── logging │ │ │ ├── DebugLevelHighlightingConverter.java │ │ │ ├── FileAppenderConfig.java │ │ │ ├── LogbackInitializer.java │ │ │ ├── LogbackManager.java │ │ │ └── OSGiLoggerConfig.java │ │ │ ├── osgi │ │ │ ├── BridgeHttpSessionIdListener.java │ │ │ ├── BridgeHttpSessionListener.java │ │ │ ├── BridgeServiceTracker.java │ │ │ ├── BridgeServletContextAttributeListener.java │ │ │ ├── BundleProvisioner.java │ │ │ ├── DispatcherServletConfig.java │ │ │ ├── DispatcherServletTracker.java │ │ │ ├── DispatcherServletWrapper.java │ │ │ ├── EventDispatcherTracker.java │ │ │ ├── FrameworkEvents.java │ │ │ ├── FrameworkLauncher.java │ │ │ ├── FrameworkLifecycleListener.java │ │ │ ├── FrameworkManager.java │ │ │ ├── FrameworkShutdownHandler.java │ │ │ ├── HttpSessionEvents.java │ │ │ ├── LoggerConfigFactoryListener.java │ │ │ └── ServiceTrackers.java │ │ │ └── servlet │ │ │ ├── AdminServlet.java │ │ │ ├── BridgeServlet.java │ │ │ └── ErrorServlet.java │ ├── resources │ │ ├── META-INF │ │ │ └── services │ │ │ │ └── ch.qos.logback.classic.spi.Configurator │ │ ├── application.conf │ │ ├── banner.txt │ │ ├── framework.properties │ │ ├── i18n │ │ │ └── main.properties │ │ └── server.p12 │ └── webapp │ │ ├── i18n │ │ └── messages.properties │ │ ├── static │ │ ├── css │ │ │ ├── error-page.css │ │ │ ├── main.css │ │ │ └── vendors │ │ │ │ └── bootstrap.min.css │ │ └── img │ │ │ ├── favicon.ico │ │ │ └── logo.png │ │ └── templates │ │ ├── change-pwd.html │ │ ├── error.html │ │ └── login.html │ └── test │ └── java │ └── com │ └── adeptj │ └── runtime │ └── common │ └── BundleContextHolderTest.java ├── pom.xml └── server-adapters ├── jetty ├── LICENSE ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── adeptj │ │ └── runtime │ │ └── jetty │ │ ├── JettyServer.java │ │ ├── MVStoreLoginService.java │ │ ├── SecurityConfigurer.java │ │ ├── Sha256Base64EncodedPassword.java │ │ ├── handler │ │ ├── ContextPathHandler.java │ │ └── HealthCheckHandler.java │ │ └── osgi │ │ └── JettyPackageExportsProvider.java │ └── resources │ ├── META-INF │ └── services │ │ ├── com.adeptj.runtime.kernel.Server │ │ └── com.adeptj.runtime.kernel.osgi.PackageExportsProvider │ ├── i18n │ └── jetty.properties │ └── reference.conf ├── pom.xml ├── tomcat ├── LICENSE ├── README.md ├── pom.xml └── src │ └── main │ ├── java │ └── com │ │ └── adeptj │ │ └── runtime │ │ └── tomcat │ │ ├── ConnectorConfigurer.java │ │ ├── GeneralConfigurer.java │ │ ├── MVStoreCredentialHandler.java │ │ ├── MVStoreRealm.java │ │ ├── SecurityConfigurer.java │ │ ├── ServerConstants.java │ │ ├── TomcatServer.java │ │ ├── filter │ │ └── ContextPathFilter.java │ │ └── servlet │ │ └── HealthCheckServlet.java │ └── resources │ ├── META-INF │ └── services │ │ └── com.adeptj.runtime.kernel.Server │ ├── i18n │ └── tomcat.properties │ └── reference.conf └── undertow ├── LICENSE ├── README.md ├── pom.xml └── src └── main ├── java └── com │ └── adeptj │ └── runtime │ └── undertow │ ├── UndertowServer.java │ ├── core │ ├── BaseOptions.java │ ├── ServerConstants.java │ ├── ServerOptions.java │ ├── SimpleAccount.java │ ├── SimpleIdentityManager.java │ ├── SimplePrincipal.java │ ├── SocketOptions.java │ └── WorkerOptions.java │ ├── handler │ ├── HealthCheckHandler.java │ └── ServletInitialHandlerWrapper.java │ └── predicate │ └── ContextPathPredicate.java └── resources ├── META-INF └── services │ └── com.adeptj.runtime.kernel.Server ├── i18n └── undertow.properties └── reference.conf /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Use the latest 2.1 version of CircleCI pipeline process engine. 2 | # See: https://circleci.com/docs/2.0/configuration-reference 3 | version: 2.1 4 | 5 | # Define a job to be invoked later in a workflow. 6 | # See: https://circleci.com/docs/2.0/configuration-reference/#jobs 7 | jobs: 8 | # Below is the definition of your job to build and test your app, you can rename and customize it as you want. 9 | build-and-test: 10 | # These next lines define a Docker executor: https://circleci.com/docs/2.0/executor-types/ 11 | # You can specify an image from Dockerhub or use one of our Convenience Images from CircleCI's Developer Hub. 12 | # Be sure to update the Docker image tag below to openjdk version of your application. 13 | # A list of available CircleCI Docker Convenience Images are available here: https://circleci.com/developer/images/image/cimg/openjdk 14 | docker: 15 | - image: cimg/openjdk:21.0.2 16 | # Add steps to the job 17 | # See: https://circleci.com/docs/2.0/configuration-reference/#steps 18 | steps: 19 | # Checkout the code as the first step. 20 | - checkout 21 | # Use mvn clean and package as the standard maven build phase 22 | - run: 23 | name: Build 24 | command: mvn -B -DskipTests clean package 25 | # Then run your tests! 26 | - run: 27 | name: Test 28 | command: mvn test 29 | 30 | # Invoke jobs via workflows 31 | # See: https://circleci.com/docs/2.0/configuration-reference/#workflows 32 | workflows: 33 | sample: # This is the name of the workflow, feel free to change it to better match your workflow. 34 | # Inside the workflow, you define the jobs you want to run. 35 | jobs: 36 | - build-and-test 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | /target 3 | 4 | # Mobile Tools for Java (J2ME) 5 | .mtj.tmp/ 6 | 7 | # Package Files # 8 | *.jar 9 | *.war 10 | *.ear 11 | 12 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 13 | hs_err_pid* 14 | dependency-reduced-pom.xml 15 | deployment/log 16 | .idea 17 | adeptj-runtime.iml 18 | deployment 19 | target_swiftype 20 | *.pem 21 | *.prefs 22 | .classpath 23 | .project 24 | .DS_Store 25 | .factorypath 26 | /.apt_generated/ 27 | /.apt_generated_tests/ 28 | target 29 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | sudo: false 3 | install: true 4 | 5 | addons: 6 | sonarcloud: 7 | organization: "adeptj" 8 | token: 9 | secure: ${SONAR_TOKEN} 10 | 11 | jdk: 12 | - openjdk11 13 | 14 | script: 15 | - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.projectKey=adeptj-runtime 16 | 17 | cache: 18 | directories: 19 | - '$HOME/.m2/repository' 20 | - '$HOME/.sonar/cache' 21 | 22 | branches: 23 | only: 24 | - master -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # # 3 | # Copyright 2016, AdeptJ (http://adeptj.com) # 4 | # # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); # 6 | # you may not use this file except in compliance with the License. # 7 | # You may obtain a copy of the License at # 8 | # # 9 | # http://www.apache.org/licenses/LICENSE-2.0 # 10 | # # 11 | # Unless required by applicable law or agreed to in writing, software # 12 | # distributed under the License is distributed on an "AS IS" BASIS, # 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 14 | # See the License for the specific language governing permissions and # 15 | # limitations under the License. # 16 | # # 17 | ############################################################################### -------------------------------------------------------------------------------- /kernel/README.md: -------------------------------------------------------------------------------- 1 | # adeptj-runtime-kernel 2 | Core of AdeptJ Runtime 3 | -------------------------------------------------------------------------------- /kernel/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.adeptj 8 | adeptj-parent 9 | 45 10 | 11 | 12 | adeptj-runtime-kernel 13 | 1.0.0 14 | jar 15 | AdeptJ Runtime :: Kernel 16 | High performance, dynamic, modular runtime for RESTful APIs, MicroServices and WebApps. 17 | https://www.adeptj.com 18 | 2016 19 | 20 | 21 | UTF-8 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | org.apache.maven.plugins 30 | maven-compiler-plugin 31 | 32 | 33 | 34 | org.apache.maven.plugins 35 | maven-surefire-plugin 36 | 37 | ${skipTests} 38 | 39 | 40 | 41 | 42 | org.apache.maven.plugins 43 | maven-enforcer-plugin 44 | 45 | 46 | 47 | org.codehaus.mojo 48 | versions-maven-plugin 49 | 50 | false 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | org.apache.commons 62 | commons-lang3 63 | 64 | 65 | 66 | com.h2database 67 | h2-mvstore 68 | 69 | 70 | 71 | com.typesafe 72 | config 73 | 74 | 75 | 76 | org.slf4j 77 | slf4j-api 78 | 79 | 80 | 81 | jakarta.servlet 82 | jakarta.servlet-api 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/FilterInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel; 21 | 22 | import jakarta.servlet.Filter; 23 | 24 | /** 25 | * {@link Filter} info object needed for deployment on AdeptJ Runtime. 26 | * 27 | * @author Rakesh Kumar, AdeptJ 28 | */ 29 | public class FilterInfo { 30 | 31 | private final String filterName; 32 | 33 | private final String pattern; 34 | 35 | private Class filterClass; 36 | 37 | private Filter filterInstance; 38 | 39 | public FilterInfo(String filterName, String pattern) { 40 | this.filterName = filterName; 41 | this.pattern = pattern; 42 | } 43 | 44 | public String getFilterName() { 45 | return filterName; 46 | } 47 | 48 | public String getPattern() { 49 | return pattern; 50 | } 51 | 52 | public Class getFilterClass() { 53 | return filterClass; 54 | } 55 | 56 | public void setFilterClass(Class filterClass) { 57 | this.filterClass = filterClass; 58 | } 59 | 60 | public Filter getFilterInstance() { 61 | return filterInstance; 62 | } 63 | 64 | public void setFilterInstance(Filter filterInstance) { 65 | this.filterInstance = filterInstance; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/SciInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel; 21 | 22 | import jakarta.servlet.ServletContainerInitializer; 23 | import java.util.Set; 24 | 25 | /** 26 | * {@link ServletContainerInitializer} info object needed for deployment on AdeptJ Runtime. 27 | * 28 | * @author Rakesh Kumar, AdeptJ 29 | */ 30 | public class SciInfo { 31 | 32 | private ServletContainerInitializer sci; 33 | 34 | private final Set> handleTypes; 35 | 36 | private Class sciClass; 37 | 38 | // Tomcat and Jetty expects an instance of ServletContainerInitializer. 39 | public SciInfo(ServletContainerInitializer sci, Set> handleTypes) { 40 | this.sci = sci; 41 | this.handleTypes = handleTypes; 42 | } 43 | 44 | // Undertow expects ServletContainerInitializer class. 45 | public SciInfo(Class sciClass, Set> handleTypes) { 46 | this.sciClass = sciClass; 47 | this.handleTypes = handleTypes; 48 | } 49 | 50 | public ServletContainerInitializer getSciInstance() { 51 | return sci; 52 | } 53 | 54 | public Class getSciClass() { 55 | return sciClass; 56 | } 57 | 58 | public Set> getHandleTypes() { 59 | return handleTypes; 60 | } 61 | 62 | public Class[] getHandleTypesArray() { 63 | return this.handleTypes.toArray(new Class[0]); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/Server.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel; 21 | 22 | import com.typesafe.config.Config; 23 | import jakarta.servlet.ServletContainerInitializer; 24 | 25 | import java.util.List; 26 | 27 | /** 28 | * Server interface to be implemented by a given server adapter such as Tomcat, Jetty, Undertow etc. 29 | * 30 | * @author Rakesh Kumar, AdeptJ 31 | */ 32 | public interface Server { 33 | 34 | ServerRuntime getRuntime(); 35 | 36 | /** 37 | * Starts the given {@link Server} instance. 38 | * 39 | * @param deployment Servlet deployment information for (Tomcat or Jetty or Undertow) instance. 40 | * @param appConfig the application configuration. 41 | * @param args the program arguments to the server instance. 42 | */ 43 | void start(ServletDeployment deployment, Config appConfig, String[] args) throws Exception; 44 | 45 | default void postStart() { 46 | // NOOP 47 | } 48 | 49 | void stop(); 50 | 51 | default void registerServlets(List servletInfos) { 52 | } 53 | 54 | default void registerFilters(List filterInfos) { 55 | } 56 | 57 | default void registerErrorPages(List errorCodes) { 58 | } 59 | 60 | void addServletContextAttribute(String name, Object value); 61 | 62 | UserManager getUserManager(); 63 | } 64 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/ServerMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel; 21 | 22 | /** 23 | * Execution mode for optimizing server settings according to the mode provided. 24 | *

25 | * Note: Defaults to DEV mode. 26 | * 27 | * @author Rakesh.Kumar, AdeptJ 28 | */ 29 | public enum ServerMode { 30 | 31 | DEV, 32 | 33 | PROD 34 | } 35 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/ServerPostStopTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel; 21 | 22 | /** 23 | * A task that needs to be executed while server is stopping. 24 | * 25 | * @author Rakesh Kumar, AdeptJ 26 | */ 27 | public interface ServerPostStopTask { 28 | 29 | void execute(); 30 | } 31 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/ServerRuntime.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel; 21 | 22 | /** 23 | * Enum denoting the Server adapters supported by AdeptJ Runtime. 24 | * 25 | * @author Rakesh Kumar, AdeptJ 26 | */ 27 | public enum ServerRuntime { 28 | 29 | JETTY("Jetty"), 30 | 31 | TOMCAT("Tomcat"), 32 | 33 | UNDERTOW("Undertow"); 34 | 35 | private final String name; 36 | 37 | ServerRuntime(String name) { 38 | this.name = name; 39 | } 40 | 41 | public String getLowerCaseName() { 42 | return this.name.toLowerCase(); 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return this.name; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/ServerShutdownHook.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel; 21 | 22 | /** 23 | * A shutdown hook which stops the underlying server powering AdeptJ Runtime. 24 | * 25 | * @author Rakesh Kumar, AdeptJ 26 | */ 27 | public final class ServerShutdownHook extends Thread { 28 | 29 | private final Server server; 30 | 31 | public ServerShutdownHook(Server server, String threadName) { 32 | super(threadName); 33 | this.server = server; 34 | } 35 | 36 | /** 37 | * Calls the {@link Server#stop()} in run method. 38 | */ 39 | @Override 40 | public void run() { 41 | this.server.stop(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/ServletDeployment.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | /** 26 | * Deployment info object composing the {@link SciInfo}, Servlets and Filters needed to be deployed bu AdeptJ Runtime. 27 | * 28 | * @author Rakesh Kumar, AdeptJ 29 | */ 30 | public class ServletDeployment { 31 | 32 | private final SciInfo sciInfo; 33 | 34 | // Servlet 35 | private final List servletInfos; 36 | 37 | // Filter 38 | private final List filterInfos; 39 | 40 | public ServletDeployment(SciInfo sciInfo) { 41 | this.sciInfo = sciInfo; 42 | this.servletInfos = new ArrayList<>(); 43 | this.filterInfos = new ArrayList<>(); 44 | } 45 | 46 | public SciInfo getSciInfo() { 47 | return sciInfo; 48 | } 49 | 50 | public List getServletInfos() { 51 | return servletInfos; 52 | } 53 | 54 | public ServletDeployment addServletInfo(ServletInfo info) { 55 | this.servletInfos.add(info); 56 | return this; 57 | } 58 | 59 | public List getFilterInfos() { 60 | return filterInfos; 61 | } 62 | 63 | public ServletDeployment addFilterInfo(FilterInfo info) { 64 | this.filterInfos.add(info); 65 | return this; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/ServletInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel; 21 | 22 | import jakarta.servlet.http.HttpServlet; 23 | 24 | /** 25 | * {@link HttpServlet} info object needed for deployment on AdeptJ Runtime. 26 | * 27 | * @author Rakesh Kumar, AdeptJ 28 | */ 29 | public record ServletInfo(String servletName, String path, Class servletClass) { 30 | } 31 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/UserManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * UserManager interface for handling user authentication on AdeptJ Runtime. 26 | * 27 | * @author Rakesh Kumar, AdeptJ 28 | */ 29 | public interface UserManager { 30 | 31 | String getPassword(String username); 32 | 33 | boolean matchPassword(String inputPassword, String storedPassword); 34 | 35 | boolean matchPassword(char[] inputPassword, char[] storedPassword); 36 | 37 | String encodePassword(String password); 38 | 39 | List getRoles(String username); 40 | } 41 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/exception/RuntimeInitializationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.exception; 21 | 22 | import java.io.Serial; 23 | 24 | /** 25 | * RuntimeInitializationException: Exception thrown by AdeptJ Runtime initialization code. 26 | * 27 | * @author Rakesh.Kumar, AdeptJ 28 | */ 29 | public class RuntimeInitializationException extends RuntimeException { 30 | 31 | @Serial 32 | private static final long serialVersionUID = 6707002227136114960L; 33 | 34 | public RuntimeInitializationException(Throwable cause) { 35 | super(cause); 36 | } 37 | } -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/exception/ServerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.exception; 21 | 22 | import java.io.Serial; 23 | 24 | /** 25 | * ServerException: Exception thrown by AdeptJ Runtime. 26 | * 27 | * @author Rakesh.Kumar, AdeptJ 28 | */ 29 | public class ServerException extends RuntimeException { 30 | 31 | @Serial 32 | private static final long serialVersionUID = -1812814226481606887L; 33 | 34 | public ServerException(Throwable cause) { 35 | super(cause); 36 | } 37 | } -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/osgi/PackageExportsProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.osgi; 21 | 22 | /** 23 | * SPI for providing OSGi export packages. 24 | * 25 | * @author Rakesh Kumar, AdeptJ 26 | */ 27 | public interface PackageExportsProvider { 28 | 29 | default String getName() { 30 | return this.getClass().getName(); 31 | } 32 | 33 | /** 34 | * Gets the java packages to be exported by OSGi from system bundle. 35 | * 36 | * @return comma separated packages with version number, if any. 37 | */ 38 | String getPackageExports(); 39 | } 40 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/servlet/FaviconServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.servlet; 21 | 22 | import jakarta.servlet.ServletException; 23 | import jakarta.servlet.http.HttpServlet; 24 | import jakarta.servlet.http.HttpServletRequest; 25 | import jakarta.servlet.http.HttpServletResponse; 26 | 27 | import java.io.IOException; 28 | import java.io.Serial; 29 | 30 | /** 31 | * {@link HttpServlet} implementation for serving Favicon. 32 | * 33 | * @author Rakesh Kumar, AdeptJ 34 | */ 35 | public class FaviconServlet extends HttpServlet { 36 | 37 | @Serial 38 | private static final long serialVersionUID = -4158958392097965401L; 39 | 40 | private static final String CONTENT_TYPE = "image/x-icon"; 41 | 42 | private static final String FAVICON_PATH = "/static/img/favicon.ico"; 43 | 44 | @Override 45 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 46 | resp.setContentType(CONTENT_TYPE); 47 | req.getRequestDispatcher(FAVICON_PATH).include(req, resp); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/util/ClasspathResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.util; 21 | 22 | import java.io.IOException; 23 | import java.net.URL; 24 | import java.util.Enumeration; 25 | 26 | /** 27 | * Utility for accessing classpath resources such as files etc. 28 | * 29 | * @author Rakesh Kumar, AdeptJ 30 | */ 31 | public class ClasspathResource { 32 | 33 | public static URL toUrl(String resourceName, ClassLoader cl) { 34 | return cl.getResource(resourceName); 35 | } 36 | 37 | public static Enumeration toUrls(String resourceName, ClassLoader cl) throws IOException { 38 | return cl.getResources(resourceName); 39 | } 40 | 41 | private ClasspathResource() { 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/util/Configs.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.util; 21 | 22 | import com.typesafe.config.Config; 23 | import org.apache.commons.lang3.StringUtils; 24 | 25 | import java.util.Collections; 26 | import java.util.List; 27 | 28 | /** 29 | * Utility methods for typesafe {@link Config} object. 30 | * 31 | * @author Rakesh Kumar, AdeptJ 32 | */ 33 | public class Configs { 34 | 35 | /** 36 | * Checks whether a value is present and non-null at the given path. 37 | * 38 | * @return true or false basis a value is present and non-null at the given path. 39 | */ 40 | public static boolean isPresent(Config config, String path) { 41 | if (config == null || StringUtils.isEmpty(path)) { 42 | return false; 43 | } 44 | return config.hasPath(path); 45 | } 46 | 47 | public static List getStringList(Config config, String path) { 48 | if (isPresent(config, path)) { 49 | return config.getStringList(path); 50 | } 51 | return Collections.emptyList(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/util/Environment.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.util; 21 | 22 | import com.adeptj.runtime.kernel.ServerMode; 23 | 24 | import java.nio.file.Path; 25 | 26 | import static com.adeptj.runtime.kernel.Constants.CONF_DIR; 27 | import static com.adeptj.runtime.kernel.Constants.DIR_ADEPTJ_RUNTIME; 28 | import static com.adeptj.runtime.kernel.Constants.DIR_DEPLOYMENT; 29 | import static com.adeptj.runtime.kernel.Constants.FRAMEWORK_CONF_FILE; 30 | import static com.adeptj.runtime.kernel.Constants.SYS_PROP_SERVER_MODE; 31 | import static org.apache.commons.lang3.SystemUtils.USER_DIR; 32 | 33 | /** 34 | * Utility methods for getting environment details AdeptJ Runtime is running in. 35 | * 36 | * @author Rakesh.Kumar, AdeptJ. 37 | */ 38 | public final class Environment { 39 | 40 | /** 41 | * Deny direct instantiation. 42 | */ 43 | private Environment() { 44 | } 45 | 46 | public static boolean isDev() { 47 | return ServerMode.DEV.toString().equalsIgnoreCase(System.getProperty(SYS_PROP_SERVER_MODE)); 48 | } 49 | 50 | public static Path getConfDirPath() { 51 | return Path.of(USER_DIR, DIR_ADEPTJ_RUNTIME, DIR_DEPLOYMENT, CONF_DIR); 52 | } 53 | 54 | public static Path getFrameworkConfPath() { 55 | return Path.of(USER_DIR, DIR_ADEPTJ_RUNTIME, DIR_DEPLOYMENT, FRAMEWORK_CONF_FILE); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/util/IOUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.util; 21 | 22 | import java.io.ByteArrayOutputStream; 23 | import java.io.IOException; 24 | import java.io.InputStream; 25 | 26 | import static java.nio.charset.StandardCharsets.UTF_8; 27 | 28 | /** 29 | * Common utility methods. 30 | * 31 | * @author Rakesh.Kumar, AdeptJ 32 | */ 33 | public final class IOUtils { 34 | 35 | /** 36 | * Deny direct instantiation. 37 | */ 38 | private IOUtils() { 39 | } 40 | 41 | public static String toString(InputStream input) throws IOException { 42 | return toByteArrayOutputStream(input).toString(UTF_8); 43 | } 44 | 45 | public static byte[] toBytes(InputStream input) throws IOException { 46 | return toByteArrayOutputStream(input).toByteArray(); 47 | } 48 | 49 | private static ByteArrayOutputStream toByteArrayOutputStream(InputStream source) throws IOException { 50 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 51 | // Below section is borrowed (with much appreciation) from JBoss Xnio Streams.copyStream :) 52 | final byte[] buffer = new byte[8192]; 53 | int res; 54 | for (; ; ) { 55 | res = source.read(buffer); 56 | if (res == -1) { 57 | return out; 58 | } 59 | out.write(buffer, 0, res); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/util/KeyStores.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.util; 21 | 22 | import com.adeptj.runtime.kernel.exception.RuntimeInitializationException; 23 | 24 | import java.io.IOException; 25 | import java.io.InputStream; 26 | import java.nio.file.Files; 27 | import java.nio.file.Paths; 28 | import java.security.GeneralSecurityException; 29 | import java.security.KeyStore; 30 | 31 | /** 32 | * Utilities for Java KeyStore. 33 | * 34 | * @author Rakesh.Kumar, AdeptJ 35 | */ 36 | final class KeyStores { 37 | 38 | private KeyStores() { 39 | } 40 | 41 | static KeyStore getKeyStore(boolean p12FileExternal, String type, String p12Loc, char[] p12Pwd) { 42 | try (InputStream is = p12FileExternal 43 | ? Files.newInputStream(Paths.get(p12Loc)) : KeyStores.class.getResourceAsStream(p12Loc)) { 44 | KeyStore keyStore = KeyStore.getInstance(type); 45 | keyStore.load(is, p12Pwd); 46 | return keyStore; 47 | } catch (IOException | GeneralSecurityException ex) { 48 | throw new RuntimeInitializationException(ex); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/util/MVStoreUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.util; 21 | 22 | import org.h2.mvstore.MVMap; 23 | import org.h2.mvstore.MVStore; 24 | 25 | import static com.adeptj.runtime.kernel.Constants.H2_MAP_ADMIN_CREDENTIALS; 26 | import static com.adeptj.runtime.kernel.Constants.MV_CREDENTIALS_STORE; 27 | 28 | /** 29 | * Utility for MV Store. 30 | * 31 | * @author Rakesh Kumar, AdeptJ 32 | */ 33 | public final class MVStoreUtil { 34 | 35 | private MVStoreUtil() { 36 | } 37 | 38 | public static String getValue(String storeName, String mapName, String key) { 39 | try (MVStore store = MVStore.open(storeName)) { 40 | MVMap mvMap = store.openMap(mapName); 41 | return mvMap.get(key); 42 | } 43 | } 44 | 45 | public static String getPassword(String username) { 46 | return getValue(MV_CREDENTIALS_STORE, H2_MAP_ADMIN_CREDENTIALS, username); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/util/PasswordEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.util; 21 | 22 | import java.security.MessageDigest; 23 | import java.security.NoSuchAlgorithmException; 24 | import java.util.Base64; 25 | 26 | import static com.adeptj.runtime.kernel.Constants.SHA_256; 27 | import static java.nio.charset.StandardCharsets.UTF_8; 28 | 29 | /** 30 | * Password encoding utility. 31 | * 32 | * @author Rakesh Kumar, AdeptJ 33 | */ 34 | public class PasswordEncoder { 35 | 36 | public static byte[] encodePassword(byte[] password) { 37 | return Base64.getEncoder().encode(sha256(password)); 38 | } 39 | 40 | public static byte[] encodePassword(String password) { 41 | return Base64.getEncoder().encode(sha256(password.getBytes(UTF_8))); 42 | } 43 | 44 | private static byte[] sha256(byte[] inputPwdBytes) { 45 | try { 46 | return MessageDigest.getInstance(SHA_256).digest(inputPwdBytes); 47 | } catch (final NoSuchAlgorithmException ex) { 48 | throw new IllegalArgumentException(ex); 49 | } 50 | } 51 | 52 | private PasswordEncoder() { 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/util/RequestUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.util; 21 | 22 | import com.adeptj.runtime.kernel.exception.ServerException; 23 | import jakarta.servlet.ServletException; 24 | import jakarta.servlet.http.HttpServletRequest; 25 | import org.apache.commons.lang3.exception.ExceptionUtils; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | 29 | import static jakarta.servlet.RequestDispatcher.ERROR_EXCEPTION; 30 | 31 | /** 32 | * Utils for {@link HttpServletRequest} 33 | * 34 | * @author Rakesh.Kumar, AdeptJ 35 | */ 36 | public final class RequestUtil { 37 | 38 | private static final Logger LOGGER = LoggerFactory.getLogger(RequestUtil.class); 39 | 40 | private RequestUtil() { 41 | } 42 | 43 | public static Object getAttribute(HttpServletRequest req, String name) { 44 | return req.getAttribute(name); 45 | } 46 | 47 | public static boolean hasException(HttpServletRequest req) { 48 | return getAttribute(req, ERROR_EXCEPTION) != null; 49 | } 50 | 51 | public static String getException(HttpServletRequest req) { 52 | return ExceptionUtils.getStackTrace((Throwable) RequestUtil.getAttribute(req, ERROR_EXCEPTION)); 53 | } 54 | 55 | public static void logout(HttpServletRequest req) { 56 | try { 57 | req.logout(); 58 | } catch (ServletException ex) { 59 | LOGGER.error(ex.getMessage(), ex); 60 | throw new ServerException(ex); 61 | } 62 | } 63 | 64 | public static boolean isContextRootRequest(HttpServletRequest req) { 65 | return isContextRootRequest(req.getRequestURI()); 66 | } 67 | 68 | public static boolean isContextRootRequest(String requestPath) { 69 | return requestPath.equals("/") || requestPath.startsWith("/;jsessionid"); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/util/SslContextFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.util; 21 | 22 | import com.typesafe.config.Config; 23 | 24 | import javax.net.ssl.KeyManagerFactory; 25 | import javax.net.ssl.SSLContext; 26 | import java.security.GeneralSecurityException; 27 | import java.security.KeyStore; 28 | 29 | import static com.adeptj.runtime.kernel.Constants.KEY_KEYSTORE_TYPE; 30 | import static com.adeptj.runtime.kernel.Constants.KEY_P12_FILE_LOCATION; 31 | import static com.adeptj.runtime.kernel.Constants.KEY_P12_PASSWORD; 32 | import static com.adeptj.runtime.kernel.Constants.KEY_TLS_VERSION; 33 | import static com.adeptj.runtime.kernel.Constants.SYS_PROP_P12_FILE_EXTERNAL; 34 | import static com.adeptj.runtime.kernel.Constants.SYS_PROP_P12_FILE_LOCATION; 35 | import static com.adeptj.runtime.kernel.Constants.SYS_PROP_P12_PASSWORD; 36 | import static com.adeptj.runtime.kernel.Constants.SYS_PROP_TLS_VERSION; 37 | 38 | /** 39 | * Utilities for SSL/TLS. 40 | * 41 | * @author Rakesh.Kumar, AdeptJ 42 | */ 43 | public final class SslContextFactory { 44 | 45 | private SslContextFactory() { 46 | } 47 | 48 | public static SSLContext newSslContext(Config httpsConf) throws GeneralSecurityException { 49 | String p12Loc; 50 | char[] p12Pwd; 51 | boolean p12FileExternal = Boolean.getBoolean(SYS_PROP_P12_FILE_EXTERNAL); 52 | if (p12FileExternal) { 53 | p12Loc = System.getProperty(SYS_PROP_P12_FILE_LOCATION); 54 | p12Pwd = System.getProperty(SYS_PROP_P12_PASSWORD).toCharArray(); 55 | } else { 56 | p12Loc = httpsConf.getString(KEY_P12_FILE_LOCATION); 57 | p12Pwd = httpsConf.getString(KEY_P12_PASSWORD).toCharArray(); 58 | } 59 | String keyStoreType = httpsConf.getString(KEY_KEYSTORE_TYPE); 60 | KeyStore keyStore = KeyStores.getKeyStore(p12FileExternal, keyStoreType, p12Loc, p12Pwd); 61 | KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); 62 | kmf.init(keyStore, p12Pwd); 63 | String protocol = System.getProperty(SYS_PROP_TLS_VERSION, httpsConf.getString(KEY_TLS_VERSION)); 64 | SSLContext sslContext = SSLContext.getInstance(protocol); 65 | // tm is initialized by SSLContext impl, that's why passing a null. 66 | sslContext.init(kmf.getKeyManagers(), null, null); 67 | return sslContext; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /kernel/src/main/java/com/adeptj/runtime/kernel/util/Times.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.kernel.util; 21 | 22 | import static java.util.concurrent.TimeUnit.MILLISECONDS; 23 | import static java.util.concurrent.TimeUnit.NANOSECONDS; 24 | 25 | /** 26 | * Utility for providing execution time in different {@link java.util.concurrent.TimeUnit}. 27 | * 28 | * @author Rakesh.Kumar, AdeptJ 29 | */ 30 | public final class Times { 31 | 32 | // No instances, just utility methods. 33 | private Times() { 34 | } 35 | 36 | /** 37 | * Returns elapsed time in milliseconds from the provided time in nanoseconds. 38 | * 39 | * @param startTime time in nanoseconds 40 | * @return elapsed time in milliseconds 41 | */ 42 | public static long elapsedMillis(final long startTime) { 43 | return NANOSECONDS.toMillis(System.nanoTime() - startTime); 44 | } 45 | 46 | /** 47 | * Returns elapsed time in seconds from the provided time in milliseconds. 48 | * 49 | * @param startTime time in milliseconds 50 | * @return elapsed time in seconds 51 | */ 52 | public static long elapsedSeconds(final long startTime) { 53 | return MILLISECONDS.toSeconds(System.currentTimeMillis() - startTime); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /kernel/src/main/resources/i18n/kernel.properties: -------------------------------------------------------------------------------- 1 | ajrt.port.system.property.not.specified=No port specified via system property: [adeptj.rt.port], will resolve port from configs! -------------------------------------------------------------------------------- /kernel/src/main/resources/reference.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # # 3 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 4 | # # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); # 6 | # you may not use this file except in compliance with the License. # 7 | # You may obtain a copy of the License at # 8 | # # 9 | # http://www.apache.org/licenses/LICENSE-2.0 # 10 | # # 11 | # Unless required by applicable law or agreed to in writing, software # 12 | # distributed under the License is distributed on an "AS IS" BASIS, # 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 14 | # See the License for the specific language governing permissions and # 15 | # limitations under the License. # 16 | # # 17 | ############################################################################### 18 | 19 | kernel: { 20 | server.port: 8080 21 | server.context.path: "" 22 | } -------------------------------------------------------------------------------- /main/NOTICE: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # # 3 | # Copyright 2016, AdeptJ (http://adeptj.com) # 4 | # # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); # 6 | # you may not use this file except in compliance with the License. # 7 | # You may obtain a copy of the License at # 8 | # # 9 | # http://www.apache.org/licenses/LICENSE-2.0 # 10 | # # 11 | # Unless required by applicable law or agreed to in writing, software # 12 | # distributed under the License is distributed on an "AS IS" BASIS, # 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 14 | # See the License for the specific language governing permissions and # 15 | # limitations under the License. # 16 | # # 17 | ############################################################################### -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/common/BridgeServletConfigHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.common; 22 | 23 | import jakarta.servlet.ServletConfig; 24 | 25 | /** 26 | * Maintains the BridgeServlet's {@link ServletConfig} instance. 27 | * 28 | * @author Rakesh.Kumar, AdeptJ 29 | */ 30 | public enum BridgeServletConfigHolder { 31 | 32 | INSTANCE; 33 | 34 | private ServletConfig bridgeServletConfig; 35 | 36 | public void setBridgeServletConfig(ServletConfig bridgeServletConfig) { // NOSONAR 37 | if (this.bridgeServletConfig == null) { 38 | this.bridgeServletConfig = bridgeServletConfig; 39 | } 40 | } 41 | 42 | public ServletConfig getBridgeServletConfig() { 43 | return bridgeServletConfig; 44 | } 45 | 46 | public static BridgeServletConfigHolder getInstance() { 47 | return INSTANCE; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/common/BundleContextHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.common; 22 | 23 | import org.osgi.framework.BundleContext; 24 | 25 | /** 26 | * This Enum provides the access to the OSGi System Bundle {@link BundleContext}. 27 | * 28 | * @author Rakesh.Kumar, AdeptJ 29 | */ 30 | public enum BundleContextHolder { 31 | 32 | INSTANCE; 33 | 34 | private BundleContext bundleContext; 35 | 36 | public BundleContext getBundleContext() { 37 | return this.bundleContext; 38 | } 39 | 40 | public void setBundleContext(BundleContext bundleContext) { // NOSONAR 41 | this.bundleContext = bundleContext; 42 | } 43 | 44 | public static BundleContextHolder getInstance() { 45 | return INSTANCE; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/common/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.common; 22 | 23 | /** 24 | * Constants, common constants for AdeptJ Runtime. 25 | * 26 | * @author Rakesh.Kumar, AdeptJ 27 | */ 28 | public final class Constants { 29 | 30 | public static final String BUNDLES_ROOT_DIR_KEY = "bundles-root-dir"; 31 | 32 | public static final String ATTRIBUTE_BUNDLE_CONTEXT = "org.osgi.framework.BundleContext"; 33 | 34 | public static final String PEBBLE_CONF_SECTION = "pebble"; 35 | 36 | public static final String FELIX_CONF_SECTION = "felix"; 37 | 38 | public static final String LOGGING_CONF_SECTION = "logging"; 39 | 40 | public static final String VAR_ERROR_CODE = "errorCode"; 41 | 42 | public static final String ADMIN_LOGOUT_URI = "/admin/logout"; 43 | 44 | public static final String ADMIN_SERVLET_NAME = "AdeptJ AdminServlet"; 45 | 46 | public static final String ADMIN_SERVLET_URI = "/admin/*"; 47 | 48 | public static final String ERROR_SERVLET_URI = "/ErrorHandler"; 49 | 50 | public static final String ERROR_SERVLET_NAME = "AdeptJ ErrorServlet"; 51 | 52 | public static final String LOGBACK_VIEW_SERVLET_NAME = "Logback ViewStatusMessagesServlet"; 53 | 54 | public static final String LOGBACK_VIEW_SERVLET_URI = "/admin/logback-status"; 55 | 56 | public static final String FAVICON_SERVLET_NAME = "AdeptJ FaviconServlet"; 57 | 58 | public static final String FAVICON_SERVLET_URI = "/favicon.ico"; 59 | 60 | public static final String BANNER_TXT = "/banner.txt"; 61 | 62 | public static final String CONTENT_TYPE_HTML_UTF8 = "text/html;charset=UTF-8"; 63 | 64 | public static final String OSGI_ADMIN_ROLE = "OSGiAdmin"; 65 | 66 | public static final String MV_CREDENTIALS_STORE = "credentials.dat"; 67 | 68 | public static final String H2_MAP_ADMIN_CREDENTIALS = "adminCredentials"; 69 | 70 | /** 71 | * Deny direct instantiation. 72 | */ 73 | private Constants() { 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/common/LogbackManagerHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.common; 22 | 23 | import com.adeptj.runtime.logging.LogbackManager; 24 | 25 | /** 26 | * This Enum provides the access to the {@link LogbackManager}. 27 | * 28 | * @author Rakesh.Kumar, AdeptJ 29 | */ 30 | public enum LogbackManagerHolder { 31 | 32 | INSTANCE; 33 | 34 | private LogbackManager logbackManager; 35 | 36 | public void setLogbackManager(LogbackManager logbackManager) { 37 | if (this.logbackManager == null) { 38 | this.logbackManager = logbackManager; 39 | } 40 | } 41 | 42 | public LogbackManager getLogbackManager() { 43 | return this.logbackManager; 44 | } 45 | 46 | public static LogbackManagerHolder getInstance() { 47 | return INSTANCE; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/common/ServerMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://wwwadeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.common; 22 | 23 | /** 24 | * Execution mode for optimizing server settings according to the mode provided. 25 | *

26 | * Note: Defaults to DEV mode. 27 | * 28 | * @author Rakesh.Kumar, AdeptJ 29 | */ 30 | public enum ServerMode { 31 | 32 | DEV, 33 | 34 | PROD 35 | } 36 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/common/ServletContextHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.common; 22 | 23 | import jakarta.servlet.ServletContext; 24 | 25 | /** 26 | * This Enum provides the access to the {@link ServletContext} and corresponding attributes. 27 | * 28 | * @author Rakesh.Kumar, AdeptJ 29 | */ 30 | public enum ServletContextHolder { 31 | 32 | INSTANCE; 33 | 34 | private ServletContext context; 35 | 36 | public void setServletContext(ServletContext context) { // NOSONAR 37 | if (this.context == null) { 38 | this.context = context; 39 | } 40 | } 41 | 42 | public ServletContext getServletContext() { 43 | return this.context; 44 | } 45 | 46 | public T getContextAttributeOfType(String name, Class type) { 47 | final Object value = this.context.getAttribute(name); 48 | return type.isInstance(value) ? type.cast(value) : null; 49 | } 50 | 51 | public void setContextAttribute(String name, Object value) { 52 | this.context.setAttribute(name, value); 53 | } 54 | 55 | public static ServletContextHolder getInstance() { 56 | return INSTANCE; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/core/DefaultStartupAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.core; 22 | 23 | import com.adeptj.runtime.common.Servlets; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import jakarta.servlet.ServletContext; 28 | 29 | /** 30 | * DefaultStartupAware is a {@link StartupAware} that registers the bridge listeners and servlet. 31 | * 32 | * @author Rakesh.Kumar, AdeptJ 33 | */ 34 | public class DefaultStartupAware implements StartupAware { 35 | 36 | /** 37 | * {@inheritDoc} 38 | */ 39 | @Override 40 | public void onStartup(ServletContext servletContext) { 41 | Logger logger = LoggerFactory.getLogger(DefaultStartupAware.class); 42 | Servlets.registerBridgeListeners(servletContext); 43 | logger.info("OSGi bridge listeners registered successfully!!"); 44 | Servlets.registerBridgeServlet(servletContext); 45 | logger.info("BridgeServlet registered successfully!!"); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/core/LoggerCleanupTask.java: -------------------------------------------------------------------------------- 1 | package com.adeptj.runtime.core; 2 | 3 | import com.adeptj.runtime.common.LogbackManagerHolder; 4 | import com.adeptj.runtime.kernel.ServerPostStopTask; 5 | 6 | public class LoggerCleanupTask implements ServerPostStopTask { 7 | 8 | @Override 9 | public void execute() { 10 | LogbackManagerHolder.getInstance().getLogbackManager().cleanup(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/core/ServerBootstrapper.java: -------------------------------------------------------------------------------- 1 | package com.adeptj.runtime.core; 2 | 3 | import ch.qos.logback.classic.ViewStatusMessagesServlet; 4 | import com.adeptj.runtime.kernel.SciInfo; 5 | import com.adeptj.runtime.kernel.Server; 6 | import com.adeptj.runtime.kernel.ServletDeployment; 7 | import com.adeptj.runtime.kernel.ServletInfo; 8 | import com.adeptj.runtime.kernel.servlet.FaviconServlet; 9 | import com.adeptj.runtime.osgi.FrameworkLauncher; 10 | import com.adeptj.runtime.servlet.AdminServlet; 11 | import com.adeptj.runtime.servlet.ErrorServlet; 12 | import com.typesafe.config.Config; 13 | 14 | import java.util.LinkedHashSet; 15 | import java.util.Set; 16 | 17 | import static com.adeptj.runtime.common.Constants.ADMIN_SERVLET_NAME; 18 | import static com.adeptj.runtime.common.Constants.ADMIN_SERVLET_URI; 19 | import static com.adeptj.runtime.common.Constants.ERROR_SERVLET_NAME; 20 | import static com.adeptj.runtime.common.Constants.ERROR_SERVLET_URI; 21 | import static com.adeptj.runtime.common.Constants.FAVICON_SERVLET_NAME; 22 | import static com.adeptj.runtime.common.Constants.FAVICON_SERVLET_URI; 23 | import static com.adeptj.runtime.common.Constants.LOGBACK_VIEW_SERVLET_NAME; 24 | import static com.adeptj.runtime.common.Constants.LOGBACK_VIEW_SERVLET_URI; 25 | import static com.adeptj.runtime.kernel.ServerRuntime.UNDERTOW; 26 | 27 | /** 28 | * Bootstrap the given {@link Server} instance. 29 | * 30 | * @author Rakesh Kumar, AdeptJ 31 | */ 32 | public final class ServerBootstrapper { 33 | 34 | /** 35 | * Bootstrap the given {@link Server} instance. 36 | * 37 | * @param server the {@link Server} (Tomcat, Jetty, Undertow) instance. 38 | * @param appConfig the application configuration. 39 | * @param args the program arguments to the server instance. 40 | */ 41 | public static void bootstrap(Server server, Config appConfig, String[] args) throws Exception { 42 | Set> handleTypes = new LinkedHashSet<>(); 43 | handleTypes.add(FrameworkLauncher.class); 44 | handleTypes.add(DefaultStartupAware.class); 45 | SciInfo sciInfo; 46 | // Undertow expects a ServletContainerInitializer class instance. 47 | if (server.getRuntime() == UNDERTOW) { 48 | sciInfo = new SciInfo(RuntimeInitializer.class, handleTypes); 49 | } else { 50 | sciInfo = new SciInfo(new RuntimeInitializer(), handleTypes); 51 | } 52 | ServletDeployment deployment = new ServletDeployment(sciInfo) 53 | .addServletInfo(new ServletInfo(ADMIN_SERVLET_NAME, ADMIN_SERVLET_URI, AdminServlet.class)) 54 | .addServletInfo(new ServletInfo(ERROR_SERVLET_NAME, ERROR_SERVLET_URI, ErrorServlet.class)) 55 | .addServletInfo(new ServletInfo(FAVICON_SERVLET_NAME, FAVICON_SERVLET_URI, FaviconServlet.class)) 56 | .addServletInfo(new ServletInfo(LOGBACK_VIEW_SERVLET_NAME, LOGBACK_VIEW_SERVLET_URI, 57 | ViewStatusMessagesServlet.class)); 58 | server.start(deployment, appConfig, args); 59 | } 60 | 61 | private ServerBootstrapper() { 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/core/StartupAware.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.core; 22 | 23 | import jakarta.servlet.ServletContext; 24 | import jakarta.servlet.ServletException; 25 | 26 | /** 27 | * This will be called by the ServletContainerInitializer while startup is in progress because this is 28 | * declared as a HandlesTypes. 29 | * 30 | * @author Rakesh.Kumar, AdeptJ 31 | */ 32 | @FunctionalInterface 33 | public interface StartupAware { 34 | 35 | /** 36 | * This method will be called by the ServletContainerInitializer while startup is in progress. 37 | * 38 | * @param servletContext the {@link ServletContext} in which this StartupAware runs in. 39 | * @throws ServletException exception thrown by startup code 40 | */ 41 | void onStartup(ServletContext servletContext) throws ServletException; 42 | } 43 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/exception/RuntimeInitializationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.exception; 22 | 23 | import java.io.Serial; 24 | 25 | /** 26 | * RuntimeInitializationException: Exception thrown by AdeptJ Runtime initialization code. 27 | * 28 | * @author Rakesh.Kumar, AdeptJ 29 | */ 30 | public class RuntimeInitializationException extends RuntimeException { 31 | 32 | @Serial 33 | private static final long serialVersionUID = -1731078900410045078L; 34 | 35 | public RuntimeInitializationException(Throwable cause) { 36 | super(cause); 37 | } 38 | } -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/exception/ServerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.exception; 22 | 23 | import java.io.Serial; 24 | 25 | /** 26 | * ServerException: Exception thrown by AdeptJ Runtime. 27 | * 28 | * @author Rakesh.Kumar, AdeptJ 29 | */ 30 | public class ServerException extends RuntimeException { 31 | 32 | @Serial 33 | private static final long serialVersionUID = -7931100309885768442L; 34 | 35 | public ServerException(Throwable cause) { 36 | super(cause); 37 | } 38 | } -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/html/I18nSupport.java: -------------------------------------------------------------------------------- 1 | package com.adeptj.runtime.html; 2 | 3 | import io.pebbletemplates.pebble.extension.AbstractExtension; 4 | import io.pebbletemplates.pebble.extension.Function; 5 | import io.pebbletemplates.pebble.extension.i18n.UTF8Control; 6 | import io.pebbletemplates.pebble.template.EvaluationContext; 7 | import io.pebbletemplates.pebble.template.PebbleTemplate; 8 | import org.apache.commons.lang3.StringUtils; 9 | 10 | import java.text.MessageFormat; 11 | import java.util.ArrayList; 12 | import java.util.HashMap; 13 | import java.util.List; 14 | import java.util.Map; 15 | import java.util.ResourceBundle; 16 | 17 | import static com.adeptj.runtime.common.Constants.VAR_ERROR_CODE; 18 | 19 | /** 20 | * This class replaces the default i18n extension provided by Pebble, this is done to cater AdeptJ Runtime requirements. 21 | * 22 | * @author Rakesh Kumar, AdeptJ 23 | */ 24 | public class I18nSupport extends AbstractExtension implements Function { 25 | 26 | private final String rbDir; 27 | 28 | private final List argumentNames; 29 | 30 | public I18nSupport(String rbDir) { 31 | this.rbDir = rbDir; 32 | this.argumentNames = new ArrayList<>(); 33 | this.argumentNames.add("bundle"); 34 | this.argumentNames.add("key"); 35 | this.argumentNames.add("params"); 36 | } 37 | 38 | // ----------------------------------------- Extension Methods ----------------------------------------- 39 | 40 | @Override 41 | public Map getFunctions() { 42 | Map functions = new HashMap<>(); 43 | functions.put("i18n", this); 44 | return functions; 45 | } 46 | 47 | // ------------------------------------------ Function Methods ------------------------------------------ 48 | 49 | @Override 50 | public List getArgumentNames() { 51 | return this.argumentNames; 52 | } 53 | 54 | @Override 55 | public Object execute(Map args, PebbleTemplate self, EvaluationContext context, int lineNumber) { 56 | String basename = (String) args.get("bundle"); 57 | ResourceBundle rb = ResourceBundle.getBundle(this.rbDir + basename, context.getLocale(), 58 | new UTF8Control()); 59 | String key = (String) args.get("key"); 60 | Object errorCode = context.getVariable(VAR_ERROR_CODE); 61 | Object phraseObject; 62 | if (errorCode == null || StringUtils.equals(key, "go.home.msg")) { 63 | phraseObject = rb.getObject(key); 64 | } else { 65 | phraseObject = rb.getObject(errorCode + "." + key); 66 | } 67 | Object params = args.get("params"); 68 | if (params == null) { 69 | return phraseObject; 70 | } 71 | if (params instanceof List list) { 72 | phraseObject = MessageFormat.format(phraseObject.toString(), list.toArray()); 73 | } else { 74 | phraseObject = MessageFormat.format(phraseObject.toString(), params); 75 | } 76 | return phraseObject; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/html/TemplateProcessingException.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.html; 22 | 23 | import java.io.Serial; 24 | 25 | /** 26 | * The {@link TemplateProcessingException} thrown when an exception occurred while processing a given template. 27 | * 28 | * @author Rakesh.Kumar, AdeptJ. 29 | */ 30 | final class TemplateProcessingException extends RuntimeException { 31 | 32 | @Serial 33 | private static final long serialVersionUID = -8077495079692215520L; 34 | 35 | TemplateProcessingException(Throwable cause) { 36 | super(cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/logging/DebugLevelHighlightingConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.logging; 22 | 23 | import ch.qos.logback.classic.pattern.color.HighlightingCompositeConverter; 24 | import ch.qos.logback.classic.spi.ILoggingEvent; 25 | 26 | import static ch.qos.logback.classic.Level.DEBUG_INT; 27 | import static ch.qos.logback.core.pattern.color.ANSIConstants.YELLOW_FG; 28 | 29 | /** 30 | * Extended version of {@link HighlightingCompositeConverter} which prints debug log level in yellow. 31 | * 32 | * @author Rakesh.Kumar, AdeptJ 33 | */ 34 | public class DebugLevelHighlightingConverter extends HighlightingCompositeConverter { 35 | 36 | @Override 37 | protected String getForegroundColorCode(ILoggingEvent event) { 38 | if (event.getLevel().toInt() == DEBUG_INT) { 39 | return YELLOW_FG; 40 | } 41 | return super.getForegroundColorCode(event); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/logging/LogbackInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.logging; 22 | 23 | import ch.qos.logback.classic.LoggerContext; 24 | import ch.qos.logback.classic.spi.Configurator; 25 | import ch.qos.logback.classic.spi.ConfiguratorRank; 26 | import ch.qos.logback.core.spi.ContextAwareBase; 27 | import ch.qos.logback.core.util.StatusPrinter2; 28 | import com.adeptj.runtime.common.LogbackManagerHolder; 29 | import com.adeptj.runtime.kernel.ConfigProvider; 30 | import com.typesafe.config.Config; 31 | import org.slf4j.bridge.SLF4JBridgeHandler; 32 | 33 | import static com.adeptj.runtime.common.Constants.LOGGING_CONF_SECTION; 34 | 35 | /** 36 | * This Class initializes the Logback logging framework. 37 | *

38 | * Usually Logback is initialized via logback.xml file on classpath but programmatic approach is faster and takes 39 | * about ~ 140 milliseconds to fully bootstrap Logback. 40 | *

41 | * Note: 05-Aug-2023 - {@link ConfiguratorRank} was introduced in Logback v1.4.9 42 | * 43 | * @author Rakesh.Kumar, AdeptJ 44 | */ 45 | @ConfiguratorRank(value = ConfiguratorRank.CUSTOM_TOP_PRIORITY) 46 | public final class LogbackInitializer extends ContextAwareBase implements Configurator { 47 | 48 | /** 49 | * See class description for details. 50 | * 51 | * @param context the {@link LoggerContext} 52 | */ 53 | @Override 54 | public ExecutionStatus configure(LoggerContext context) { 55 | Config loggingCfg = ConfigProvider.getInstance().getMainConfig().getConfig(LOGGING_CONF_SECTION); 56 | LogbackManager logbackManager = new LogbackManager(context); 57 | LogbackManagerHolder.getInstance().setLogbackManager(logbackManager); 58 | // Initialize ConsoleAppender. 59 | logbackManager.initConsoleAppender(loggingCfg); 60 | // Initialize RollingFileAppender. 61 | logbackManager.initRollingFileAppender(loggingCfg); 62 | // Update level and add appenders to ROOT Logger 63 | logbackManager.configureRootLogger(loggingCfg); 64 | // Add all the loggers defined in server.conf logging section. 65 | logbackManager.addServerConfigLoggers(loggingCfg); 66 | // SLF4J JUL Bridge. 67 | SLF4JBridgeHandler.removeHandlersForRootLogger(); 68 | SLF4JBridgeHandler.install(); 69 | // LevelChangePropagator - see http://logback.qos.ch/manual/configuration.html#LevelChangePropagator 70 | logbackManager.initLevelChangePropagator(); 71 | // Finally, start LoggerContext and print status information. 72 | context.start(); 73 | new StatusPrinter2().printInCaseOfErrorsOrWarnings(context); 74 | return ExecutionStatus.DO_NOT_INVOKE_NEXT_IF_ANY; 75 | } 76 | } -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/logging/OSGiLoggerConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.logging; 22 | 23 | import java.util.Set; 24 | 25 | /** 26 | * Configurations for creating a Logback Logger. 27 | * 28 | * @author Rakesh.Kumar, AdeptJ 29 | */ 30 | class OSGiLoggerConfig { 31 | 32 | private final String configPid; 33 | 34 | private final Set categories; 35 | 36 | private final String level; 37 | 38 | OSGiLoggerConfig(String configPid, Set categories, String level) { 39 | this.configPid = configPid; 40 | this.categories = categories; 41 | this.level = level; 42 | } 43 | 44 | public String getConfigPid() { 45 | return configPid; 46 | } 47 | 48 | public Set getCategories() { 49 | return this.categories; 50 | } 51 | 52 | public String getLevel() { 53 | return this.level; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/osgi/BridgeHttpSessionIdListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.osgi; 22 | 23 | import jakarta.servlet.http.HttpSessionEvent; 24 | import jakarta.servlet.http.HttpSessionIdListener; 25 | 26 | /** 27 | * An {@link HttpSessionIdListener} which propagates the {@link jakarta.servlet.http.HttpSession} Id change 28 | * event to Felix {@link org.apache.felix.http.base.internal.EventDispatcher}. 29 | * 30 | * @author Rakesh.Kumar, AdeptJ 31 | */ 32 | public class BridgeHttpSessionIdListener implements HttpSessionIdListener { 33 | 34 | @Override 35 | public void sessionIdChanged(HttpSessionEvent event, String oldSessionId) { 36 | HttpSessionEvents.handleSessionIdChangedEvent(event, oldSessionId); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/osgi/BridgeHttpSessionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.osgi; 22 | 23 | import jakarta.servlet.http.HttpSessionEvent; 24 | import jakarta.servlet.http.HttpSessionListener; 25 | 26 | /** 27 | * An {@link HttpSessionListener} which propagates the {@link jakarta.servlet.http.HttpSession} create and destroy 28 | * event to Felix {@link org.apache.felix.http.base.internal.EventDispatcher}. 29 | * 30 | * @author Rakesh.Kumar, AdeptJ 31 | */ 32 | public class BridgeHttpSessionListener implements HttpSessionListener { 33 | 34 | @Override 35 | public void sessionCreated(HttpSessionEvent se) { 36 | HttpSessionEvents.handleHttpSessionEvent(HttpSessionEvents.SESSION_CREATED, se); 37 | } 38 | 39 | @Override 40 | public void sessionDestroyed(HttpSessionEvent se) { 41 | HttpSessionEvents.handleHttpSessionEvent(HttpSessionEvents.SESSION_DESTROYED, se); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/osgi/BridgeServletContextAttributeListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.osgi; 22 | 23 | import com.adeptj.runtime.common.BundleContextHolder; 24 | import org.apache.commons.lang3.StringUtils; 25 | import org.osgi.framework.BundleContext; 26 | 27 | import jakarta.servlet.ServletContextAttributeEvent; 28 | import jakarta.servlet.ServletContextAttributeListener; 29 | 30 | import static com.adeptj.runtime.common.Constants.ATTRIBUTE_BUNDLE_CONTEXT; 31 | 32 | /** 33 | * A {@link ServletContextAttributeListener} which initializes the {@link EventDispatcherTracker} 34 | * when {@link BundleContext} is being set as a {@link jakarta.servlet.ServletContext} attribute and again closes 35 | * and opens when {@link BundleContext} is replaced as a {@link jakarta.servlet.ServletContext} attribute. 36 | * 37 | * @author Rakesh.Kumar, AdeptJ 38 | */ 39 | public class BridgeServletContextAttributeListener implements ServletContextAttributeListener { 40 | 41 | @Override 42 | public void attributeAdded(ServletContextAttributeEvent event) { 43 | if (StringUtils.equals(event.getName(), ATTRIBUTE_BUNDLE_CONTEXT)) { 44 | ServiceTrackers.getInstance().openEventDispatcherTracker((BundleContext) event.getValue()); 45 | } 46 | } 47 | 48 | @Override 49 | public void attributeReplaced(ServletContextAttributeEvent event) { 50 | if (StringUtils.equals(event.getName(), ATTRIBUTE_BUNDLE_CONTEXT)) { 51 | ServiceTrackers.getInstance().closeEventDispatcherTracker(); 52 | /* 53 | * Now open the EventDispatcherTracker with fresh BundleContext which is already hold by 54 | * BundleContextHolder after being set in FrameworkLifecycleListener. 55 | * 56 | * Rationale: If we use the BundleContext contained in the event passed which is a stale 57 | * BundleContext in case of a framework restart event and results in an IllegalStateException. 58 | */ 59 | ServiceTrackers.getInstance() 60 | .openEventDispatcherTracker(BundleContextHolder.getInstance().getBundleContext()); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/osgi/DispatcherServletConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.osgi; 21 | 22 | import jakarta.servlet.ServletConfig; 23 | import jakarta.servlet.ServletContext; 24 | import java.util.Enumeration; 25 | 26 | /** 27 | * {@link ServletConfig} for Felix {@link org.apache.felix.http.base.internal.dispatch.DispatcherServlet}. 28 | * 29 | * @author Rakesh.Kumar, AdeptJ 30 | */ 31 | public class DispatcherServletConfig implements ServletConfig { 32 | 33 | private final ServletConfig bridgeServletConfig; 34 | 35 | public DispatcherServletConfig(ServletConfig bridgeServletConfig) { 36 | this.bridgeServletConfig = bridgeServletConfig; 37 | } 38 | 39 | @Override 40 | public String getServletName() { 41 | return "Felix DispatcherServlet in Bridge Mode"; 42 | } 43 | 44 | @Override 45 | public ServletContext getServletContext() { 46 | return this.bridgeServletConfig.getServletContext(); 47 | } 48 | 49 | @Override 50 | public String getInitParameter(String name) { 51 | return this.bridgeServletConfig.getInitParameter(name); 52 | } 53 | 54 | @Override 55 | public Enumeration getInitParameterNames() { 56 | return this.bridgeServletConfig.getInitParameterNames(); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/osgi/DispatcherServletWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.osgi; 22 | 23 | import com.adeptj.runtime.kernel.util.Times; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import jakarta.servlet.ServletConfig; 28 | import jakarta.servlet.ServletException; 29 | import jakarta.servlet.ServletRequest; 30 | import jakarta.servlet.ServletResponse; 31 | import jakarta.servlet.http.HttpServlet; 32 | import java.io.IOException; 33 | import java.io.Serial; 34 | 35 | /** 36 | * {@link HttpServlet} wrapper for Felix {@link org.apache.felix.http.base.internal.dispatch.DispatcherServlet}. 37 | * 38 | * @author Rakesh.Kumar, AdeptJ 39 | */ 40 | public class DispatcherServletWrapper extends HttpServlet { 41 | 42 | @Serial 43 | private static final long serialVersionUID = 3090993776785941111L; 44 | 45 | private static final Logger LOGGER = LoggerFactory.getLogger(DispatcherServletWrapper.class); 46 | 47 | /** 48 | * The Felix {@link org.apache.felix.http.base.internal.dispatch.DispatcherServlet} 49 | */ 50 | private final HttpServlet dispatcherServlet; 51 | 52 | DispatcherServletWrapper(HttpServlet dispatcherServlet) { 53 | this.dispatcherServlet = dispatcherServlet; 54 | } 55 | 56 | @Override 57 | public void init(ServletConfig config) throws ServletException { 58 | long startTime = System.nanoTime(); 59 | super.init(config); 60 | this.dispatcherServlet.init(config); 61 | LOGGER.info("Felix DispatcherServlet initialized in [{}] ms!!", Times.elapsedMillis(startTime)); 62 | } 63 | 64 | @Override 65 | public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { 66 | this.dispatcherServlet.service(req, res); 67 | } 68 | 69 | @Override 70 | public void destroy() { 71 | this.dispatcherServlet.destroy(); 72 | LOGGER.info("Felix DispatcherServlet Destroyed!!"); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/osgi/FrameworkEvents.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.osgi; 22 | 23 | import java.util.stream.Stream; 24 | 25 | /** 26 | * OSGi Framework event code to string mapping. 27 | * 28 | * @author Rakesh.Kumar, AdeptJ 29 | */ 30 | public enum FrameworkEvents { 31 | 32 | STARTED(1), 33 | 34 | ERROR(2), 35 | 36 | PACKAGES_REFRESHED(4), 37 | 38 | STOPPED(64), 39 | 40 | STOPPED_UPDATE(128), 41 | 42 | WAIT_TIMED_OUT(512), 43 | 44 | UNKNOWN(-1); 45 | 46 | private final int code; 47 | 48 | FrameworkEvents(int code) { 49 | this.code = code; 50 | } 51 | 52 | public int getCode() { 53 | return code; 54 | } 55 | 56 | public static String asString(int code) { 57 | return Stream.of(values()) 58 | .filter(fe -> code == fe.getCode()) 59 | .findFirst() 60 | .orElse(UNKNOWN) 61 | .toString(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/osgi/FrameworkLauncher.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.osgi; 22 | 23 | import com.adeptj.runtime.core.StartupAware; 24 | 25 | import jakarta.servlet.ServletContext; 26 | 27 | /** 28 | * FrameworkLauncher is a {@link StartupAware} that launches the OSGi Framework. 29 | * 30 | * @author Rakesh.Kumar, AdeptJ 31 | */ 32 | public class FrameworkLauncher implements StartupAware { 33 | 34 | /** 35 | * This method will be called by the ServletContainerInitializer while startup is in progress. 36 | * 37 | * @param servletContext the {@link ServletContext} 38 | */ 39 | @Override 40 | public void onStartup(ServletContext servletContext) { 41 | FrameworkManager.getInstance().startFramework(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/osgi/FrameworkShutdownHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.osgi; 22 | 23 | import com.adeptj.runtime.common.ServletContextHolder; 24 | import com.adeptj.runtime.kernel.util.Times; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | import jakarta.servlet.ServletContextEvent; 29 | import jakarta.servlet.ServletContextListener; 30 | import jakarta.servlet.annotation.WebListener; 31 | 32 | /** 33 | * ContextListener that handles the OSGi Framework shutdown. 34 | * 35 | * @author Rakesh.Kumar, AdeptJ 36 | */ 37 | @WebListener("Stops the OSGi Framework when ServletContext is destroyed") 38 | public class FrameworkShutdownHandler implements ServletContextListener { 39 | 40 | @Override 41 | public void contextDestroyed(ServletContextEvent event) { 42 | long startTime = System.nanoTime(); 43 | Logger logger = LoggerFactory.getLogger(this.getClass()); 44 | logger.info("Stopping OSGi Framework as ServletContext is being destroyed!!"); 45 | ServiceTrackers.getInstance().closeEventDispatcherTracker(); 46 | // see - https://github.com/AdeptJ/adeptj-runtime/issues/4 47 | // Close the DispatcherServletTracker here rather than in BridgeServlet#destroy method. 48 | // As with version 3.0.18 of Felix Http base the way with HttpSessionListener(s) handled 49 | // is changed which results in a NPE. 50 | ServiceTrackers.getInstance().closeDispatcherServletTracker(); 51 | FrameworkManager.getInstance().stopFramework(); 52 | ServletContextHolder.getInstance().setServletContext(null); 53 | logger.info("OSGi Framework stopped in [{}] ms!!", Times.elapsedMillis(startTime)); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/osgi/LoggerConfigFactoryListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.osgi; 22 | 23 | import com.adeptj.runtime.common.LogbackManagerHolder; 24 | import com.adeptj.runtime.logging.LogbackManager; 25 | import org.osgi.framework.ServiceEvent; 26 | import org.osgi.framework.ServiceListener; 27 | import org.slf4j.Logger; 28 | import org.slf4j.LoggerFactory; 29 | 30 | import java.util.concurrent.locks.Lock; 31 | import java.util.concurrent.locks.ReentrantLock; 32 | 33 | import static org.osgi.framework.ServiceEvent.REGISTERED; 34 | import static org.osgi.framework.ServiceEvent.UNREGISTERING; 35 | 36 | /** 37 | * OSGi {@link ServiceListener} for getting logger config properties from LoggerConfigFactory services. 38 | * 39 | * @author Rakesh.Kumar, AdeptJ 40 | */ 41 | public class LoggerConfigFactoryListener implements ServiceListener { 42 | 43 | private static final Logger LOGGER = LoggerFactory.getLogger(LoggerConfigFactoryListener.class); 44 | 45 | private final Lock lock; 46 | 47 | LoggerConfigFactoryListener() { 48 | this.lock = new ReentrantLock(); 49 | } 50 | 51 | @Override 52 | public void serviceChanged(ServiceEvent event) { 53 | this.lock.lock(); 54 | LogbackManager logbackManager = LogbackManagerHolder.getInstance().getLogbackManager(); 55 | try { 56 | switch (event.getType()) { 57 | case REGISTERED -> logbackManager.addOSGiLoggers(event.getServiceReference()); 58 | case UNREGISTERING -> logbackManager.resetLoggers(event.getServiceReference()); 59 | default -> LOGGER.warn("Ignored ServiceEvent: [{}]", event.getType()); 60 | } 61 | } finally { 62 | this.lock.unlock(); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /main/src/main/java/com/adeptj/runtime/servlet/ErrorServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | 21 | package com.adeptj.runtime.servlet; 22 | 23 | import com.adeptj.runtime.html.TemplateEngine; 24 | import com.adeptj.runtime.html.TemplateEngineContext; 25 | import com.adeptj.runtime.kernel.util.Environment; 26 | import com.adeptj.runtime.kernel.util.RequestUtil; 27 | import jakarta.servlet.annotation.WebServlet; 28 | import jakarta.servlet.http.HttpServlet; 29 | import jakarta.servlet.http.HttpServletRequest; 30 | import jakarta.servlet.http.HttpServletResponse; 31 | 32 | import java.io.Serial; 33 | 34 | import static com.adeptj.runtime.common.Constants.ERROR_SERVLET_URI; 35 | import static com.adeptj.runtime.common.Constants.VAR_ERROR_CODE; 36 | import static jakarta.servlet.DispatcherType.ERROR; 37 | 38 | /** 39 | * ErrorServlet that serves the error page w.r.t error coded(401, 403, 404, 500). 40 | *

41 | * This servlet is invoked by the container using the servlet error page mechanism therefore should not be called directly. 42 | * 43 | * @author Rakesh.Kumar, AdeptJ 44 | */ 45 | @WebServlet(name = "AdeptJ ErrorServlet", urlPatterns = ERROR_SERVLET_URI) 46 | public class ErrorServlet extends HttpServlet { 47 | 48 | @Serial 49 | private static final long serialVersionUID = 3178276466531152040L; 50 | 51 | private static final String KEY_EXCEPTION = "exception"; 52 | 53 | private static final String ERROR_TEMPLATE = "error"; 54 | 55 | @Override 56 | protected void service(HttpServletRequest req, HttpServletResponse resp) { 57 | // Make sure the below code is invoked only on an error dispatch. 58 | if (req.getDispatcherType() == ERROR) { 59 | TemplateEngineContext.Builder builder = TemplateEngineContext.builder(ERROR_TEMPLATE, req, resp) 60 | .addTemplateVariable(VAR_ERROR_CODE, resp.getStatus()); 61 | if (Environment.isDev() && RequestUtil.hasException(req)) { 62 | builder.addTemplateVariable(KEY_EXCEPTION, RequestUtil.getException(req)); 63 | } 64 | TemplateEngine.getInstance().render(builder.build()); 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /main/src/main/resources/META-INF/services/ch.qos.logback.classic.spi.Configurator: -------------------------------------------------------------------------------- 1 | com.adeptj.runtime.logging.LogbackInitializer -------------------------------------------------------------------------------- /main/src/main/resources/banner.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | ___ __ __ __ ___ __ _ 4 | / _ |___/ /__ ___ / /___ / / / _ \__ _____ / /_(_)_ _ ___ 5 | / __ / _ / -_) _ \/ __/ // / / _/ // / _ \/ __/ / \/ -_) 6 | /_/ |_\___/\__/ ___/\__/\___/ /_/|_|\___/_//_/\__/_/_/_/_/\__/ (v${project.version}, codename - ${codename}) 7 | /_/ 8 | 9 | 10 | ############################################################################### 11 | # # 12 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 13 | # # 14 | # Licensed under the Apache License, Version 2.0 (the "License"); # 15 | # you may not use this file except in compliance with the License. # 16 | # You may obtain a copy of the License at # 17 | # # 18 | # http://www.apache.org/licenses/LICENSE-2.0 # 19 | # # 20 | # Unless required by applicable law or agreed to in writing, software # 21 | # distributed under the License is distributed on an "AS IS" BASIS, # 22 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 23 | # See the License for the specific language governing permissions and # 24 | # limitations under the License. # 25 | # # 26 | ############################################################################### 27 | 28 | -------------------------------------------------------------------------------- /main/src/main/resources/i18n/main.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptJ/adeptj-runtime/5cdf191155a497ed110207cafc1c3279e1339cc0/main/src/main/resources/i18n/main.properties -------------------------------------------------------------------------------- /main/src/main/resources/server.p12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptJ/adeptj-runtime/5cdf191155a497ed110207cafc1c3279e1339cc0/main/src/main/resources/server.p12 -------------------------------------------------------------------------------- /main/src/main/webapp/i18n/messages.properties: -------------------------------------------------------------------------------- 1 | login.page.title.msg=AdeptJ Runtime 2 | login.welcome.msg=Welcome! 3 | logo.img.alt.msg=AdeptJ Logo 4 | login.error.msg=Invalid credentials! 5 | go.home.msg=Go Home 6 | 401.page.title.msg=401 Unauthorized 7 | 401.page.error.code.msg=401 8 | 401.page.error.details.msg=Unauthorized access to the resource is not permitted! 9 | 403.page.title.msg=403 Forbidden 10 | 403.page.error.code.msg=403 11 | 403.page.error.details.msg=Forbidden 12 | 404.page.title.msg=404 Not Found 13 | 404.page.error.code.msg=404 14 | 404.page.error.details.msg=Resource Not Found 15 | 500.page.title.msg=500 Internal Server Error 16 | 500.page.error.code.msg=500 17 | 500.page.error.details.msg=Internal Server Error 18 | 500.page.error.extra.details.msg=The server encountered an internal error and was unable to complete your request. Please try again later! 19 | 503.page.title.msg=503 Unavailable 20 | 503.page.error.code.msg=503 21 | 503.page.error.details.msg=Service Unavailable -------------------------------------------------------------------------------- /main/src/main/webapp/static/css/error-page.css: -------------------------------------------------------------------------------- 1 | .page-error-message { 2 | width: 57%; 3 | margin-top: 8%; 4 | } 5 | 6 | .message-detail { 7 | font-size: 15px; 8 | color: #555; 9 | font-weight: bold; 10 | } 11 | 12 | .page-error-message .error-code { 13 | font-size: 5rem; 14 | font-weight: bolder; 15 | } 16 | 17 | .message-exception-trace { 18 | font-size: 11px; 19 | font-weight: 300; 20 | padding: 10px; 21 | word-wrap: break-word; 22 | line-height: 2; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /main/src/main/webapp/static/css/main.css: -------------------------------------------------------------------------------- 1 | h1, h2, h3, h4, h5, h6, p { 2 | color: #555; 3 | } 4 | 5 | .login-form { 6 | margin-top: 3em; 7 | width: 100%; 8 | } 9 | 10 | body { 11 | background: #f2f2f2; 12 | } 13 | 14 | .form-group { 15 | margin-bottom: 2rem; 16 | } 17 | 18 | .wrapper-middle { 19 | width: 390px; 20 | background: #fff; 21 | border-radius: 10px; 22 | overflow: hidden; 23 | margin: 3% auto auto; 24 | padding: 77px 55px 33px; 25 | box-shadow: 0 5px 10px 0 rgba(0,0,0,.1); 26 | -moz-box-shadow: 0 5px 10px 0 rgba(0,0,0,.1); 27 | -webkit-box-shadow: 0 5px 10px 0 rgba(0,0,0,.1); 28 | -o-box-shadow: 0 5px 10px 0 rgba(0,0,0,.1); 29 | -ms-box-shadow: 0 5px 10px 0 rgba(0,0,0,.1); 30 | } 31 | 32 | .main-logo img { 33 | width: auto; 34 | height: 100%; 35 | margin: auto; 36 | display: block; 37 | } 38 | 39 | .main-logo img { 40 | width: auto; 41 | height: 150px; 42 | } 43 | 44 | .form-control { 45 | font-size: 15px; 46 | color: #555; 47 | line-height: 1.2; 48 | display: block; 49 | width: 100%; 50 | height: 45px; 51 | padding: 0 5px; 52 | outline: none; 53 | border: none; 54 | border-bottom: 1px solid #24245F; 55 | border-radius: 0px; 56 | } 57 | 58 | .form-control:focus { 59 | border-bottom: 1px solid #FF8300; 60 | box-shadow: none 61 | } 62 | 63 | 64 | .btn-adeptj-primary { 65 | background: #FF9A00; 66 | color: #fff; 67 | width: 100%; 68 | border: 1px solid #FF8300; 69 | padding: 10px 30px; 70 | transition: 0.3s; 71 | } 72 | 73 | span.error { 74 | color: #FF5900; 75 | } 76 | 77 | .btn-adeptj-primary.focus, .btn-adeptj-primary:focus { 78 | box-shadow: none 79 | } 80 | 81 | .btn-adeptj-primary:hover, .btn-adeptj-primary:focus { 82 | color: #fff; 83 | background: #F28600; 84 | border-color: #F28600; 85 | } -------------------------------------------------------------------------------- /main/src/main/webapp/static/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptJ/adeptj-runtime/5cdf191155a497ed110207cafc1c3279e1339cc0/main/src/main/webapp/static/img/favicon.ico -------------------------------------------------------------------------------- /main/src/main/webapp/static/img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptJ/adeptj-runtime/5cdf191155a497ed110207cafc1c3279e1339cc0/main/src/main/webapp/static/img/logo.png -------------------------------------------------------------------------------- /main/src/main/webapp/templates/change-pwd.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{ i18n("messages", "login.page.title.msg") }} 8 | 9 | 10 | 11 | 12 | 13 |

14 |
15 |
16 | 56 |
57 |
58 |
59 | 60 | 61 | -------------------------------------------------------------------------------- /main/src/main/webapp/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {# Note: errorCode variable is set from ErrorServlet #} 8 | {{ i18n("messages", "page.title.msg") }} 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 |
18 |
19 |
20 |

{{ i18n("messages", "page.error.code.msg") }}

21 |

{{ i18n("messages", "page.error.details.msg") }}

22 | {% if errorCode == 500 %} 23 |

{{ i18n("messages", "page.error.extra.details.msg") }}

24 |

{{exception}}

25 | {% endif %} 26 | {% if errorCode == 401 or errorCode == 403 or errorCode == 404 or errorCode == 503 %} 27 | {{ i18n("messages", "go.home.msg") }} 28 | {% endif %} 29 |
30 |
31 |
32 |
33 |
34 | 35 | -------------------------------------------------------------------------------- /main/src/main/webapp/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | {{ i18n("messages", "login.page.title.msg") }} 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 | 56 |
57 |
58 |
59 | 60 | 61 | -------------------------------------------------------------------------------- /main/src/test/java/com/adeptj/runtime/common/BundleContextHolderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.common; 21 | 22 | import org.junit.jupiter.api.Assertions; 23 | import org.junit.jupiter.api.Disabled; 24 | import org.junit.jupiter.api.Test; 25 | 26 | /** 27 | * BundleContextHolderTest. 28 | * 29 | * @author Rakesh.Kumar, AdeptJ. 30 | */ 31 | @Disabled 32 | class BundleContextHolderTest { 33 | 34 | @Test 35 | void testIsBundleContextSetWhenSetBundleContextCalled() { 36 | Assertions.assertNotNull(BundleContextHolder.getInstance().getBundleContext()); 37 | } 38 | 39 | @Test 40 | void testIsBundleContextSetWhenSetBundleContextNotCalled() { 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 23 | 4.0.0 24 | com.adeptj 25 | adeptj-runtime-reactor 26 | 1.0.0 27 | pom 28 | AdeptJ Runtime :: Reactor 29 | AdeptJ Runtime :: Reactor 30 | https://www.adeptj.com 31 | 2016 32 | 33 | 34 | 35 | kernel 36 | server-adapters 37 | main 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /server-adapters/jetty/README.md: -------------------------------------------------------------------------------- 1 | # adeptj-runtime-jetty 2 | Jetty Adapter for AdeptJ Runtime 3 | -------------------------------------------------------------------------------- /server-adapters/jetty/src/main/java/com/adeptj/runtime/jetty/MVStoreLoginService.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.jetty; 21 | 22 | import com.adeptj.runtime.kernel.UserManager; 23 | import org.eclipse.jetty.security.AbstractLoginService; 24 | import org.eclipse.jetty.security.RolePrincipal; 25 | import org.eclipse.jetty.security.UserPrincipal; 26 | import org.eclipse.jetty.util.StringUtil; 27 | 28 | import java.util.List; 29 | import java.util.UUID; 30 | import java.util.stream.Collectors; 31 | 32 | /** 33 | * Jetty login service for authenticating admin user(s). 34 | * 35 | * @author Rakesh Kumar, AdeptJ 36 | */ 37 | public class MVStoreLoginService extends AbstractLoginService { 38 | 39 | private final UserManager userManager; 40 | 41 | public MVStoreLoginService(UserManager userManager) { 42 | this.userManager = userManager; 43 | } 44 | 45 | @Override 46 | protected List loadRoleInfo(UserPrincipal user) { 47 | return this.userManager.getRoles(user.getName()) 48 | .stream() 49 | .map(RolePrincipal::new) 50 | .collect(Collectors.toList()); 51 | } 52 | 53 | @Override 54 | protected UserPrincipal loadUserInfo(String username) { 55 | String password = this.userManager.getPassword(username); 56 | if (StringUtil.isEmpty(password)) { 57 | // This is just called to waste a bit of time as not to reveal that the user does not exist. 58 | this.userManager.encodePassword(UUID.randomUUID().toString()); 59 | return null; 60 | } 61 | return new UserPrincipal(username, new Sha256Base64EncodedPassword(password)); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /server-adapters/jetty/src/main/java/com/adeptj/runtime/jetty/SecurityConfigurer.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.jetty; 21 | 22 | import com.adeptj.runtime.kernel.UserManager; 23 | import com.typesafe.config.Config; 24 | import org.eclipse.jetty.ee10.servlet.security.ConstraintMapping; 25 | import org.eclipse.jetty.ee10.servlet.security.ConstraintSecurityHandler; 26 | import org.eclipse.jetty.security.Constraint; 27 | import org.eclipse.jetty.security.authentication.FormAuthenticator; 28 | 29 | import java.util.HashSet; 30 | import java.util.Set; 31 | 32 | import static org.eclipse.jetty.security.Constraint.Authorization.SPECIFIC_ROLE; 33 | import static org.eclipse.jetty.security.Constraint.Transport.INHERIT; 34 | 35 | /** 36 | * Jetty security configurer. 37 | * 38 | * @author Rakesh Kumar, AdeptJ 39 | */ 40 | public class SecurityConfigurer { 41 | 42 | public void configure(ConstraintSecurityHandler securityHandler, UserManager userManager, Config commonCfg) { 43 | // Security settings 44 | securityHandler.setLoginService(new MVStoreLoginService(userManager)); 45 | securityHandler.setAuthenticator(this.getFormAuthenticator(commonCfg)); 46 | this.addConstraintMapping(securityHandler, commonCfg); 47 | } 48 | 49 | private FormAuthenticator getFormAuthenticator(Config commonCfg) { 50 | Config formAuthCfg = commonCfg.getConfig("form-auth"); 51 | String loginUrl = formAuthCfg.getString("login-url"); 52 | String errorUlr = formAuthCfg.getString("error-url"); 53 | return new FormAuthenticator(loginUrl, errorUlr, true); 54 | } 55 | 56 | private void addConstraintMapping(ConstraintSecurityHandler securityHandler, Config commonCfg) { 57 | Set roles = new HashSet<>(commonCfg.getStringList("auth-roles")); 58 | Constraint constraint = Constraint.from("AdeptJ Security Constraint", INHERIT, SPECIFIC_ROLE, roles); 59 | for (String protectedPath : commonCfg.getStringList("protected-paths")) { 60 | ConstraintMapping constraintMapping = new ConstraintMapping(); 61 | constraintMapping.setConstraint(constraint); 62 | constraintMapping.setPathSpec(protectedPath); 63 | securityHandler.addConstraintMapping(constraintMapping); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /server-adapters/jetty/src/main/java/com/adeptj/runtime/jetty/Sha256Base64EncodedPassword.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.jetty; 21 | 22 | import com.adeptj.runtime.kernel.util.PasswordEncoder; 23 | import org.eclipse.jetty.util.security.Password; 24 | 25 | import java.io.Serial; 26 | 27 | import static java.nio.charset.StandardCharsets.UTF_8; 28 | 29 | /** 30 | * Jetty {@link Password} extension for SHA 256/Base 64 encoded password matching. 31 | * 32 | * @author Rakesh Kumar, AdeptJ 33 | */ 34 | public class Sha256Base64EncodedPassword extends Password { 35 | 36 | @Serial 37 | private static final long serialVersionUID = 4019843572977985299L; 38 | 39 | public Sha256Base64EncodedPassword(String password) { 40 | super(password); 41 | } 42 | 43 | @Override 44 | public boolean check(Object credentials) { 45 | byte[] encodedPassword = PasswordEncoder.encodePassword((String) credentials); 46 | return super.check(new String(encodedPassword, UTF_8)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /server-adapters/jetty/src/main/java/com/adeptj/runtime/jetty/handler/ContextPathHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.jetty.handler; 21 | 22 | import com.adeptj.runtime.kernel.ConfigProvider; 23 | import com.adeptj.runtime.kernel.util.RequestUtil; 24 | import org.eclipse.jetty.server.Handler; 25 | import org.eclipse.jetty.server.Request; 26 | import org.eclipse.jetty.server.Response; 27 | import org.eclipse.jetty.util.Callback; 28 | 29 | /** 30 | * Jetty handler for context path handling. 31 | * 32 | * @author Rakesh Kumar, AdeptJ 33 | */ 34 | public class ContextPathHandler extends Handler.Abstract.NonBlocking { 35 | 36 | @Override 37 | public boolean handle(Request request, Response response, Callback callback) { 38 | if (RequestUtil.isContextRootRequest(request.getHttpURI().getPath())) { 39 | String systemConsolePath = ConfigProvider.getInstance() 40 | .getMainConfig() 41 | .getString("common.system-console-path"); 42 | Response.sendRedirect(request, response, callback, systemConsolePath); 43 | callback.succeeded(); 44 | return true; 45 | } 46 | return false; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /server-adapters/jetty/src/main/java/com/adeptj/runtime/jetty/handler/HealthCheckHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.jetty.handler; 21 | 22 | import org.eclipse.jetty.server.Handler; 23 | import org.eclipse.jetty.server.Request; 24 | import org.eclipse.jetty.server.Response; 25 | import org.eclipse.jetty.util.Callback; 26 | 27 | import static org.eclipse.jetty.http.HttpStatus.OK_200; 28 | 29 | /** 30 | * Jetty handler for health checks. 31 | * 32 | * @author Rakesh Kumar, AdeptJ 33 | */ 34 | public class HealthCheckHandler extends Handler.Abstract.NonBlocking { 35 | 36 | private static final String HC_URI = "/hc"; 37 | 38 | @Override 39 | public boolean handle(Request request, Response response, Callback callback) { 40 | if (request.getHttpURI().getPath().equals(HC_URI)) { 41 | response.setStatus(OK_200); 42 | callback.succeeded(); 43 | return true; 44 | } 45 | return false; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /server-adapters/jetty/src/main/java/com/adeptj/runtime/jetty/osgi/JettyPackageExportsProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.jetty.osgi; 21 | 22 | import com.adeptj.runtime.kernel.ConfigProvider; 23 | import com.adeptj.runtime.kernel.osgi.PackageExportsProvider; 24 | import org.eclipse.jetty.server.Server; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import java.util.List; 28 | 29 | /** 30 | * Export Jetty packages with the currently used Jetty version. 31 | * 32 | * @author Rakesh Kumar, AdeptJ 33 | */ 34 | public class JettyPackageExportsProvider implements PackageExportsProvider { 35 | 36 | @Override 37 | public String getName() { 38 | return "Jetty PackageExportsProvider"; 39 | } 40 | 41 | /** 42 | * Prepares the package list from the packages declared in Jetty's config along with Jetty's version. 43 | * 44 | * @return packages with Jetty's version. 45 | */ 46 | @Override 47 | public String getPackageExports() { 48 | StringBuilder packageExportsBuilder = new StringBuilder(); 49 | try { 50 | List packageExports = ConfigProvider.getInstance() 51 | .getApplicationConfig() 52 | .getStringList("jetty.osgi.package-exports"); 53 | for (String packageExport : packageExports) { 54 | packageExportsBuilder.append(packageExport); 55 | } 56 | packageExportsBuilder.append("version=") 57 | .append("\"") 58 | .append(Server.getVersion()) 59 | .append("\""); 60 | } catch (Exception ex) { 61 | LoggerFactory.getLogger(this.getClass()).error(ex.getMessage(), ex); 62 | } 63 | return packageExportsBuilder.toString(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /server-adapters/jetty/src/main/resources/META-INF/services/com.adeptj.runtime.kernel.Server: -------------------------------------------------------------------------------- 1 | com.adeptj.runtime.jetty.JettyServer -------------------------------------------------------------------------------- /server-adapters/jetty/src/main/resources/META-INF/services/com.adeptj.runtime.kernel.osgi.PackageExportsProvider: -------------------------------------------------------------------------------- 1 | com.adeptj.runtime.jetty.osgi.JettyPackageExportsProvider -------------------------------------------------------------------------------- /server-adapters/jetty/src/main/resources/i18n/jetty.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptJ/adeptj-runtime/5cdf191155a497ed110207cafc1c3279e1339cc0/server-adapters/jetty/src/main/resources/i18n/jetty.properties -------------------------------------------------------------------------------- /server-adapters/jetty/src/main/resources/reference.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # # 3 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 4 | # # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); # 6 | # you may not use this file except in compliance with the License. # 7 | # You may obtain a copy of the License at # 8 | # # 9 | # http://www.apache.org/licenses/LICENSE-2.0 # 10 | # # 11 | # Unless required by applicable law or agreed to in writing, software # 12 | # distributed under the License is distributed on an "AS IS" BASIS, # 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 14 | # See the License for the specific language governing permissions and # 15 | # limitations under the License. # 16 | # # 17 | ############################################################################### 18 | 19 | jetty: { 20 | qtp: { 21 | min-threads: 10 22 | max-threads: 100 23 | idle-timeout: 120 24 | } 25 | 26 | http: { 27 | port: 8080 28 | output-buffer-size: 32768 29 | request-header-size: 8192 30 | response-header-size: 8192 31 | send-server-version: false 32 | send-date-header: true 33 | relative-redirect-allowed: true 34 | } 35 | 36 | connector: { 37 | # IdleTimeout in milliseconds 38 | idle-timeout: 30000 39 | } 40 | 41 | context: { 42 | path: / 43 | req-char-encoding: UTF-8 44 | res-char-encoding: UTF-8 45 | init-params: [] 46 | resource-servlet-path: "/static/*" 47 | static-resources-base-path: /webapp/static 48 | } 49 | 50 | osgi: { 51 | package-exports: [ 52 | org.eclipse.jetty.util;, 53 | org.eclipse.jetty.util.annotation;, 54 | org.eclipse.jetty.util.component;, 55 | org.eclipse.jetty.util.compression;, 56 | org.eclipse.jetty.util.preventers;, 57 | org.eclipse.jetty.util.resource;, 58 | org.eclipse.jetty.util.security;, 59 | org.eclipse.jetty.util.ssl;, 60 | org.eclipse.jetty.util.statistic;, 61 | org.eclipse.jetty.util.thread;, 62 | org.eclipse.jetty.util.thread.strategy;, 63 | org.eclipse.jetty.io;, 64 | org.eclipse.jetty.io.jmx;, 65 | org.eclipse.jetty.io.ssl;, 66 | org.eclipse.jetty.io.content;, 67 | org.eclipse.jetty.http;, 68 | org.eclipse.jetty.http.compression;, 69 | org.eclipse.jetty.http.content;, 70 | org.eclipse.jetty.http.pathmap; 71 | ] 72 | } 73 | } -------------------------------------------------------------------------------- /server-adapters/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 21 | 23 | 4.0.0 24 | com.adeptj 25 | adeptj-runtime-server-adapters-reactor 26 | 1.0.0 27 | pom 28 | AdeptJ Runtime :: Server Adapters :: Reactor 29 | Maven reactor project for AdeptJ Runtime server adapters. 30 | https://www.adeptj.com 31 | 2016 32 | 33 | 34 | 35 | jetty 36 | tomcat 37 | undertow 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /server-adapters/tomcat/README.md: -------------------------------------------------------------------------------- 1 | # adeptj-runtime-tomcat 2 | Tomcat adapter for AdeptJ Runtime 3 | -------------------------------------------------------------------------------- /server-adapters/tomcat/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.adeptj 8 | adeptj-parent 9 | 45 10 | 11 | 12 | adeptj-runtime-tomcat 13 | 1.0.0 14 | jar 15 | AdeptJ Runtime :: Server Adapters :: Tomcat 16 | High performance, dynamic, modular runtime for RESTful APIs, MicroServices and WebApps. 17 | https://www.adeptj.com 18 | 2016 19 | 20 | 21 | UTF-8 22 | 11.0.8 23 | 1.0.0 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | org.apache.maven.plugins 32 | maven-compiler-plugin 33 | 34 | 35 | 36 | org.apache.maven.plugins 37 | maven-surefire-plugin 38 | 39 | ${skipTests} 40 | 41 | 42 | 43 | 44 | org.apache.maven.plugins 45 | maven-enforcer-plugin 46 | 47 | 48 | 49 | org.codehaus.mojo 50 | versions-maven-plugin 51 | 52 | false 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | com.typesafe 64 | config 65 | compile 66 | 67 | 68 | 69 | org.slf4j 70 | slf4j-api 71 | compile 72 | 73 | 74 | 75 | com.adeptj 76 | adeptj-runtime-kernel 77 | ${adeptj-runtime-kernel.version} 78 | 79 | 80 | 81 | org.apache.tomcat 82 | tomcat-annotations-api 83 | ${tomcat.version} 84 | 85 | 86 | 87 | org.apache.tomcat.embed 88 | tomcat-embed-core 89 | ${tomcat.version} 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /server-adapters/tomcat/src/main/java/com/adeptj/runtime/tomcat/ConnectorConfigurer.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.tomcat; 21 | 22 | import com.typesafe.config.Config; 23 | import org.apache.catalina.connector.Connector; 24 | import org.apache.catalina.startup.Tomcat; 25 | import org.apache.coyote.http11.AbstractHttp11Protocol; 26 | import org.apache.coyote.http2.Http2Protocol; 27 | 28 | import static com.adeptj.runtime.tomcat.ServerConstants.CFG_KEY_CONNECTOR_PROTOCOL; 29 | import static com.adeptj.runtime.tomcat.ServerConstants.CFG_KEY_CONNECTOR_SERVER; 30 | 31 | /** 32 | * Tomcat Catalina {@link Connector} configuration. 33 | * 34 | * @author Rakesh Kumar, AdeptJ 35 | */ 36 | public class ConnectorConfigurer { 37 | 38 | public void configure(int port, Tomcat tomcat, Config serverConfig) { 39 | Connector connector = new Connector(serverConfig.getString(CFG_KEY_CONNECTOR_PROTOCOL)); 40 | connector.setPort(port); 41 | AbstractHttp11Protocol protocol = (AbstractHttp11Protocol) connector.getProtocolHandler(); 42 | protocol.setServer(serverConfig.getString(CFG_KEY_CONNECTOR_SERVER)); 43 | protocol.addUpgradeProtocol(new Http2Protocol()); // This will enable h2c 44 | tomcat.setConnector(connector); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /server-adapters/tomcat/src/main/java/com/adeptj/runtime/tomcat/MVStoreCredentialHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.tomcat; 21 | 22 | import com.adeptj.runtime.kernel.UserManager; 23 | import org.apache.catalina.CredentialHandler; 24 | 25 | /** 26 | * Tomcat Catalina {@link CredentialHandler} implementation for authenticating AdeptJ Runtime admin(s). 27 | * 28 | * @author Rakesh Kumar, AdeptJ 29 | */ 30 | public class MVStoreCredentialHandler implements CredentialHandler { 31 | 32 | private final UserManager userManager; 33 | 34 | public MVStoreCredentialHandler(UserManager userManager) { 35 | this.userManager = userManager; 36 | } 37 | 38 | @Override 39 | public boolean matches(String inputCredentials, String storedCredentials) { 40 | return this.userManager.matchPassword(inputCredentials, storedCredentials); 41 | } 42 | 43 | /** 44 | * This is just called to waste a bit of time as not to reveal that the user does not exist. 45 | * 46 | * @param inputCredentials User provided credentials 47 | * @return encoded version of passed credentials. 48 | */ 49 | @Override 50 | public String mutate(String inputCredentials) { 51 | return this.userManager.encodePassword(inputCredentials); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /server-adapters/tomcat/src/main/java/com/adeptj/runtime/tomcat/MVStoreRealm.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.tomcat; 21 | 22 | import com.adeptj.runtime.kernel.UserManager; 23 | import org.apache.catalina.realm.GenericPrincipal; 24 | import org.apache.catalina.realm.RealmBase; 25 | 26 | import java.security.Principal; 27 | 28 | /** 29 | * Tomcat Catalina Realm implementation. 30 | * 31 | * @author Rakesh Kumar, AdeptJ 32 | */ 33 | public class MVStoreRealm extends RealmBase { 34 | 35 | private final UserManager userManager; 36 | 37 | public MVStoreRealm(UserManager userManager) { 38 | this.userManager = userManager; 39 | } 40 | 41 | @Override 42 | protected String getPassword(String username) { 43 | return this.userManager.getPassword(username); 44 | } 45 | 46 | @Override 47 | protected Principal getPrincipal(String username) { 48 | return new GenericPrincipal(username, this.userManager.getRoles(username)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /server-adapters/tomcat/src/main/java/com/adeptj/runtime/tomcat/ServerConstants.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.tomcat; 21 | 22 | /** 23 | * General constants for Tomcat server adapter. 24 | * 25 | * @author Rakesh Kumar, AdeptJ 26 | */ 27 | public class ServerConstants { 28 | 29 | public static final String SYMBOL_DASH = "-"; 30 | 31 | public static final String CFG_KEY_BASE_DIR = "base-dir"; 32 | 33 | public static final String CFG_KEY_CONNECTOR_PROTOCOL = "connector.protocol"; 34 | 35 | public static final String CFG_KEY_CONNECTOR_SERVER = "connector.server"; 36 | 37 | public static final String CFG_KEY_CTX_PATH = "context-path"; 38 | 39 | public static final String CFG_KEY_DOC_BASE = "doc-base"; 40 | 41 | public static final String CFG_KEY_MAIN_COMMON = "main.common"; 42 | 43 | public static final String CFG_KEY_LIB_PATH = "lib-path"; 44 | 45 | public static final String CFG_KEY_WEBAPP_JAR_NAME = "webapp-jar-name"; 46 | 47 | public static final String CFG_KEY_JAR_RES_INTERNAL_PATH = "jar-resource-internal-path"; 48 | 49 | public static final String CFG_KEY_JAR_RES_WEBAPP_MT = "jar-resource-webapp-mount"; 50 | 51 | public static final String CFG_KEY_ASYNC = "async"; 52 | 53 | private ServerConstants() { 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /server-adapters/tomcat/src/main/java/com/adeptj/runtime/tomcat/filter/ContextPathFilter.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.tomcat.filter; 21 | 22 | import com.adeptj.runtime.kernel.util.RequestUtil; 23 | import com.adeptj.runtime.kernel.util.ResponseUtil; 24 | import jakarta.servlet.Filter; 25 | import jakarta.servlet.FilterChain; 26 | import jakarta.servlet.ServletException; 27 | import jakarta.servlet.ServletRequest; 28 | import jakarta.servlet.ServletResponse; 29 | import jakarta.servlet.http.HttpServletRequest; 30 | import jakarta.servlet.http.HttpServletResponse; 31 | 32 | import java.io.IOException; 33 | 34 | /** 35 | * Tomcat servlet filter for context path handling. 36 | * 37 | * @author Rakesh Kumar, AdeptJ 38 | */ 39 | public class ContextPathFilter implements Filter { 40 | 41 | @Override 42 | public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { 43 | if (request instanceof HttpServletRequest req 44 | && response instanceof HttpServletResponse resp && RequestUtil.isContextRootRequest(req)) { 45 | ResponseUtil.redirectToSystemConsole(resp); 46 | return; 47 | } 48 | chain.doFilter(request, response); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /server-adapters/tomcat/src/main/java/com/adeptj/runtime/tomcat/servlet/HealthCheckServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.tomcat.servlet; 21 | 22 | import jakarta.servlet.http.HttpServlet; 23 | import jakarta.servlet.http.HttpServletRequest; 24 | import jakarta.servlet.http.HttpServletResponse; 25 | 26 | import java.io.Serial; 27 | 28 | /** 29 | * Tomcat servlet for health checks. 30 | * 31 | * @author Rakesh Kumar, AdeptJ 32 | */ 33 | public class HealthCheckServlet extends HttpServlet { 34 | 35 | @Serial 36 | private static final long serialVersionUID = -302226466401000851L; 37 | 38 | @Override 39 | protected void doHead(HttpServletRequest req, HttpServletResponse resp) { 40 | resp.setStatus(HttpServletResponse.SC_OK); 41 | } 42 | 43 | @Override 44 | protected void doGet(HttpServletRequest req, HttpServletResponse resp) { 45 | this.doHead(req, resp); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /server-adapters/tomcat/src/main/resources/META-INF/services/com.adeptj.runtime.kernel.Server: -------------------------------------------------------------------------------- 1 | com.adeptj.runtime.tomcat.TomcatServer -------------------------------------------------------------------------------- /server-adapters/tomcat/src/main/resources/i18n/tomcat.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptJ/adeptj-runtime/5cdf191155a497ed110207cafc1c3279e1339cc0/server-adapters/tomcat/src/main/resources/i18n/tomcat.properties -------------------------------------------------------------------------------- /server-adapters/tomcat/src/main/resources/reference.conf: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # # 3 | # Copyright 2016, AdeptJ (http://www.adeptj.com) # 4 | # # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); # 6 | # you may not use this file except in compliance with the License. # 7 | # You may obtain a copy of the License at # 8 | # # 9 | # http://www.apache.org/licenses/LICENSE-2.0 # 10 | # # 11 | # Unless required by applicable law or agreed to in writing, software # 12 | # distributed under the License is distributed on an "AS IS" BASIS, # 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 14 | # See the License for the specific language governing permissions and # 15 | # limitations under the License. # 16 | # # 17 | ############################################################################### 18 | 19 | tomcat: { 20 | context-path: "" 21 | base-dir: adeptj-runtime 22 | doc-base: "." 23 | jar-resource-internal-path: /webapp 24 | jar-resource-webapp-mount: / 25 | lib-path: /lib 26 | webapp-jar-name: adeptj-runtime 27 | 28 | filters: [ 29 | { 30 | name: ContextPathFilter 31 | class: com.adeptj.runtime.tomcat.filter.ContextPathFilter 32 | async: "true" 33 | desc: Filter for handling context path(/) requests 34 | pattern: "/*" 35 | init-params: { 36 | } 37 | } 38 | ] 39 | 40 | servlets: [ 41 | { 42 | name: default 43 | class: org.apache.catalina.servlets.DefaultServlet 44 | load-on-startup: 1 45 | pattern: "/static/*" 46 | init-params: { 47 | debug: "0" 48 | listings: "false" 49 | fileEncoding: UTF-8 50 | } 51 | } 52 | { 53 | name: HealthCheckServlet 54 | class: com.adeptj.runtime.tomcat.servlet.HealthCheckServlet 55 | async: true 56 | desc: Servlet for handling health check(/hc) requests 57 | pattern: "/hc" 58 | init-params: { 59 | } 60 | } 61 | ] 62 | 63 | http: { 64 | port: 8080 65 | } 66 | 67 | connector: { 68 | protocol: org.apache.coyote.http11.Http11Nio2Protocol 69 | server: AdeptJ Runtime 70 | } 71 | } -------------------------------------------------------------------------------- /server-adapters/undertow/README.md: -------------------------------------------------------------------------------- 1 | # adeptj-runtime-undertow 2 | Undertow Adapter for AdeptJ Runtime 3 | -------------------------------------------------------------------------------- /server-adapters/undertow/src/main/java/com/adeptj/runtime/undertow/core/BaseOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.undertow.core; 21 | 22 | import com.typesafe.config.Config; 23 | import io.undertow.Undertow; 24 | import io.undertow.UndertowOptions; 25 | import org.apache.commons.lang3.reflect.FieldUtils; 26 | import org.slf4j.Logger; 27 | import org.slf4j.LoggerFactory; 28 | import org.xnio.Option; 29 | import org.xnio.Options; 30 | 31 | import java.lang.reflect.Field; 32 | 33 | /** 34 | * Base class for setting Undertow Server and Socket Options. 35 | * 36 | * @author Rakesh.Kumar, AdeptJ 37 | */ 38 | public abstract class BaseOptions { 39 | 40 | final Logger logger = LoggerFactory.getLogger(this.getClass()); 41 | 42 | abstract void setOptions(Undertow.Builder builder, Config undertowConfig); 43 | 44 | /** 45 | * Search the given {@link Option} first in UndertowOptions class and if not found then Options class. 46 | * 47 | * @param name the option name 48 | * @param the option type 49 | * @return Option of correct resolved type as per the field type. 50 | */ 51 | @SuppressWarnings("unchecked") 52 | Option getOption(String name) { 53 | Option option = null; 54 | try { 55 | Field field = FieldUtils.getDeclaredField(UndertowOptions.class, name); 56 | if (field == null) { 57 | field = FieldUtils.getDeclaredField(Options.class, name); 58 | } 59 | if (field == null) { 60 | this.logger.error("[{}] field is not found either in class UndertowOptions or Options", name); 61 | } 62 | option = (field == null ? null : (Option) field.get(null)); 63 | } catch (IllegalArgumentException | IllegalAccessException ex) { 64 | this.logger.error("Exception while accessing field: [{}]", name, ex); 65 | } 66 | return option; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /server-adapters/undertow/src/main/java/com/adeptj/runtime/undertow/core/ServerOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.undertow.core; 21 | 22 | import com.adeptj.runtime.kernel.util.Times; 23 | import com.typesafe.config.Config; 24 | import io.undertow.Undertow; 25 | 26 | /** 27 | * UNDERTOW Server Options. 28 | * 29 | * @author Rakesh.Kumar, AdeptJ 30 | */ 31 | public final class ServerOptions extends BaseOptions { 32 | 33 | private static final String SERVER_OPTIONS = "server-options"; 34 | 35 | private static final String OPTIONS_TYPE_OTHERS = "options-type-others"; 36 | 37 | private static final String OPTIONS_TYPE_LONG = "options-type-long"; 38 | 39 | /** 40 | * Configures the server options dynamically. 41 | * 42 | * @param builder Undertow.Builder 43 | * @param undertowConfig Undertow Typesafe Config 44 | */ 45 | @Override 46 | public void setOptions(Undertow.Builder builder, Config undertowConfig) { 47 | long startTime = System.nanoTime(); 48 | Config serverOptionsCfg = undertowConfig.getConfig(SERVER_OPTIONS); 49 | serverOptionsCfg.getObject(OPTIONS_TYPE_OTHERS) 50 | .unwrapped() 51 | .forEach((key, val) -> builder.setServerOption(this.getOption(key), val)); 52 | serverOptionsCfg.getObject(OPTIONS_TYPE_LONG) 53 | .unwrapped() 54 | .forEach((key, val) -> builder.setServerOption(this.getOption(key), Long.valueOf((Integer) val))); 55 | this.logger.info("Undertow ServerOptions configured in [{}] ms!!", Times.elapsedMillis(startTime)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /server-adapters/undertow/src/main/java/com/adeptj/runtime/undertow/core/SimpleAccount.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.undertow.core; 21 | 22 | import io.undertow.security.idm.Account; 23 | 24 | import java.io.Serial; 25 | import java.security.Principal; 26 | import java.util.Set; 27 | 28 | /** 29 | * SimpleAccount. 30 | * 31 | * @author Rakesh.Kumar, AdeptJ 32 | */ 33 | final class SimpleAccount implements Account { 34 | 35 | @Serial 36 | private static final long serialVersionUID = -6710801164493273235L; 37 | 38 | private final SimplePrincipal principal; 39 | 40 | private final Set roles; 41 | 42 | SimpleAccount(SimplePrincipal principal, Set roles) { 43 | this.principal = principal; 44 | this.roles = roles; 45 | } 46 | 47 | @Override 48 | public Principal getPrincipal() { 49 | return principal; 50 | } 51 | 52 | @Override 53 | public Set getRoles() { 54 | return roles; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /server-adapters/undertow/src/main/java/com/adeptj/runtime/undertow/core/SimplePrincipal.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.undertow.core; 21 | 22 | import java.io.Serial; 23 | import java.io.Serializable; 24 | import java.security.Principal; 25 | import java.util.Objects; 26 | 27 | /** 28 | * SimplePrincipal. 29 | * 30 | * @author Rakesh.Kumar, AdeptJ 31 | */ 32 | final class SimplePrincipal implements Principal, Serializable { 33 | 34 | @Serial 35 | private static final long serialVersionUID = 1237481553907680848L; 36 | 37 | private final String name; 38 | 39 | SimplePrincipal(String name) { 40 | this.name = name; 41 | } 42 | 43 | @Override 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | @Override 49 | public boolean equals(Object o) { 50 | if (this == o) return true; 51 | if (o == null || getClass() != o.getClass()) return false; 52 | SimplePrincipal that = (SimplePrincipal) o; 53 | return Objects.equals(this.name, that.name); 54 | } 55 | 56 | @Override 57 | public int hashCode() { 58 | return Objects.hash(this.name); 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "SimplePrincipal [name=" + this.name + "]"; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /server-adapters/undertow/src/main/java/com/adeptj/runtime/undertow/core/SocketOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.undertow.core; 21 | 22 | import com.adeptj.runtime.kernel.util.Times; 23 | import com.typesafe.config.Config; 24 | import io.undertow.Undertow; 25 | 26 | /** 27 | * Undertow Socket Options. 28 | * 29 | * @author Rakesh.Kumar, AdeptJ 30 | */ 31 | public final class SocketOptions extends BaseOptions { 32 | 33 | private static final String SOCKET_OPTIONS = "socket-options"; 34 | 35 | /** 36 | * Configures the socket options dynamically. 37 | * 38 | * @param builder Undertow.Builder 39 | * @param undertowConfig Undertow Typesafe Config 40 | */ 41 | @Override 42 | public void setOptions(Undertow.Builder builder, Config undertowConfig) { 43 | long startTime = System.nanoTime(); 44 | undertowConfig.getObject(SOCKET_OPTIONS) 45 | .unwrapped() 46 | .forEach((key, val) -> builder.setSocketOption(this.getOption(key), val)); 47 | this.logger.info("Undertow SocketOptions configured in [{}] ms!!", Times.elapsedMillis(startTime)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /server-adapters/undertow/src/main/java/com/adeptj/runtime/undertow/core/WorkerOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.undertow.core; 21 | 22 | import com.typesafe.config.Config; 23 | import io.undertow.Undertow; 24 | import org.xnio.Option; 25 | 26 | /** 27 | * Undertow Worker Options. 28 | * 29 | * @author Rakesh.Kumar, AdeptJ 30 | */ 31 | public final class WorkerOptions extends BaseOptions { 32 | 33 | private static final String WORKER_OPTIONS = "worker-options"; 34 | 35 | /** 36 | * Configures the worker options dynamically. 37 | * 38 | * @param builder Undertow.Builder 39 | * @param undertowConfig Undertow Typesafe Config 40 | */ 41 | @Override 42 | public void setOptions(Undertow.Builder builder, Config undertowConfig) { 43 | undertowConfig.getObject(WORKER_OPTIONS) 44 | .unwrapped() 45 | .forEach((key, val) -> builder.setWorkerOption(this.getOption(key), val)); 46 | } 47 | 48 | public WorkerOptions overrideOption(Undertow.Builder builder, Option option, T value) { 49 | builder.setWorkerOption(option, value); 50 | return this; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /server-adapters/undertow/src/main/java/com/adeptj/runtime/undertow/handler/HealthCheckHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.undertow.handler; 21 | 22 | import io.undertow.server.HttpHandler; 23 | import io.undertow.server.HttpServerExchange; 24 | 25 | import static io.undertow.util.StatusCodes.OK; 26 | 27 | /** 28 | * Just returns a 200 OK for a health check request and simply terminate the request. 29 | * 30 | * @author Rakesh.Kumar, AdeptJ 31 | */ 32 | public class HealthCheckHandler implements HttpHandler { 33 | 34 | @Override 35 | public void handleRequest(HttpServerExchange exchange) { 36 | exchange.setStatusCode(OK); 37 | exchange.endExchange(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /server-adapters/undertow/src/main/java/com/adeptj/runtime/undertow/predicate/ContextPathPredicate.java: -------------------------------------------------------------------------------- 1 | /* 2 | ############################################################################### 3 | # # 4 | # Copyright 2016-2024, AdeptJ (http://www.adeptj.com) # 5 | # # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); # 7 | # you may not use this file except in compliance with the License. # 8 | # You may obtain a copy of the License at # 9 | # # 10 | # http://www.apache.org/licenses/LICENSE-2.0 # 11 | # # 12 | # Unless required by applicable law or agreed to in writing, software # 13 | # distributed under the License is distributed on an "AS IS" BASIS, # 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # 15 | # See the License for the specific language governing permissions and # 16 | # limitations under the License. # 17 | # # 18 | ############################################################################### 19 | */ 20 | package com.adeptj.runtime.undertow.predicate; 21 | 22 | import io.undertow.predicate.Predicate; 23 | import io.undertow.server.HttpServerExchange; 24 | 25 | /** 26 | * Predicate just checks if the request path is / i.e. root 27 | * 28 | * @author Rakesh.Kumar, AdeptJ 29 | */ 30 | public class ContextPathPredicate implements Predicate { 31 | 32 | private final String contextPath; 33 | 34 | public ContextPathPredicate(String contextPath) { 35 | this.contextPath = contextPath; 36 | } 37 | 38 | @Override 39 | public boolean resolve(HttpServerExchange value) { 40 | return value.getRequestPath().equals(this.contextPath); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /server-adapters/undertow/src/main/resources/META-INF/services/com.adeptj.runtime.kernel.Server: -------------------------------------------------------------------------------- 1 | com.adeptj.runtime.undertow.UndertowServer -------------------------------------------------------------------------------- /server-adapters/undertow/src/main/resources/i18n/undertow.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdeptJ/adeptj-runtime/5cdf191155a497ed110207cafc1c3279e1339cc0/server-adapters/undertow/src/main/resources/i18n/undertow.properties --------------------------------------------------------------------------------