├── .classpath ├── .gitignore ├── .mvn └── wrapper │ ├── MavenWrapperDownloader.java │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── .pre-commit-config.yaml ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── codegen-cli ├── .classpath ├── codegen.ps1 ├── codegen.sh ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── networknt │ │ │ └── codegen │ │ │ ├── Cli.java │ │ │ └── YAMLFileParameterizer.java │ └── resources │ │ └── config │ │ └── service.yml │ └── test │ ├── java │ └── com │ │ └── networknt │ │ └── codegen │ │ ├── CliTest.java │ │ └── YAMLFileParameterizerTest.java │ └── resources │ ├── externalTemplates │ └── templates │ │ └── rest │ │ └── buildSh.rocker.raw │ ├── logback-test.xml │ ├── openapi.json │ ├── openapi.yaml │ └── rocker-compiler-example.conf ├── codegen-core ├── .classpath ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── networknt │ │ └── codegen │ │ ├── Generator.java │ │ └── Utils.java │ └── test │ ├── java │ └── com │ │ └── networknt │ │ └── codegen │ │ ├── JsonDefaultTest.java │ │ └── UtilsTest.java │ └── resources │ └── logback-test.xml ├── codegen-fwk ├── .classpath ├── dependency-reduced-pom.xml ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── networknt │ │ └── codegen │ │ └── FrameworkRegistry.java │ └── test │ ├── java │ └── com │ │ └── networknt │ │ └── codegen │ │ └── FrameworkRegistryTest.java │ └── resources │ ├── config │ └── service.yml │ └── logback-test.xml ├── codegen-web ├── .classpath ├── pom.xml ├── src │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── networknt │ │ │ │ └── codegen │ │ │ │ ├── CodegenWebConfig.java │ │ │ │ └── handler │ │ │ │ ├── CodegenMultipleHandler.java │ │ │ │ ├── CodegenResourceProvider.java │ │ │ │ ├── CodegenSingleHandler.java │ │ │ │ ├── FrameworkListHandler.java │ │ │ │ ├── SchemaGetHandler.java │ │ │ │ └── ValidateUploadFileHandler.java │ │ └── resources │ │ │ ├── config │ │ │ ├── codegen-web.yml │ │ │ ├── cors.yml │ │ │ ├── handler.yml │ │ │ ├── rpc-router.yml │ │ │ └── service.yml │ │ │ └── spec.yaml │ └── test │ │ ├── java │ │ └── com │ │ │ └── networknt │ │ │ └── codegen │ │ │ └── handler │ │ │ ├── FrameworkListHandlerTest.java │ │ │ ├── GeneratorServiceHandlerTest.java │ │ │ ├── SchemaGetHandlerTest.java │ │ │ └── TestServer.java │ │ └── resources │ │ ├── config │ │ ├── client.keystore │ │ ├── client.truststore │ │ ├── primary.crt │ │ ├── secondary.crt │ │ ├── server.keystore │ │ ├── server.truststore │ │ └── values.yml │ │ └── logback-test.xml └── view │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── public │ ├── favicon.ico │ ├── index.html │ └── manifest.json │ ├── src │ ├── App.css │ ├── App.js │ ├── App.test.js │ ├── actions │ │ ├── index.js │ │ └── types.js │ ├── components │ │ ├── Document.js │ │ ├── Form.js │ │ ├── GitHub.js │ │ ├── Home.js │ │ ├── ListItem.js │ │ ├── MuiTreeList.js │ │ └── ResponsiveDrawer.js │ ├── data │ │ ├── Forms.json │ │ └── ListItems.json │ ├── index.css │ ├── index.js │ ├── logo.svg │ ├── reducers │ │ ├── FormReducer.js │ │ ├── index.js │ │ └── menu.js │ └── serviceWorker.js │ └── yarn.lock ├── config.json ├── light-graphql-4j ├── .classpath ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── networknt │ │ │ └── codegen │ │ │ └── graphql │ │ │ └── GraphqlGenerator.java │ └── resources │ │ ├── binaries │ │ ├── client.keystore │ │ ├── client.truststore │ │ ├── server.keystore │ │ └── server.truststore │ │ ├── light-graphql-4j.json │ │ ├── maven │ │ ├── mvn │ │ │ └── wrapper │ │ │ │ ├── MavenWrapperDownloader.java │ │ │ │ ├── maven-wrapper.jar │ │ │ │ └── maven-wrapper.properties │ │ ├── mvnw │ │ └── mvnw.cmd │ │ └── templates │ │ └── graphql │ │ ├── LICENSE.rocker.raw │ │ ├── README.md.rocker.raw │ │ ├── appStatusYml.rocker.raw │ │ ├── buildSh.rocker.raw │ │ ├── classpath.rocker.raw │ │ ├── dockerfile.rocker.raw │ │ ├── dockerfileslim.rocker.raw │ │ ├── gitignore.rocker.raw │ │ ├── handlerProvider.rocker.raw │ │ ├── handlerYml.rocker.raw │ │ ├── logback.rocker.raw │ │ ├── pom.xml.rocker.raw │ │ ├── primaryCrt.rocker.raw │ │ ├── project.rocker.raw │ │ ├── schemaClass.rocker.raw │ │ ├── schemaClassExample.rocker.raw │ │ ├── secondaryCrt.rocker.raw │ │ ├── securityYml.rocker.raw │ │ ├── serverYml.rocker.raw │ │ ├── serviceYml.rocker.raw │ │ ├── testServer.rocker.raw │ │ ├── validatorYml.rocker.raw │ │ └── values.rocker.raw │ └── test │ ├── java │ └── com │ │ └── networknt │ │ └── codegen │ │ └── graphql │ │ └── GraphqlGeneratorTest.java │ └── resources │ ├── config.json │ ├── logback-test.xml │ └── schema.graphqls ├── light-hybrid-4j ├── .classpath ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── networknt │ │ │ └── codegen │ │ │ └── hybrid │ │ │ ├── HybridGenerator.java │ │ │ ├── HybridServerGenerator.java │ │ │ └── HybridServiceGenerator.java │ └── resources │ │ ├── binaries │ │ ├── client.keystore │ │ ├── client.truststore │ │ ├── server.keystore │ │ └── server.truststore │ │ ├── light-hybrid-4j-server.json │ │ ├── light-hybrid-4j-service.json │ │ ├── maven │ │ ├── mvn │ │ │ └── wrapper │ │ │ │ ├── MavenWrapperDownloader.java │ │ │ │ ├── maven-wrapper.jar │ │ │ │ └── maven-wrapper.properties │ │ ├── mvnw │ │ └── mvnw.cmd │ │ └── templates │ │ └── hybrid │ │ ├── LICENSE.rocker.raw │ │ ├── appStatusYml.rocker.raw │ │ ├── classpath.rocker.raw │ │ ├── gitignore.rocker.raw │ │ ├── handler.rocker.raw │ │ ├── handlerTest.rocker.raw │ │ ├── handlerYml.rocker.raw │ │ ├── kafkaConsumerYml.rocker.raw │ │ ├── kafkaProducerYml.rocker.raw │ │ ├── kafkaStreamsYml.rocker.raw │ │ ├── logback.rocker.raw │ │ ├── project.rocker.raw │ │ ├── server │ │ ├── README.md.rocker.raw │ │ ├── buildSh.rocker.raw │ │ ├── dockerfile.rocker.raw │ │ ├── dockerfileslim.rocker.raw │ │ └── pom.xml.rocker.raw │ │ ├── service │ │ ├── README.md.rocker.raw │ │ └── pom.xml.rocker.raw │ │ ├── testServer.rocker.raw │ │ └── values.rocker.raw │ └── test │ ├── java │ └── com │ │ └── networknt │ │ └── codegen │ │ └── hybrid │ │ ├── HybridServerGeneratorTest.java │ │ └── HybridServiceGeneratorTest.java │ └── resources │ ├── logback-test.xml │ ├── serverConfig.json │ ├── service.yaml │ ├── serviceConfig.json │ └── spec.yaml ├── light-rest-4j ├── .classpath ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── networknt │ │ │ └── codegen │ │ │ └── rest │ │ │ ├── AbstractLambdaGenerator.java │ │ │ ├── ModelCallback.java │ │ │ ├── OpenApiGenerator.java │ │ │ ├── OpenApiKotlinGenerator.java │ │ │ ├── OpenApiLambdaGenerator.java │ │ │ ├── OpenApiLambdaNativeGenerator.java │ │ │ ├── OpenApiLightGenerator.java │ │ │ ├── OpenApiSpecGenerator.java │ │ │ ├── OpenApiSpringGenerator.java │ │ │ └── UrlGenerator.java │ └── resources │ │ ├── binaries │ │ ├── client.keystore │ │ ├── client.truststore │ │ ├── server.keystore │ │ └── server.truststore │ │ ├── gradle │ │ ├── gradle │ │ │ └── wrapper │ │ │ │ ├── gradle-wrapper.jar │ │ │ │ └── gradle-wrapper.properties │ │ ├── gradlew │ │ └── gradlew.bat │ │ ├── maven │ │ ├── mvn │ │ │ └── wrapper │ │ │ │ ├── MavenWrapperDownloader.java │ │ │ │ ├── maven-wrapper.jar │ │ │ │ └── maven-wrapper.properties │ │ ├── mvnw │ │ └── mvnw.cmd │ │ ├── openapi.json │ │ ├── openapikotlin.json │ │ ├── openapilambda.json │ │ ├── swagger.json │ │ └── templates │ │ ├── lambda │ │ ├── AppGateway.java.rocker.raw │ │ ├── AppProxy.java.rocker.raw │ │ ├── AppTest.java.rocker.raw │ │ ├── BusinessHandler.java.rocker.raw │ │ ├── BusinessHandlerTest.java.rocker.raw │ │ ├── Dockerfile.rocker.raw │ │ ├── DockerfileProxy.rocker.raw │ │ ├── EC2 │ │ │ ├── privateProxyYaml.rocker.raw │ │ │ ├── privateVpcYaml.rocker.raw │ │ │ ├── publicProxyYaml.rocker.raw │ │ │ └── publicVpcYaml.rocker.raw │ │ ├── Fargate │ │ │ ├── privateProxyYaml.rocker.raw │ │ │ ├── privateVpcYaml.rocker.raw │ │ │ ├── publicProxyYaml.rocker.raw │ │ │ └── publicVpcYaml.rocker.raw │ │ ├── Makefile.rocker.raw │ │ ├── README.md.rocker.raw │ │ ├── appYml.rocker.raw │ │ ├── bootstrap.rocker.raw │ │ ├── buildGraalvmSh.rocker.raw │ │ ├── buildGradle.rocker.raw │ │ ├── buildSh.rocker.raw │ │ ├── event.json.rocker.raw │ │ ├── gitignore.rocker.raw │ │ ├── gradleProperties.rocker.raw │ │ ├── logback.rocker.raw │ │ ├── pom.xml.rocker.raw │ │ ├── proxy │ │ │ ├── handlerYml.rocker.raw │ │ │ ├── lambdaInvokerYml.rocker.raw │ │ │ ├── logback.xml │ │ │ ├── proxy.yml.rocker.raw │ │ │ └── server.yml.rocker.raw │ │ ├── reflectJson.rocker.raw │ │ ├── resourceJson.rocker.raw │ │ ├── template.yaml.rocker.raw │ │ └── values.rocker.raw │ │ ├── lambdanative │ │ ├── App.java.rocker.raw │ │ ├── AppTest.java.rocker.raw │ │ ├── BusinessHandler.java.rocker.raw │ │ ├── BusinessHandlerTest.java.rocker.raw │ │ ├── Dockerfile.rocker.raw │ │ ├── DockerfileProxy.rocker.raw │ │ ├── LICENSE.rocker.raw │ │ ├── Makefile.rocker.raw │ │ ├── README.md.rocker.raw │ │ ├── appYml.rocker.raw │ │ ├── bootstrap.rocker.raw │ │ ├── buildGraalvmSh.rocker.raw │ │ ├── buildGradle.rocker.raw │ │ ├── buildSh.rocker.raw │ │ ├── event.json.rocker.raw │ │ ├── gitattributes.rocker.raw │ │ ├── gitignore.rocker.raw │ │ ├── gradleProperties.rocker.raw │ │ ├── logback.rocker.raw │ │ ├── pom.xml.rocker.raw │ │ ├── proxy │ │ │ ├── handlerYml.rocker.raw │ │ │ ├── lambdaInvokerYml.rocker.raw │ │ │ ├── logback.xml │ │ │ ├── proxy.yml.rocker.raw │ │ │ └── server.yml.rocker.raw │ │ ├── reflectJson.rocker.raw │ │ ├── resourceJson.rocker.raw │ │ ├── template.yaml.rocker.raw │ │ └── values.rocker.raw │ │ ├── rest │ │ ├── LICENSE.rocker.raw │ │ ├── README.md.rocker.raw │ │ ├── buildSh.rocker.raw │ │ ├── classpath.rocker.raw │ │ ├── client │ │ │ ├── buildGradleKts.rocker.raw │ │ │ ├── pom.xml.rocker.raw │ │ │ └── settingsGradleKts.rocker.raw │ │ ├── dockerfile.rocker.raw │ │ ├── dockerfileslim.rocker.raw │ │ ├── enumClass.rocker.raw │ │ ├── enumInline.rocker.raw │ │ ├── gitignore.rocker.raw │ │ ├── handler.rocker.raw │ │ ├── handlerService.rocker.raw │ │ ├── handlerSingle.rocker.raw │ │ ├── handlerTest.rocker.raw │ │ ├── handlerYml.rocker.raw │ │ ├── kafkaProducerYml.rocker.raw │ │ ├── kafkaStreamsYml.rocker.raw │ │ ├── kubernetes.rocker.raw │ │ ├── logback.rocker.raw │ │ ├── model │ │ │ ├── buildGradleKts.rocker.raw │ │ │ ├── pom.xml.rocker.raw │ │ │ └── settingsGradleKts.rocker.raw │ │ ├── parent │ │ │ ├── buildGradleKts.rocker.raw │ │ │ ├── gradleProperties.rocker.raw │ │ │ ├── pom.xml.rocker.raw │ │ │ └── settingsGradleKts.rocker.raw │ │ ├── pojo.rocker.raw │ │ ├── project.rocker.raw │ │ ├── schemaRegistryYml.rocker.raw │ │ ├── server │ │ │ ├── buildGradleKts.rocker.raw │ │ │ ├── pom.xml.rocker.raw │ │ │ └── settingsGradleKts.rocker.raw │ │ ├── service │ │ │ ├── buildGradleKts.rocker.raw │ │ │ ├── pom.xml.rocker.raw │ │ │ └── settingsGradleKts.rocker.raw │ │ ├── single │ │ │ ├── buildGradleKts.rocker.raw │ │ │ ├── gradleProperties.rocker.raw │ │ │ ├── pom.xml.rocker.raw │ │ │ └── settingsGradleKts.rocker.raw │ │ ├── testServer.rocker.raw │ │ └── values.rocker.raw │ │ └── restkotlin │ │ ├── LICENSE.rocker.raw │ │ ├── README.md.rocker.raw │ │ ├── appStatusYml.rocker.raw │ │ ├── buildGradleKts.rocker.raw │ │ ├── buildSh.rocker.raw │ │ ├── dockerfile.rocker.raw │ │ ├── dockerfileslim.rocker.raw │ │ ├── enumClass.rocker.raw │ │ ├── enumInline.rocker.raw │ │ ├── gitignore.rocker.raw │ │ ├── gradleProperties.rocker.raw │ │ ├── handler.rocker.raw │ │ ├── handlerTest.rocker.raw │ │ ├── junitPlatformProperties.rocker.raw │ │ ├── lightTestServerKt.rocker.raw │ │ ├── logback.rocker.raw │ │ ├── maskYml.rocker.raw │ │ ├── model.rocker.raw │ │ ├── openapi │ │ ├── config.rocker.raw │ │ ├── handlerYml.rocker.raw │ │ ├── service.yml.rocker.raw │ │ └── values.rocker.raw │ │ ├── openapiSecurity.yml.rocker.raw │ │ ├── openapiValidator.yml.rocker.raw │ │ ├── pojo.rocker.raw │ │ ├── server.yml.rocker.raw │ │ ├── settingsGradleKts.rocker.raw │ │ ├── swaggerValidator.yml.rocker.raw │ │ └── testServer.rocker.raw │ └── test │ ├── java │ └── com │ │ └── networknt │ │ └── codegen │ │ ├── ConfigTest.java │ │ ├── OpenApiArrayReferenceGeneratorTest.java │ │ ├── OpenApiKotlinGeneratorTest.java │ │ ├── OpenApiLambdaGeneratorTest.java │ │ ├── OpenApiLightGeneratorTest.java │ │ └── rest │ │ └── OpenApiSpecGeneratorTest.java │ └── resources │ ├── account-info.yaml │ ├── array_ref-oa3.json │ ├── config.json │ ├── config.yaml │ ├── configKafka.json │ ├── configProxyLambda.json │ ├── configlambda.json │ ├── configlambdamaven.json │ ├── logback-test.xml │ ├── openapi-enum.yaml │ ├── openapi-error.yaml │ ├── openapi-noServers.yaml │ ├── openapi.json │ ├── openapi.yaml │ ├── openapilambda.json │ ├── openapilambda.yaml │ ├── petstore.yaml │ └── swagger.json ├── mvnw ├── mvnw.cmd └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | bower_components/ 3 | node_modules/ 4 | dist/ 5 | .idea/ 6 | .tmp/ 7 | .project 8 | .settings 9 | .metadata/ 10 | *.iml 11 | *.log 12 | *.tmp 13 | *.zip 14 | *.bak 15 | *.versionsBackup 16 | dependency-reduced-pom.xml 17 | bin/ 18 | .vscode/ 19 | 20 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 21 | hs_err_pid* 22 | 23 | **/.DS_Store 24 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar 3 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v5.0.0 4 | hooks: 5 | - id: trailing-whitespace 6 | - id: end-of-file-fixer 7 | - id: check-yaml 8 | - id: check-added-large-files 9 | - repo: https://github.com/networknt/pre-commit-hook-keyword 10 | rev: f17c4de14fc24420f6768c19cad06ba03af06d86 11 | hooks: 12 | - id: keywordscan 13 | args: ["--keywords=c3VubGlmZQ==,Y2liYw==,c3VuIGxpZmU="] 14 | types: ["text"] 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | cache: 3 | directories: 4 | - $HOME/.m2 5 | jdk: 6 | - openjdk11 7 | 8 | branches: 9 | only: 10 | - master 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | A code generator based on [rocker](https://github.com/fizzed/rocker) that can be used as a command line utility or web service. 2 | 3 | [Stack Overflow](https://stackoverflow.com/questions/tagged/light-4j) | 4 | [Google Group](https://groups.google.com/forum/#!forum/light-4j) | 5 | [Gitter Chat](https://gitter.im/networknt/light-codegen) | 6 | [Subreddit](https://www.reddit.com/r/lightapi/) | 7 | [Youtube Channel](https://www.youtube.com/channel/UCHCRMWJVXw8iB7zKxF55Byw) | 8 | [Documentation](https://doc.networknt.com/tool/light-codegen/) | 9 | [Contribution Guide](https://doc.networknt.com/contribute/) | 10 | 11 | [![Build Status](https://travis-ci.org/networknt/light-codegen.svg?branch=master)](https://travis-ci.org/networknt/light-codegen) 12 | 13 | The Light platform contains several frameworks to build different styles of APIs or microservices based on the contract specifications. It encourages users to create service contract specification before coding, and it would be nice if we can scaffold a project based on the designed specification. Further, it would be even sweeter if we could utilize the specification during runtime to verify the security and validate input request/out response based on the same specification. 14 | 15 | Before we built our generator, we looked at the open-source community and couldn't find anything suitable for our needs. So we created one over a weekend, and it turned out very successful. If you want to know more about it, please check out the [light-codegen document](https://doc.networknt.com/tool/light-codegen/). 16 | 17 | The generator is very easy to use, and there are numeric ways to use it. Command-line, Docker, Scripting, and [Web UI](https://codegen.lightapi.net). To get started, please follow the [getting-started](https://doc.networknt.com/getting-started/light-codegen/). 18 | 19 | If you want to know all the options with the light-codegen, you can follow the tutorials for each generator at [light-codegen tutorial](https://doc.networknt.com/tutorial/generator/). 20 | 21 | Also, there are so many [other tutorials](https://doc.networknt.com/tutorial/) that are using light-codegen to scaffold projects, and these can be found in the tutorial section. 22 | -------------------------------------------------------------------------------- /codegen-cli/codegen.ps1: -------------------------------------------------------------------------------- 1 | Set-PSDebug -Off 2 | #Set-PSDebug -Trace 2 3 | 4 | $workDir = $PSScriptRoot 5 | $cliJar = "$workDir\codegen-cli.jar" 6 | 7 | if (-not (Test-Path $cliJar)) { 8 | Write-Host "$cliJar cannot be found." 9 | Exit 1 10 | } 11 | 12 | if (-not (Test-Path env:JAVA_HOME)) { 13 | Write-Host "JAVA_HOME is not set." 14 | Exit 1 15 | } 16 | 17 | $compilerConf = "$workDir\rocker-compiler.conf" 18 | 19 | if (-not (Test-Path $compilerConf)) { 20 | Write-Host "generate config $compilerConf" 21 | # Note: do not add quotation marks to the value of rocker.template.dir even if there are spaces in the path 22 | $escapedDir = $workDir -replace '\\', '/' 23 | Set-Content -Path $compilerConf -Value "rocker.template.dir=$escapedDir" 24 | } 25 | 26 | $classDir = "$workDir\target\classes" 27 | 28 | if (-not (Test-Path -PathType Container $classDir)) { 29 | Write-Host "create class folder $classDir" 30 | New-Item -ItemType Directory -Force -Path $classDir 31 | } 32 | 33 | # Note: please point JAVA_HOME to a JDK installation. JRE is not sufficient. 34 | $javaHome = (get-item env:JAVA_HOME).Value 35 | # Note: the order of the pathes in the classpath matters 36 | $classpath = ".;target\classes;codegen-cli.jar" 37 | 38 | & $javaHome\bin\java -cp $classpath com.networknt.codegen.Cli $args 39 | -------------------------------------------------------------------------------- /codegen-cli/codegen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | CURRENT_DIR=$PWD 6 | 7 | if [ ! -f "$CURRENT_DIR/codegen-cli.jar" ]; then 8 | echo "codegen-cli.jar cannot be found!" 9 | 10 | exit 1 11 | fi 12 | 13 | if [ -z "$JAVA_HOME" ]; then 14 | echo "JAVA_HOME is not set" 15 | 16 | exit 1 17 | fi 18 | 19 | if [ ! -f "$CURRENT_DIR/rocker-compiler.conf" ]; then 20 | echo "generate config $CURRENT_DIR/rocker-compiler.conf" 21 | 22 | echo "rocker.template.dir=$CURRENT_DIR" > rocker-compiler.conf 23 | fi 24 | 25 | if [ ! -d "$CURRENT_DIR/target/classes" ]; then 26 | echo "create class folder $CURRENT_DIR/target/classes" 27 | 28 | mkdir -p "$CURRENT_DIR/target/classes" 29 | fi 30 | 31 | 32 | # Note: the order of the pathes in the classpath matters 33 | # You need to change the path separator to ';' in order to run this script in git bash 34 | JAVA_OPS="-cp .:target/classes/:codegen-cli.jar com.networknt.codegen.Cli" 35 | 36 | # Note: please point JAVA_HOME to a JDK installation. JRE is not sufficient. 37 | "$JAVA_HOME/bin/java" $JAVA_OPS "$@" 38 | 39 | exit 0 40 | -------------------------------------------------------------------------------- /codegen-cli/src/main/resources/config/service.yml: -------------------------------------------------------------------------------- 1 | # Singleton service factory configuration/IoC injection 2 | singletons: 3 | # Generator interface implementations 4 | - com.networknt.codegen.Generator: 5 | - com.networknt.codegen.rest.OpenApiLightGenerator 6 | - com.networknt.codegen.hybrid.HybridServerGenerator 7 | - com.networknt.codegen.hybrid.HybridServiceGenerator 8 | - com.networknt.codegen.graphql.GraphqlGenerator 9 | - com.networknt.codegen.rest.OpenApiKotlinGenerator 10 | - com.networknt.codegen.rest.OpenApiLambdaGenerator 11 | - com.networknt.codegen.rest.OpenApiSpecGenerator 12 | - com.networknt.codegen.rest.OpenApiLambdaNativeGenerator 13 | -------------------------------------------------------------------------------- /codegen-cli/src/test/java/com/networknt/codegen/CliTest.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.fasterxml.jackson.databind.ObjectReader; 6 | import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; 7 | import org.junit.jupiter.api.Test; 8 | 9 | 10 | /** 11 | * Created by steve on 24/04/17. 12 | */ 13 | public class CliTest { 14 | private ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory()); 15 | private final ObjectReader reader = objectMapper.reader(); 16 | 17 | @Test 18 | public void testJsonModel() throws Exception { 19 | JsonNode modelNode = reader.readTree(CliTest.class.getClassLoader().getResourceAsStream("openapi.json")); 20 | System.out.println(modelNode); 21 | } 22 | 23 | @Test 24 | public void testYamlModel() throws Exception { 25 | JsonNode modelNode = reader.readTree(CliTest.class.getClassLoader().getResourceAsStream("openapi.yaml")); 26 | System.out.println(modelNode); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /codegen-cli/src/test/resources/externalTemplates/templates/rest/buildSh.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String org, String serviceId) 2 | #!/bin/bash 3 | #Modified ..... 4 | set -ex 5 | 6 | VERSION=$1 7 | IMAGE_NAME="@org/@serviceId" 8 | 9 | showHelp() { 10 | echo " " 11 | echo "Error: $1" 12 | echo " " 13 | echo " build.sh [VERSION]" 14 | echo " " 15 | echo " where [VERSION] version of the docker image that you want to publish (example: 0.0.1)" 16 | echo " " 17 | echo " example: ./build.sh 0.0.1" 18 | echo " " 19 | } 20 | 21 | build() { 22 | echo "Building ..." 23 | mvn clean install 24 | echo "Successfully built!" 25 | } 26 | 27 | cleanup() { 28 | if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" != "" ]]; then 29 | echo "Removing old $IMAGE_NAME images" 30 | docker images | grep $IMAGE_NAME | awk '{print $3}' | xargs docker rmi -f 31 | echo "Cleanup completed!" 32 | fi 33 | } 34 | 35 | publish() { 36 | echo "Building Docker image with version $VERSION" 37 | docker build -t $IMAGE_NAME:$VERSION -t $IMAGE_NAME:latest -f ./docker/Dockerfile . --no-cache=true 38 | docker build -t $IMAGE_NAME:$VERSION-redhat -f ./docker/Dockerfile-Redhat . --no-cache=true 39 | echo "Images built with version $VERSION" 40 | echo "Pushing image to DockerHub" 41 | docker push $IMAGE_NAME -a 42 | echo "Image successfully published!" 43 | } 44 | 45 | if [ -z $VERSION ]; then 46 | showHelp "[VERSION] parameter is missing" 47 | exit 48 | fi 49 | 50 | build; 51 | cleanup; 52 | publish; 53 | -------------------------------------------------------------------------------- /codegen-cli/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /codegen-cli/src/test/resources/rocker-compiler-example.conf: -------------------------------------------------------------------------------- 1 | rocker.template.dir=src/test/resources/externalTemplates/ 2 | -------------------------------------------------------------------------------- /codegen-core/src/test/java/com/networknt/codegen/JsonDefaultTest.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.node.ObjectNode; 5 | import org.junit.jupiter.api.Test; 6 | 7 | 8 | public class JsonDefaultTest { 9 | String s = "{\"enabled\":true,\"level\":5,\"name\":\"steve\"}"; 10 | 11 | @Test 12 | public void testBooleanDefault() throws Exception { 13 | JsonNode node = Generator.jsonMapper.readTree(s); 14 | ((ObjectNode)node).put("useData", true); 15 | boolean b = node.get("useData").booleanValue(); 16 | System.out.println(b); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /codegen-core/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /codegen-fwk/src/main/java/com/networknt/codegen/FrameworkRegistry.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen; 2 | 3 | import com.networknt.service.SingletonServiceFactory; 4 | 5 | import java.util.*; 6 | 7 | /** 8 | * This class register all the framework generators. 9 | * Created by steve on 26/04/17. 10 | */ 11 | public class FrameworkRegistry { 12 | 13 | private final Map frameworks; 14 | 15 | private static final FrameworkRegistry INSTANCE = new FrameworkRegistry(); 16 | 17 | private FrameworkRegistry() { 18 | Generator[] generators = SingletonServiceFactory.getBeans(Generator.class); 19 | final Map map = new HashMap<>(); 20 | if(generators != null) Arrays.stream(generators).forEach(s -> map.put(s.getFramework(), s)); 21 | this.frameworks = Collections.unmodifiableMap(map); 22 | } 23 | 24 | public Set getFrameworks() { 25 | return frameworks.keySet(); 26 | } 27 | 28 | public Generator getGenerator(String framework) { 29 | return frameworks.get(framework); 30 | } 31 | 32 | public static FrameworkRegistry getInstance() { 33 | return INSTANCE; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /codegen-fwk/src/test/java/com/networknt/codegen/FrameworkRegistryTest.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen; 2 | 3 | import static org.junit.jupiter.api.Assertions.*; 4 | import org.junit.jupiter.api.Test; 5 | 6 | import java.util.Set; 7 | 8 | /** 9 | * Created by steve on 26/04/17. 10 | */ 11 | public class FrameworkRegistryTest { 12 | 13 | @Test 14 | public void testRegistry() { 15 | FrameworkRegistry registry = FrameworkRegistry.getInstance(); 16 | Set frameworks = registry.getFrameworks(); 17 | assertTrue(frameworks.size() > 0); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /codegen-fwk/src/test/resources/config/service.yml: -------------------------------------------------------------------------------- 1 | # Singleton service factory configuration/IoC injection 2 | singletons: 3 | # Generator interface implementations 4 | - com.networknt.codegen.Generator: 5 | # - com.networknt.codegen.rest.OpenApiGenerator 6 | # - com.networknt.codegen.hybrid.HybridServerGenerator 7 | # - com.networknt.codegen.hybrid.HybridServiceGenerator 8 | - com.networknt.codegen.graphql.GraphqlGenerator 9 | # - com.networknt.codegen.rest.OpenApiKotlinGenerator 10 | -------------------------------------------------------------------------------- /codegen-fwk/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /codegen-web/src/main/java/com/networknt/codegen/CodegenWebConfig.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen; 2 | 3 | /** 4 | * Created by steve on 22/10/16. 5 | */ 6 | public class CodegenWebConfig { 7 | String tmpFolder; 8 | String zipFolder; 9 | int zipKeptMinute; 10 | 11 | public CodegenWebConfig() { 12 | } 13 | 14 | public String getTmpFolder() { 15 | return tmpFolder; 16 | } 17 | 18 | public void setTmpFolder(String tmpFolder) { 19 | this.tmpFolder = tmpFolder; 20 | } 21 | 22 | public String getZipFolder() { 23 | return zipFolder; 24 | } 25 | 26 | public void setZipFolder(String zipFolder) { 27 | this.zipFolder = zipFolder; 28 | } 29 | 30 | public int getZipKeptMinute() { 31 | return zipKeptMinute; 32 | } 33 | 34 | public void setZipKeptMinute(int zipKeptMinute) { 35 | this.zipKeptMinute = zipKeptMinute; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /codegen-web/src/main/java/com/networknt/codegen/handler/CodegenResourceProvider.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen.handler; 2 | 3 | import com.networknt.resource.PathResourceProvider; 4 | import io.undertow.server.handlers.resource.PathResourceManager; 5 | import io.undertow.server.handlers.resource.ResourceManager; 6 | 7 | import java.io.File; 8 | import java.net.URL; 9 | 10 | /** 11 | * @author Nicholas Azar 12 | * Created on April 22, 2018 13 | */ 14 | public class CodegenResourceProvider implements PathResourceProvider { 15 | @Override 16 | public String getPath() { 17 | return "/view"; 18 | } 19 | 20 | @Override 21 | public Boolean isPrefixPath() { 22 | return true; 23 | } 24 | 25 | @Override 26 | public ResourceManager getResourceManager() { 27 | URL resourceDir = CodegenResourceProvider.class.getResource("/view"); 28 | if (resourceDir != null) { 29 | return new PathResourceManager(new File(resourceDir.getFile()).toPath()); 30 | } 31 | return null; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /codegen-web/src/main/java/com/networknt/codegen/handler/FrameworkListHandler.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen.handler; 2 | 3 | import com.fasterxml.jackson.core.JsonProcessingException; 4 | import com.networknt.codegen.FrameworkRegistry; 5 | import com.networknt.config.Config; 6 | import com.networknt.rpc.HybridHandler; 7 | import com.networknt.rpc.router.ServiceHandler; 8 | import com.networknt.utility.NioUtils; 9 | import io.undertow.server.HttpServerExchange; 10 | import io.undertow.util.HttpString; 11 | import org.slf4j.Logger; 12 | import org.slf4j.LoggerFactory; 13 | 14 | import java.nio.ByteBuffer; 15 | import java.util.Set; 16 | 17 | /** 18 | * Created by steve on 26/04/17. 19 | */ 20 | @ServiceHandler(id="lightapi.net/codegen/listFramework/0.0.1") 21 | public class FrameworkListHandler implements HybridHandler { 22 | static private final Logger logger = LoggerFactory.getLogger(FrameworkListHandler.class); 23 | static private Set frameworks = FrameworkRegistry.getInstance().getFrameworks(); 24 | 25 | /** 26 | * Returns a JSON list of all available frameworks defined in the service.yml of codegen-cli. 27 | * If any issues occur with converting the result to JSON, an empty string is returned (not an empty json list). 28 | */ 29 | @Override 30 | public ByteBuffer handle(HttpServerExchange exchange, Object input) { 31 | String result = ""; 32 | exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json"); 33 | try { 34 | result = Config.getInstance().getMapper().writeValueAsString(frameworks); 35 | } catch (JsonProcessingException e) { 36 | // return empty back in this case. 37 | } 38 | return NioUtils.toByteBuffer(result); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /codegen-web/src/main/java/com/networknt/codegen/handler/SchemaGetHandler.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen.handler; 2 | 3 | import com.networknt.codegen.FrameworkRegistry; 4 | import com.networknt.codegen.Generator; 5 | import com.networknt.rpc.HybridHandler; 6 | import com.networknt.rpc.router.ServiceHandler; 7 | import io.undertow.server.HttpServerExchange; 8 | import io.undertow.util.HttpString; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.io.IOException; 13 | import java.nio.ByteBuffer; 14 | import java.util.Map; 15 | 16 | /** 17 | * Created by steve on 10/05/17. 18 | */ 19 | @ServiceHandler(id="lightapi.net/codegen/getSchema/0.0.1") 20 | public class SchemaGetHandler implements HybridHandler { 21 | static private final Logger logger = LoggerFactory.getLogger(SchemaGetHandler.class); 22 | 23 | @Override 24 | public ByteBuffer handle(HttpServerExchange exchange, Object input) { 25 | exchange.getResponseHeaders().add(new HttpString("Content-Type"), "application/json"); 26 | Map map = (Map)input; 27 | String framework = (String)map.get("framework"); 28 | Generator generator = FrameworkRegistry.getInstance().getGenerator(framework); 29 | 30 | ByteBuffer bf = null; 31 | try { 32 | bf = generator.getConfigSchema(); 33 | } catch (IOException e) { 34 | // return empty back in this case. 35 | } 36 | return bf; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /codegen-web/src/main/resources/config/codegen-web.yml: -------------------------------------------------------------------------------- 1 | # Code generation web service configuration 2 | --- 3 | # Temp folder to hold the generated projects 4 | tmpFolder: /tmp 5 | # The folder that contains generated and zipped files 6 | zipFolder: /tmp/zip 7 | # Geneated project zip file will be removed after 15 minutes 8 | zipKeptMinute: 15 9 | -------------------------------------------------------------------------------- /codegen-web/src/main/resources/config/cors.yml: -------------------------------------------------------------------------------- 1 | --- 2 | description: Cors Http Handler 3 | # If cors handler is enabled or not 4 | enabled: true 5 | # Allowed origins, you can have multiple and with port if port is not 80 or 443 6 | # Wildcard is not supported for security reasons. 7 | allowedOrigins: 8 | - http://localhost 9 | # Support for react dev server. 10 | - http://localhost:3001 11 | # Allowed methods list. 12 | allowedMethods: 13 | - GET 14 | - POST 15 | - OPTIONS 16 | -------------------------------------------------------------------------------- /codegen-web/src/main/resources/config/rpc-router.yml: -------------------------------------------------------------------------------- 1 | --- 2 | description: RPC router description 3 | handlerPackages: com.networknt.codegen 4 | jsonPath: /codegen 5 | -------------------------------------------------------------------------------- /codegen-web/src/main/resources/config/service.yml: -------------------------------------------------------------------------------- 1 | # Singleton service factory configuration/IoC injection 2 | singletons: 3 | # StartupHookProvider implementations 4 | - com.networknt.server.StartupHookProvider: 5 | # registry all service handlers by from annotations 6 | - com.networknt.rpc.router.RpcStartupHookProvider 7 | # ShutdownHookProvider implementations 8 | # - com.networknt.server.ShutdownHookProvider: 9 | # - com.networknt.server.Test1ShutdownHook 10 | # - com.networknt.server.Test2ShutdownHook 11 | 12 | # Generator interface implementations 13 | - com.networknt.codegen.Generator: 14 | - com.networknt.codegen.rest.OpenApiLightGenerator 15 | - com.networknt.codegen.hybrid.HybridServerGenerator 16 | - com.networknt.codegen.hybrid.HybridServiceGenerator 17 | - com.networknt.codegen.graphql.GraphqlGenerator 18 | - com.networknt.codegen.rest.OpenApiKotlinGenerator 19 | - com.networknt.resources.PathResourceProvider: 20 | - com.networknt.codegen.handler.CodegenResourceProvider 21 | -------------------------------------------------------------------------------- /codegen-web/src/test/java/com/networknt/codegen/handler/TestServer.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen.handler; 2 | 3 | import com.networknt.server.Server; 4 | import com.networknt.server.ServerConfig; 5 | import org.junit.jupiter.api.extension.AfterAllCallback; 6 | import org.junit.jupiter.api.extension.BeforeAllCallback; 7 | import org.junit.jupiter.api.extension.ExtensionContext; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.util.concurrent.atomic.AtomicInteger; 12 | 13 | public class TestServer implements BeforeAllCallback, AfterAllCallback { 14 | static final Logger logger = LoggerFactory.getLogger(TestServer.class); 15 | 16 | private static final AtomicInteger refCount = new AtomicInteger(0); 17 | 18 | private static final TestServer instance = new TestServer(); 19 | 20 | private TestServer() { 21 | logger.info("TestServer is constructed!"); 22 | } 23 | 24 | public static TestServer getInstance () { 25 | return instance; 26 | } 27 | 28 | @Override 29 | public void beforeAll(ExtensionContext context) throws Exception { 30 | try { 31 | if (refCount.get() == 0) { 32 | Server.start(); 33 | } 34 | } 35 | finally { 36 | refCount.getAndIncrement(); 37 | } 38 | 39 | Runtime.getRuntime().addShutdownHook(new Thread(() -> clean())); 40 | } 41 | 42 | @Override 43 | public void afterAll(ExtensionContext context) throws Exception { 44 | clean(); 45 | } 46 | 47 | protected void clean() { 48 | refCount.getAndDecrement(); 49 | if (refCount.get() == 0) { 50 | Server.stop(); 51 | } 52 | 53 | 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /codegen-web/src/test/resources/config/client.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/codegen-web/src/test/resources/config/client.keystore -------------------------------------------------------------------------------- /codegen-web/src/test/resources/config/client.truststore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/codegen-web/src/test/resources/config/client.truststore -------------------------------------------------------------------------------- /codegen-web/src/test/resources/config/primary.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDmzCCAoOgAwIBAgIEHnAgtDANBgkqhkiG9w0BAQsFADB+MQswCQYDVQQGEwJDQTEQMA4GA1UE 3 | CBMHT250YXJpbzEUMBIGA1UEBxMLTWlzc2lzc2F1Z2ExJjAkBgNVBAoTHU5ldHdvcmsgTmV3IFRl 4 | Y2hub2xvZ2llcyBJbmMuMQwwCgYDVQQLEwNERVYxETAPBgNVBAMTCFN0ZXZlIEh1MB4XDTE2MDkw 5 | MTE2MTYxNVoXDTI2MDcxMTE2MTYxNVowfjELMAkGA1UEBhMCQ0ExEDAOBgNVBAgTB09udGFyaW8x 6 | FDASBgNVBAcTC01pc3Npc3NhdWdhMSYwJAYDVQQKEx1OZXR3b3JrIE5ldyBUZWNobm9sb2dpZXMg 7 | SW5jLjEMMAoGA1UECxMDREVWMREwDwYDVQQDEwhTdGV2ZSBIdTCCASIwDQYJKoZIhvcNAQEBBQAD 8 | ggEPADCCAQoCggEBALrlxMtDb60DogElf4TBz504tRheZimAE0dJL/Yby4nacJdqvc5l4z+WWpDf 9 | rI9krQ2Yi9yvhwAP+PrR6gWcIqWP4cpNE7XIAUDgr4CtyI7CptT/lpjtbkz4DGCMmaeDn0jqHqJt 10 | SeSZGfwVu5zAGm8n4sHatjnnxBI/iWzkTII3V4xv0WeK37szNTEd+ly2ag7n2IV5zNnYmqZTeMQm 11 | J2ENS+IwAG3ENtiVtrVTx/2bGtqutJjtdxsN58/cUG/guRyMT6OPI8Yi3ZzevdvRbxadyhEl/Kaw 12 | 6vJcdxmJI3tp4lx+p6sAxOWa7aapJe4JxutAQqzv0GKdVjoHKQ1wB60CAwEAAaMhMB8wHQYDVR0O 13 | BBYEFIPF9SBd06RWU1eDL73CKfy01lavMA0GCSqGSIb3DQEBCwUAA4IBAQAoaKZGOak3Upz/ordF 14 | slZoJuZlCu7jnKQEjYwHf3DNxcd1WmgFPtMcna6pW0VUxPIfidEA6VCMsGoK1RvshB0SjrRdCht6 15 | 5qPXs9kV3NW0WvMiwDSYZZ9HgaZ9efTe5E9Fzc7ltKrE43L6k8NJcaEEWEdpdjFbrAqH4I+j/Vro 16 | K3OhIo062fXjas5ipL4gF+3ECImjWzirQP8UiAfM0/36x7rtAu3btH/qI9hSyx39LBPPE5AsDJZ4 17 | dSMwNTW1gqmBAZIj+zQ/RD5dyWfPwON7Q+t96YbK6WBuYo0xy+I+PjcUgrWYWP3N24hlq8ZBIei+ 18 | BudoEVJlIlmS0aRCuP8n 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /codegen-web/src/test/resources/config/secondary.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDkzCCAnugAwIBAgIEUBGbJDANBgkqhkiG9w0BAQsFADB6MQswCQYDVQQGEwJDQTEQMA4GA1UE 3 | CBMHT250YXJpbzEQMA4GA1UEBxMHVG9yb250bzEmMCQGA1UEChMdTmV0d29yayBOZXcgVGVjaG5v 4 | bG9naWVzIEluYy4xDDAKBgNVBAsTA0FQSTERMA8GA1UEAxMIU3RldmUgSHUwHhcNMTYwOTIyMjI1 5 | OTIxWhcNMjYwODAxMjI1OTIxWjB6MQswCQYDVQQGEwJDQTEQMA4GA1UECBMHT250YXJpbzEQMA4G 6 | A1UEBxMHVG9yb250bzEmMCQGA1UEChMdTmV0d29yayBOZXcgVGVjaG5vbG9naWVzIEluYy4xDDAK 7 | BgNVBAsTA0FQSTERMA8GA1UEAxMIU3RldmUgSHUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK 8 | AoIBAQCqYfarFwug2DwpG/mmcW77OluaHVNsKEVJ/BptLp5suJAH/Z70SS5pwM4x2QwMOVO2ke8U 9 | rsAws8allxcuKXrbpVt4evpO1Ly2sFwqB1bjN3+VMp6wcT+tSjzYdVGFpQAYHpeA+OLuoHtQyfpB 10 | 0KCveTEe3KAG33zXDNfGKTGmupZ3ZfmBLINoey/X13rY71ITt67AY78VHUKb+D53MBahCcjJ9YpJ 11 | UHG+Sd3d4oeXiQcqJCBCVpD97awWARf8WYRIgU1xfCe06wQ3CzH3+GyfozLeu76Ni5PwE1tm7Dhg 12 | EDSSZo5khmzVzo4G0T2sOeshePc5weZBNRHdHlJA0L0fAgMBAAGjITAfMB0GA1UdDgQWBBT9rnek 13 | spnrFus5wTszjdzYgKll9TANBgkqhkiG9w0BAQsFAAOCAQEAT8udTfUGBgeWbN6ZAXRI64VsSJj5 14 | 1sNUN1GPDADLxZF6jArKU7LjBNXn9bG5VjJqlx8hQ1SNvi/t7FqBRCUt/3MxDmGZrVZqLY1kZ2e7 15 | x+5RykbspA8neEUtU8sOr/NP3O5jBjU77EVec9hNNT5zwKLevZNL/Q5mfHoc4GrIAolQvi/5fEqC 16 | 8OMdOIWS6sERgjaeI4tXxQtHDcMo5PeLW0/7t5sgEsadZ+pkdeEMVTmLfgf97bpNNI7KF5uEbYnQ 17 | NpwCT+NNC5ACmJmKidrfW23kml1C7vr7YzTevw9QuH/hN8l/Rh0fr+iPEVpgN6Zv00ymoKGmjuuW 18 | owVmdKg/0w== 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /codegen-web/src/test/resources/config/server.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/codegen-web/src/test/resources/config/server.keystore -------------------------------------------------------------------------------- /codegen-web/src/test/resources/config/server.truststore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/codegen-web/src/test/resources/config/server.truststore -------------------------------------------------------------------------------- /codegen-web/src/test/resources/config/values.yml: -------------------------------------------------------------------------------- 1 | # server.yml 2 | server.httpPort: 49587 3 | server.enableHttp: true 4 | server.httpsPort: 49588 5 | server.enableHttps: false 6 | server.enableHttp2: false 7 | 8 | # unified-security.yml 9 | unified-security.pathPrefixAuths: 10 | - prefix: /api/json 11 | basic: true 12 | jwt: true 13 | apikey: true 14 | unified-security.anonymousPrefixes: 15 | - /codegen 16 | -------------------------------------------------------------------------------- /codegen-web/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /codegen-web/view/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /codegen-web/view/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "view", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@material-ui/core": "^4.3.2", 7 | "@material-ui/icons": "^4.2.1", 8 | "react": "^16.9.0", 9 | "react-dom": "^16.9.0", 10 | "react-redux": "^7.1.0", 11 | "react-router": "^5.0.1", 12 | "react-router-dom": "^5.0.1", 13 | "react-schema-form": "^0.7.0", 14 | "react-scripts": "3.1.0", 15 | "recompose": "^0.30.0", 16 | "redux": "^4.0.4", 17 | "redux-logger": "^3.0.6", 18 | "redux-thunk": "^2.3.0" 19 | }, 20 | "scripts": { 21 | "start": "react-scripts start", 22 | "build": "react-scripts build", 23 | "test": "react-scripts test", 24 | "eject": "react-scripts eject" 25 | }, 26 | "eslintConfig": { 27 | "extends": "react-app" 28 | }, 29 | "browserslist": { 30 | "production": [ 31 | ">0.2%", 32 | "not dead", 33 | "not op_mini all" 34 | ], 35 | "development": [ 36 | "last 1 chrome version", 37 | "last 1 firefox version", 38 | "last 1 safari version" 39 | ] 40 | }, 41 | "proxy": "http://localhost:8080" 42 | } 43 | -------------------------------------------------------------------------------- /codegen-web/view/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/codegen-web/view/public/favicon.ico -------------------------------------------------------------------------------- /codegen-web/view/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /codegen-web/view/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /codegen-web/view/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | animation: App-logo-spin infinite 20s linear; 7 | height: 40vmin; 8 | pointer-events: none; 9 | } 10 | 11 | .App-header { 12 | background-color: #282c34; 13 | min-height: 100vh; 14 | display: flex; 15 | flex-direction: column; 16 | align-items: center; 17 | justify-content: center; 18 | font-size: calc(10px + 2vmin); 19 | color: white; 20 | } 21 | 22 | .App-link { 23 | color: #61dafb; 24 | } 25 | 26 | @keyframes App-logo-spin { 27 | from { 28 | transform: rotate(0deg); 29 | } 30 | to { 31 | transform: rotate(360deg); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /codegen-web/view/src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import {Switch, Route} from 'react-router-dom'; 3 | import { Router } from 'react-router'; 4 | import { createBrowserHistory } from 'history'; 5 | import Home from './components/Home'; 6 | import Document from './components/Document'; 7 | import GitHub from './components/GitHub'; 8 | import ResponsiveDrawer from './components/ResponsiveDrawer'; 9 | import Form from './components/Form'; 10 | 11 | export const history = createBrowserHistory(); 12 | 13 | class App extends Component { 14 | render() { 15 | return ( 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | ); 27 | } 28 | } 29 | 30 | export default App; 31 | -------------------------------------------------------------------------------- /codegen-web/view/src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div'); 7 | ReactDOM.render(, div); 8 | ReactDOM.unmountComponentAtNode(div); 9 | }); 10 | -------------------------------------------------------------------------------- /codegen-web/view/src/actions/index.js: -------------------------------------------------------------------------------- 1 | import {history} from '../App'; 2 | import { LOAD_MENU, SUBMIT_FORM_STARTED, SUBMIT_FORM_SUCCESS, SUBMIT_FORM_FAILURE } from './types'; 3 | 4 | export function loadMenu(host) { 5 | return { 6 | type: LOAD_MENU, 7 | payload: host 8 | } 9 | } 10 | 11 | export function submitForm(action) { 12 | return async (dispatch) => { 13 | dispatch({type: SUBMIT_FORM_STARTED}); 14 | const request = { 15 | method: 'POST', 16 | headers: { 17 | 'Accept': 'application/json', 18 | 'Content-Type': 'application/json', 19 | 'env_tag': action.data.release 20 | }, 21 | body: JSON.stringify(action) 22 | }; 23 | console.log(action.data.release); 24 | try { 25 | const response = await fetch('/codegen', request); 26 | const data = await response.blob(); 27 | const filename = 'light-project.zip'; 28 | if (typeof window.navigator.msSaveBlob !== 'undefined') { 29 | window.navigator.msSaveBlob(data, filename); 30 | } else { 31 | const url = window.URL.createObjectURL(data); 32 | const link = document.createElement('a'); 33 | link.href = url; 34 | link.setAttribute('download', filename); 35 | document.body.appendChild(link); 36 | link.click(); 37 | } 38 | //console.log("data", data); 39 | dispatch({ type: SUBMIT_FORM_SUCCESS, payload: data }); 40 | history.push(action.success); 41 | } catch(e) { 42 | //console.log("error " + e.toString()); 43 | dispatch({ type: SUBMIT_FORM_FAILURE, error: e.toString()}) 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /codegen-web/view/src/actions/types.js: -------------------------------------------------------------------------------- 1 | export const LOAD_MENU = 'load_menu'; 2 | export const SUBMIT_FORM_STARTED = 'SUBMIT_FORM_STARTED'; 3 | export const SUBMIT_FORM_SUCCESS = 'SUBMIT_FORM_SUCCESS'; 4 | export const SUBMIT_FORM_FAILURE = 'SUBMIT_FORM_FAILURE'; 5 | -------------------------------------------------------------------------------- /codegen-web/view/src/components/Document.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import {withStyles} from "@material-ui/core"; 3 | 4 | const styles = theme => ({ 5 | root: { 6 | display: 'flex', 7 | flexWrap: 'wrap', 8 | }, 9 | pre: { 10 | 'white-space': 'pre-wrap', 11 | }, 12 | }); 13 | 14 | class Document extends Component { 15 | render() { 16 | const { classes } = this.props; 17 | return ( 18 |
19 |
20 |                     Light-codegen is used to scaffold a new project with a specification file and a config file.
21 |                 
22 |
23 |                     For document, please visit reference.
24 |                 
25 |
26 |                     To learn how to use each generator, please visit tutorial.
27 |                 
28 |
29 | ) 30 | } 31 | } 32 | 33 | export default withStyles(styles)(Document); 34 | -------------------------------------------------------------------------------- /codegen-web/view/src/components/GitHub.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import {withStyles} from "@material-ui/core"; 3 | 4 | const styles = theme => ({ 5 | root: { 6 | display: 'flex', 7 | flexWrap: 'wrap', 8 | }, 9 | pre: { 10 | 'white-space': 'pre-wrap', 11 | }, 12 | }); 13 | 14 | class GitHub extends Component { 15 | render() { 16 | const { classes } = this.props; 17 | return ( 18 |
19 |
20 |                     Light-codegen is an open source project on GitHub.com
21 |                 
22 |
23 |                     For the light-codegen project, please visit light-codegen.
24 |                 
25 |
26 |                     For the services to support this site, please visit codegen-web.
27 |                 
28 |
29 |                     For the react single page application, please visit view.
30 |                 
31 |
32 | ) 33 | } 34 | } 35 | 36 | export default withStyles(styles)(GitHub); 37 | -------------------------------------------------------------------------------- /codegen-web/view/src/components/Home.js: -------------------------------------------------------------------------------- 1 | import React, {Component} from 'react'; 2 | import {withStyles} from "@material-ui/core"; 3 | 4 | const styles = theme => ({ 5 | root: { 6 | display: 'flex', 7 | flexWrap: 'wrap', 8 | }, 9 | pre: { 10 | 'white-space': 'pre-wrap', 11 | }, 12 | }); 13 | 14 | class Home extends Component { 15 | render() { 16 | const { classes } = this.props; 17 | return ( 18 |
19 |
20 |                     Light-codegen can be used to generate a single project or multiple projects in a folder. Please select from the generator menu.
21 |                 
22 |
23 | ) 24 | } 25 | } 26 | 27 | export default withStyles(styles)(Home); 28 | -------------------------------------------------------------------------------- /codegen-web/view/src/components/ListItem.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | class ListItem extends Component { 5 | render() { 6 | const { primaryText, style } = this.props; 7 | const { onTouchTap, leftIcon } = this.props; 8 | 9 | const styles = { 10 | root: { 11 | cursor: 'pointer', 12 | transition: 'all 0.25s ease-in-out', 13 | }, 14 | primaryText: { 15 | lineHeight: '32px', 16 | }, 17 | }; 18 | 19 | return ( 20 |
21 | {leftIcon} 22 | {primaryText} 23 |
24 | ); 25 | } 26 | } 27 | 28 | ListItem.propTypes = { 29 | primaryText: PropTypes.string.isRequired, 30 | style: PropTypes.object.isRequired, 31 | leftIcon: PropTypes.element, 32 | rightIcon: PropTypes.element, 33 | to: PropTypes.string, 34 | onTouchTap: PropTypes.func, 35 | }; 36 | 37 | export default ListItem; 38 | -------------------------------------------------------------------------------- /codegen-web/view/src/data/ListItems.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "depth":0, 4 | "children":[ 5 | 6 | ], 7 | "_styles":{ 8 | "root":{ 9 | "paddingLeft":-16, 10 | "backgroundColor":null, 11 | "height":"48px", 12 | "cursor":"pointer", 13 | "color":"rgba(0,0,0,0.87)", 14 | "overflow":"hidden", 15 | "transform":"translateZ(0)" 16 | } 17 | }, 18 | "_shouldRender":false 19 | }, 20 | { 21 | "title":"Generator", 22 | "depth":1, 23 | "parentIndex":0, 24 | "children":[ 25 | 2, 26 | 5 27 | ], 28 | "disabled":false 29 | }, 30 | { 31 | "title":"Single Project", 32 | "depth":2, 33 | "parentIndex":1, 34 | "disabled":false, 35 | "link":"/form/codeGenSingleForm" 36 | }, 37 | { 38 | "title":"Multiple Project", 39 | "depth":2, 40 | "parentIndex":1, 41 | "disabled":false, 42 | "link":"/form/codeGenMultipleForm" 43 | }, 44 | { 45 | "title":"Document", 46 | "depth":1, 47 | "parentIndex":0, 48 | "disabled":false, 49 | "link":"/document" 50 | }, 51 | { 52 | "title":"GitHub", 53 | "depth":1, 54 | "parentIndex":0, 55 | "disabled":false, 56 | "link":"/github" 57 | }, 58 | { 59 | "title":"About", 60 | "depth":1, 61 | "parentIndex":0, 62 | "disabled":false, 63 | "link":"/about" 64 | } 65 | ] 66 | -------------------------------------------------------------------------------- /codegen-web/view/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 5 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 6 | sans-serif; 7 | -webkit-font-smoothing: antialiased; 8 | -moz-osx-font-smoothing: grayscale; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 13 | monospace; 14 | } 15 | -------------------------------------------------------------------------------- /codegen-web/view/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles'; 4 | import { Provider } from 'react-redux'; 5 | import { createStore, applyMiddleware } from 'redux'; 6 | import rootReducer from './reducers'; 7 | import thunk from 'redux-thunk'; 8 | import logger from 'redux-logger'; 9 | import './index.css'; 10 | import App from './App'; 11 | import * as serviceWorker from './serviceWorker'; 12 | 13 | const theme = createMuiTheme({ 14 | typography: { 15 | useNextVariants: true, 16 | }, 17 | }); 18 | 19 | const store = createStore(rootReducer, applyMiddleware(thunk, logger)); 20 | 21 | ReactDOM.render( 22 | 23 | 24 | 25 | 26 | , 27 | document.getElementById('root') 28 | ); 29 | 30 | // If you want your app to work offline and load faster, you can change 31 | // unregister() to register() below. Note this comes with some pitfalls. 32 | // Learn more about service workers: https://bit.ly/CRA-PWA 33 | serviceWorker.unregister(); 34 | -------------------------------------------------------------------------------- /codegen-web/view/src/reducers/FormReducer.js: -------------------------------------------------------------------------------- 1 | import {SUBMIT_FORM_STARTED, SUBMIT_FORM_FAILURE, SUBMIT_FORM_SUCCESS} from "../actions/types"; 2 | 3 | const initialState = {}; 4 | export default (state = initialState, action) => { 5 | switch (action.type) { 6 | case SUBMIT_FORM_SUCCESS: 7 | return { 8 | ...state, 9 | fetching: false, 10 | result: action.payload 11 | }; 12 | case SUBMIT_FORM_FAILURE: 13 | return { 14 | ...state, 15 | fetching: false, 16 | error: action.payload 17 | }; 18 | case SUBMIT_FORM_STARTED: 19 | return { 20 | ...state, 21 | fetching: true 22 | }; 23 | default: 24 | return state; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /codegen-web/view/src/reducers/index.js: -------------------------------------------------------------------------------- 1 | import { combineReducers } from 'redux'; 2 | import menuReducer from './menu'; 3 | import formReducer from './FormReducer'; 4 | 5 | export default combineReducers({ 6 | menu: menuReducer, 7 | form: formReducer 8 | }); 9 | -------------------------------------------------------------------------------- /codegen-web/view/src/reducers/menu.js: -------------------------------------------------------------------------------- 1 | export default function(state = [], action) { 2 | switch (action.type) { 3 | default: 4 | return state; 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "api-customers", 3 | "version": "1.0.0", 4 | "groupId": "com.example.api", 5 | "artifactId": "api-customers", 6 | "rootPackage": "com.example.customers", 7 | "handlerPackage":"com.example.customers.handler", 8 | "modelPackage":"com.example.customers.model", 9 | "overwriteHandler": false, 10 | "overwriteHandlerTest": false, 11 | "overwriteModel": true, 12 | "httpPort": 8080, 13 | "enableHttp": false, 14 | "httpsPort": 9443, 15 | "enableHttps": true, 16 | "enableRegistry": false, 17 | "eclipseIDE": false, 18 | "supportDb": false, 19 | "dbInfo": { 20 | "name": "mysql", 21 | "driverClassName": "com.mysql.jdbc.Driver", 22 | "jdbcUrl": "jdbc:mysql://mysqldb:3306/oauth2?useSSL=false", 23 | "username": "root", 24 | "password": "my-secret-pw" 25 | }, 26 | "supportH2ForTest": false, 27 | "supportClient": true, 28 | "dockerOrganization": "networknt", 29 | "generateEnvVars": { 30 | "generate": true, 31 | "skipArray": true, 32 | "skipMap": true, 33 | "exclude": [ 34 | "service.yml", 35 | "handler.yml", 36 | "values.yml" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/binaries/client.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-graphql-4j/src/main/resources/binaries/client.keystore -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/binaries/client.truststore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-graphql-4j/src/main/resources/binaries/client.truststore -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/binaries/server.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-graphql-4j/src/main/resources/binaries/server.keystore -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/binaries/server.truststore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-graphql-4j/src/main/resources/binaries/server.truststore -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/light-graphql-4j.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "definitions": {}, 4 | "id": "http://example.com/example.json", 5 | "properties": { 6 | "artifactId": { 7 | "id": "/properties/artifactId", 8 | "type": "string" 9 | }, 10 | "groupId": { 11 | "id": "/properties/groupId", 12 | "type": "string" 13 | }, 14 | "handlerPackage": { 15 | "id": "/properties/handlerPackage", 16 | "type": "string" 17 | }, 18 | "modelPackage": { 19 | "id": "/properties/modelPackage", 20 | "type": "string" 21 | }, 22 | "name": { 23 | "id": "/properties/name", 24 | "type": "string" 25 | }, 26 | "overwriteHandler": { 27 | "id": "/properties/overwriteHandler", 28 | "type": "boolean" 29 | }, 30 | "overwriteHandlerTest": { 31 | "id": "/properties/overwriteHandlerTest", 32 | "type": "boolean" 33 | }, 34 | "rootPackage": { 35 | "id": "/properties/rootPackage", 36 | "type": "string" 37 | }, 38 | "schemaClass": { 39 | "id": "/properties/schemaClass", 40 | "type": "string" 41 | }, 42 | "schemaPackage": { 43 | "id": "/properties/schemaPackage", 44 | "type": "string" 45 | }, 46 | "version": { 47 | "id": "/properties/version", 48 | "type": "string" 49 | } 50 | }, 51 | "type": "object" 52 | } 53 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/maven/mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-graphql-4j/src/main/resources/maven/mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/maven/mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar 3 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/README.md.rocker.raw: -------------------------------------------------------------------------------- 1 | # Swagger Light Java Server 2 | 3 | ## Start server 4 | 5 | Run with 6 | 7 | ``` 8 | mvn package exec:exec 9 | `` 10 | 11 | ## Test 12 | 13 | By default, all endpoints are protected by OAuth jwt token verifier. It can be turned off with config change through for development. 14 | 15 | 16 | In order to access the server, there is a long lived token below issued by my 17 | oauth2 server [light-oauth2](https://github.com/networknt/light-oauth2) 18 | 19 | ``` 20 | Bearer eyJraWQiOiIxMDAiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ1cm46Y29tOm5ldHdvcmtudDpvYXV0aDI6djEiLCJhdWQiOiJ1cm46Y29tLm5ldHdvcmtudCIsImV4cCI6MTc5MDAzNTcwOSwianRpIjoiSTJnSmdBSHN6NzJEV2JWdUFMdUU2QSIsImlhdCI6MTQ3NDY3NTcwOSwibmJmIjoxNDc0Njc1NTg5LCJ2ZXJzaW9uIjoiMS4wIiwidXNlcl9pZCI6InN0ZXZlIiwidXNlcl90eXBlIjoiRU1QTE9ZRUUiLCJjbGllbnRfaWQiOiJmN2Q0MjM0OC1jNjQ3LTRlZmItYTUyZC00YzU3ODc0MjFlNzIiLCJzY29wZSI6WyJ3cml0ZTpwZXRzIiwicmVhZDpwZXRzIl19.mue6eh70kGS3Nt2BCYz7ViqwO7lh_4JSFwcHYdJMY6VfgKTHhsIGKq2uEDt3zwT56JFAePwAxENMGUTGvgceVneQzyfQsJeVGbqw55E9IfM_uSM-YcHwTfR7eSLExN4pbqzVDI353sSOvXxA98ZtJlUZKgXNE1Ngun3XFORCRIB_eH8B0FY_nT_D1Dq2WJrR-re-fbR6_va95vwoUdCofLRa4IpDfXXx19ZlAtfiVO44nw6CS8O87eGfAm7rCMZIzkWlCOFWjNHnCeRsh7CVdEH34LF-B48beiG5lM7h4N12-EME8_VDefgMjZ8eqs1ICvJMxdIut58oYbdnkwTjkA 21 | ``` 22 | 23 | Postman is the best tool to test REST APIs 24 | 25 | Add "Authorization" header with value as above token and a dummy message will return from the generated stub. 26 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/appStatusYml.rocker.raw: -------------------------------------------------------------------------------- 1 | # Put your application specific error code into this file instead of status.yml 2 | # This file will be merge into the status.yml during the server startup. 3 | # Please allocate the range for the application error codes within your organization 4 | # to ensure no reused for an error code across the organization for tracing. 5 | 6 | # 20000-29999 common error codes within your business domain. 7 | # It is highly recommended to have common error codes shared within your organization 8 | # or your line of business and put them into the externalized status.yml file. 9 | 10 | # 30000-99999 customize error code that cannot be found in common range. 11 | # Only use this section if you cannot make your error code into 20000-29999 range on time. 12 | # In this case, the error code defined here will be merged to the status.yml during startup. 13 | # To ensure there is no reuse of error code, this application will use the range 30000-31000. 14 | ERR30000: 15 | statusCode: 400 16 | code: ERR30000 17 | message: FIRST_ERROR_IN_APP 18 | description: This is is the first error in this example application. 19 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/buildSh.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config, String serviceId) 3 | #!/bin/bash 4 | 5 | set -ex 6 | 7 | VERSION=$1 8 | IMAGE_NAME="@config.get("dockerOrganization").textValue()/@serviceId" 9 | 10 | showHelp() { 11 | echo " " 12 | echo "Error: $1" 13 | echo " " 14 | echo " build.sh [VERSION]" 15 | echo " " 16 | echo " where [VERSION] version of the docker image that you want to publish (example: 0.0.1)" 17 | echo " " 18 | echo " example: ./build.sh 0.0.1" 19 | echo " " 20 | } 21 | 22 | build() { 23 | echo "Building ..." 24 | @if(config.get("buildMaven").booleanValue()){ 25 | mvn clean install -Prelease 26 | }else{ 27 | ./gradlew clean build 28 | } 29 | echo "Successfully built!" 30 | } 31 | 32 | cleanup() { 33 | if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" != "" ]]; then 34 | echo "Removing old $IMAGE_NAME images" 35 | docker images | grep $IMAGE_NAME | awk '{print $3}' | xargs docker rmi -f 36 | echo "Cleanup completed!" 37 | fi 38 | } 39 | 40 | publish() { 41 | echo "Building Docker image with version $VERSION" 42 | docker build -t $IMAGE_NAME:$VERSION -t $IMAGE_NAME:latest -f ./docker/Dockerfile . --no-cache=true 43 | docker build -t $IMAGE_NAME:$VERSION-slim -f ./docker/Dockerfile-Slim . --no-cache=true 44 | echo "Images built with version $VERSION" 45 | echo "Pushing image to DockerHub" 46 | docker push $IMAGE_NAME -a 47 | echo "Image successfully published!" 48 | } 49 | 50 | if [ -z $VERSION ]; then 51 | showHelp "[VERSION] parameter is missing" 52 | exit 53 | fi 54 | 55 | build; 56 | cleanup; 57 | publish; 58 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/classpath.rocker.raw: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/dockerfile.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config, String expose) 3 | FROM azul/zulu-openjdk-alpine:11 as packager 4 | 5 | RUN { \ 6 | java --version ; \ 7 | echo "jlink version:" && \ 8 | $JAVA_HOME/bin/jlink --version ; \ 9 | } 10 | 11 | ENV JAVA_MINIMAL=/opt/jre 12 | 13 | # build modules distribution 14 | RUN $JAVA_HOME/bin/jlink \ 15 | --verbose \ 16 | --add-modules \ 17 | java.base,java.sql,java.naming,java.desktop,java.xml,jdk.crypto.cryptoki,jdk.crypto.ec,jdk.unsupported,java.management,java.security.jgss,java.net.http \ 18 | --compress 2 \ 19 | --strip-debug \ 20 | --no-header-files \ 21 | --no-man-pages \ 22 | --output "$JAVA_MINIMAL" 23 | 24 | # Second stage, add only our minimal "JRE" distr and our app 25 | FROM alpine 26 | 27 | ENV JAVA_MINIMAL=/opt/jre 28 | ENV PATH="$PATH:$JAVA_MINIMAL/bin" 29 | 30 | COPY --from=packager "$JAVA_MINIMAL" "$JAVA_MINIMAL" 31 | @if(config.get("buildMaven").booleanValue()){ 32 | @with (name = config.get("artifactId").textValue() + "-" + config.get("version").textValue() + ".jar") {COPY /target/@name server.jar} 33 | }else{ 34 | @with (name = config.get("artifactId").textValue() + ".jar") {COPY /build/libs/@name server.jar} 35 | } 36 | CMD ["/bin/sh","-c","exec java -Dlight-4j-config-dir=/config -Dlogback.configurationFile=/config/logback.xml -jar /server.jar"] 37 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/dockerfileslim.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config, String expose) 3 | FROM openjdk:11.0.3-slim 4 | @if(config.get("buildMaven").booleanValue()){ 5 | @with (name = config.get("artifactId").textValue() + "-" + config.get("version").textValue() + ".jar") {COPY /target/@name server.jar} 6 | }else{ 7 | @with (name = config.get("artifactId").textValue() + ".jar") {COPY /build/libs/@name server.jar} 8 | } 9 | CMD ["/bin/sh","-c","exec java -Dlight-4j-config-dir=/config -Dlogback.configurationFile=/config/logback.xml -jar /server.jar"] 10 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/gitignore.rocker.raw: -------------------------------------------------------------------------------- 1 | target/ 2 | bower_components/ 3 | node_modules/ 4 | dist/ 5 | .idea/ 6 | .tmp/ 7 | .project 8 | .classpath 9 | .settings 10 | .metadata/ 11 | *.iml 12 | *.log 13 | *.tmp 14 | *.zip 15 | *.bak 16 | dependency-reduced-pom.xml 17 | 18 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 19 | hs_err_pid* 20 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/handlerProvider.rocker.raw: -------------------------------------------------------------------------------- 1 | @import java.util.Map 2 | @import java.util.List 3 | @args (String rootPackage, String handlerPackage, List> items) 4 | package @rootPackage; 5 | 6 | import com.networknt.config.Config; 7 | import com.networknt.handler.HandlerProvider; 8 | import io.undertow.Handlers; 9 | import io.undertow.server.HttpHandler; 10 | import io.undertow.server.HttpServerExchange; 11 | import io.undertow.util.Methods; 12 | import com.networknt.info.ServerInfoGetHandler; 13 | import @with (p = handlerPackage + ".*;") {@p} 14 | 15 | public class PathHandlerProvider implements HandlerProvider { 16 | @@Override 17 | public HttpHandler getHandler() { 18 | return Handlers.routing() 19 | @for(item: items) { 20 | .add(Methods.@item.get("method"), "@item.get("path")", new @item.get("handlerName")()) 21 | } 22 | ; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/primaryCrt.rocker.raw: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDmzCCAoOgAwIBAgIEHnAgtDANBgkqhkiG9w0BAQsFADB+MQswCQYDVQQGEwJDQTEQMA4GA1UE 3 | CBMHT250YXJpbzEUMBIGA1UEBxMLTWlzc2lzc2F1Z2ExJjAkBgNVBAoTHU5ldHdvcmsgTmV3IFRl 4 | Y2hub2xvZ2llcyBJbmMuMQwwCgYDVQQLEwNERVYxETAPBgNVBAMTCFN0ZXZlIEh1MB4XDTE2MDkw 5 | MTE2MTYxNVoXDTI2MDcxMTE2MTYxNVowfjELMAkGA1UEBhMCQ0ExEDAOBgNVBAgTB09udGFyaW8x 6 | FDASBgNVBAcTC01pc3Npc3NhdWdhMSYwJAYDVQQKEx1OZXR3b3JrIE5ldyBUZWNobm9sb2dpZXMg 7 | SW5jLjEMMAoGA1UECxMDREVWMREwDwYDVQQDEwhTdGV2ZSBIdTCCASIwDQYJKoZIhvcNAQEBBQAD 8 | ggEPADCCAQoCggEBALrlxMtDb60DogElf4TBz504tRheZimAE0dJL/Yby4nacJdqvc5l4z+WWpDf 9 | rI9krQ2Yi9yvhwAP+PrR6gWcIqWP4cpNE7XIAUDgr4CtyI7CptT/lpjtbkz4DGCMmaeDn0jqHqJt 10 | SeSZGfwVu5zAGm8n4sHatjnnxBI/iWzkTII3V4xv0WeK37szNTEd+ly2ag7n2IV5zNnYmqZTeMQm 11 | J2ENS+IwAG3ENtiVtrVTx/2bGtqutJjtdxsN58/cUG/guRyMT6OPI8Yi3ZzevdvRbxadyhEl/Kaw 12 | 6vJcdxmJI3tp4lx+p6sAxOWa7aapJe4JxutAQqzv0GKdVjoHKQ1wB60CAwEAAaMhMB8wHQYDVR0O 13 | BBYEFIPF9SBd06RWU1eDL73CKfy01lavMA0GCSqGSIb3DQEBCwUAA4IBAQAoaKZGOak3Upz/ordF 14 | slZoJuZlCu7jnKQEjYwHf3DNxcd1WmgFPtMcna6pW0VUxPIfidEA6VCMsGoK1RvshB0SjrRdCht6 15 | 5qPXs9kV3NW0WvMiwDSYZZ9HgaZ9efTe5E9Fzc7ltKrE43L6k8NJcaEEWEdpdjFbrAqH4I+j/Vro 16 | K3OhIo062fXjas5ipL4gF+3ECImjWzirQP8UiAfM0/36x7rtAu3btH/qI9hSyx39LBPPE5AsDJZ4 17 | dSMwNTW1gqmBAZIj+zQ/RD5dyWfPwON7Q+t96YbK6WBuYo0xy+I+PjcUgrWYWP3N24hlq8ZBIei+ 18 | BudoEVJlIlmS0aRCuP8n 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/project.rocker.raw: -------------------------------------------------------------------------------- 1 | 2 | 3 | light-graphql-4j 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/schemaClass.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String schemaPackage, String schemaClass) 2 | package @schemaPackage; 3 | 4 | import com.networknt.graphql.router.SchemaProvider; 5 | import graphql.schema.GraphQLSchema; 6 | import graphql.schema.idl.RuntimeWiring; 7 | import graphql.schema.idl.SchemaGenerator; 8 | import graphql.schema.idl.SchemaParser; 9 | import graphql.schema.idl.TypeDefinitionRegistry; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.io.InputStreamReader; 16 | 17 | /** 18 | * Created by steve on 25/03/17. 19 | */ 20 | public class @schemaClass implements SchemaProvider { 21 | private static Logger logger = LoggerFactory.getLogger(SchemaProvider.class); 22 | private static String schemaName = "schema.graphqls"; 23 | @@Override 24 | public GraphQLSchema getSchema() { 25 | SchemaParser schemaParser = new SchemaParser(); 26 | TypeDefinitionRegistry typeRegistry = null; 27 | 28 | try(InputStream is = getClass().getClassLoader().getResourceAsStream(schemaName)) { 29 | typeRegistry = schemaParser.parse(new InputStreamReader(is)); 30 | } catch (IOException e) { 31 | logger.error("IOException:", e); 32 | } 33 | 34 | RuntimeWiring wiring = RuntimeWiring.newRuntimeWiring() 35 | // put other wiring logic here. 36 | .build(); 37 | 38 | return new SchemaGenerator().makeExecutableSchema(typeRegistry, wiring); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/schemaClassExample.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String schemaPackage, String schemaClass) 2 | package @schemaPackage; 3 | 4 | import com.networknt.graphql.router.SchemaProvider; 5 | import graphql.schema.GraphQLObjectType; 6 | import graphql.schema.GraphQLSchema; 7 | 8 | import static graphql.Scalars.GraphQLString; 9 | import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition; 10 | import static graphql.schema.GraphQLObjectType.newObject; 11 | 12 | /** 13 | * Created by steve on 25/03/17. 14 | */ 15 | public class @schemaClass implements SchemaProvider { 16 | @@Override 17 | public GraphQLSchema getSchema() { 18 | GraphQLObjectType queryType = newObject() 19 | .name("helloWorldQuery") 20 | .field(newFieldDefinition() 21 | .type(GraphQLString) 22 | .name("hello") 23 | .staticValue("world")) 24 | .build(); 25 | 26 | return GraphQLSchema.newSchema() 27 | .query(queryType) 28 | .build(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/secondaryCrt.rocker.raw: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDkzCCAnugAwIBAgIEUBGbJDANBgkqhkiG9w0BAQsFADB6MQswCQYDVQQGEwJDQTEQMA4GA1UE 3 | CBMHT250YXJpbzEQMA4GA1UEBxMHVG9yb250bzEmMCQGA1UEChMdTmV0d29yayBOZXcgVGVjaG5v 4 | bG9naWVzIEluYy4xDDAKBgNVBAsTA0FQSTERMA8GA1UEAxMIU3RldmUgSHUwHhcNMTYwOTIyMjI1 5 | OTIxWhcNMjYwODAxMjI1OTIxWjB6MQswCQYDVQQGEwJDQTEQMA4GA1UECBMHT250YXJpbzEQMA4G 6 | A1UEBxMHVG9yb250bzEmMCQGA1UEChMdTmV0d29yayBOZXcgVGVjaG5vbG9naWVzIEluYy4xDDAK 7 | BgNVBAsTA0FQSTERMA8GA1UEAxMIU3RldmUgSHUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK 8 | AoIBAQCqYfarFwug2DwpG/mmcW77OluaHVNsKEVJ/BptLp5suJAH/Z70SS5pwM4x2QwMOVO2ke8U 9 | rsAws8allxcuKXrbpVt4evpO1Ly2sFwqB1bjN3+VMp6wcT+tSjzYdVGFpQAYHpeA+OLuoHtQyfpB 10 | 0KCveTEe3KAG33zXDNfGKTGmupZ3ZfmBLINoey/X13rY71ITt67AY78VHUKb+D53MBahCcjJ9YpJ 11 | UHG+Sd3d4oeXiQcqJCBCVpD97awWARf8WYRIgU1xfCe06wQ3CzH3+GyfozLeu76Ni5PwE1tm7Dhg 12 | EDSSZo5khmzVzo4G0T2sOeshePc5weZBNRHdHlJA0L0fAgMBAAGjITAfMB0GA1UdDgQWBBT9rnek 13 | spnrFus5wTszjdzYgKll9TANBgkqhkiG9w0BAQsFAAOCAQEAT8udTfUGBgeWbN6ZAXRI64VsSJj5 14 | 1sNUN1GPDADLxZF6jArKU7LjBNXn9bG5VjJqlx8hQ1SNvi/t7FqBRCUt/3MxDmGZrVZqLY1kZ2e7 15 | x+5RykbspA8neEUtU8sOr/NP3O5jBjU77EVec9hNNT5zwKLevZNL/Q5mfHoc4GrIAolQvi/5fEqC 16 | 8OMdOIWS6sERgjaeI4tXxQtHDcMo5PeLW0/7t5sgEsadZ+pkdeEMVTmLfgf97bpNNI7KF5uEbYnQ 17 | NpwCT+NNC5ACmJmKidrfW23kml1C7vr7YzTevw9QuH/hN8l/Rh0fr+iPEVpgN6Zv00ymoKGmjuuW 18 | owVmdKg/0w== 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/securityYml.rocker.raw: -------------------------------------------------------------------------------- 1 | # Security configuration for graphql-security in light-graphql-4j. It is a specific config 2 | # for GraphQL framework security. It is introduced to support multiple frameworks in the 3 | # same server instance. If this file cannot be found, the generic security.yml will be 4 | # loaded for backward compatibility. 5 | --- 6 | # Enable JWT verification flag. 7 | enableVerifyJwt: false 8 | 9 | # Enable JWT scope verification. Only valid when enableVerifyJwt is true. 10 | enableVerifyScope: true 11 | 12 | # User for test only. should be always be false on official environment. 13 | enableMockJwt: false 14 | 15 | # JWT signature public certificates. kid and certificate path mappings. 16 | jwt: 17 | certificate: 18 | '100': primary.crt 19 | '101': secondary.crt 20 | clockSkewInSeconds: 60 21 | # Key distribution server standard: JsonWebKeySet for other OAuth 2.0 provider| X509Certificate for light-oauth2 22 | keyResolver: X509Certificate 23 | 24 | # Enable or disable JWT token logging 25 | logJwtToken: true 26 | 27 | # Enable or disable client_id, user_id and scope logging. 28 | logClientUserScope: false 29 | 30 | # Enable JWT token cache to speed up verification. This will only verify expired time 31 | # and skip the signature verification as it takes more CPU power and long time. 32 | enableJwtCache: true 33 | 34 | # If you are using light-oauth2, then you don't need to have oauth subfolder for public 35 | # key certificate to verify JWT token, the key will be retrieved from key endpoint once 36 | # the first token is arrived. Default to false for dev environment without oauth2 server 37 | # or official environment that use other OAuth 2.0 providers. 38 | bootstrapFromKeyService: false 39 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/serviceYml.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | # Singleton service factory configuration/IoC injection 4 | singletons: 5 | # HandlerProvider implementation 6 | #- com.networknt.handler.HandlerProvider: 7 | # - com.networknt.graphql.router.GraphqlRouter 8 | # StartupHookProvider implementations, there are one to many and they are called in the same sequence defined. 9 | # - com.networknt.server.StartupHookProvider: 10 | # If you are using mask module to remove sensitive info before logging, uncomment the following line. 11 | # - com.networknt.server.JsonPathStartupHookProvider 12 | # - com.networknt.server.Test1StartupHook 13 | # - com.networknt.server.Test1StartupHook 14 | # ShutdownHookProvider implementations, there are one to many and they are called in the same sequence defined. 15 | # - com.networknt.server.ShutdownHookProvider: 16 | # - com.networknt.server.Test1ShutdownHook 17 | # GraphQL schema provider interface implementation 18 | - com.networknt.graphql.router.SchemaProvider: 19 | - @with(schemaPackage = config.get("schemaPackage").textValue() + "." + config.get("schemaClass").textValue()) {@schemaPackage} 20 | @if(config.get("supportDb").booleanValue()){ 21 | @with (driverClassName = config.path("dbInfo").path("driverClassName").textValue(), jdbcUrl=config.path("dbInfo").path("jdbcUrl").textValue(), username=config.path("dbInfo").path("username").textValue(), password=config.path("dbInfo").path("password").textValue()) { 22 | - javax.sql.DataSource: 23 | - com.zaxxer.hikari.HikariDataSource: 24 | DriverClassName: @driverClassName 25 | jdbcUrl: @jdbcUrl 26 | username: @username 27 | password: @password 28 | maximumPoolSize: 10 29 | useServerPrepStmts: true 30 | cachePrepStmts: true 31 | cacheCallableStmts: true 32 | prepStmtCacheSize: 10 33 | prepStmtCacheSqlLimit: 2048 34 | connectionTimeout: 2000 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/testServer.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String handlerPackage) 2 | package @handlerPackage; 3 | 4 | import org.junit.rules.ExternalResource; 5 | import org.slf4j.Logger; 6 | import org.slf4j.LoggerFactory; 7 | import java.util.concurrent.atomic.AtomicInteger; 8 | 9 | import com.networknt.server.Server; 10 | import com.networknt.server.ServerConfig; 11 | 12 | public class TestServer extends ExternalResource { 13 | static final Logger logger = LoggerFactory.getLogger(TestServer.class); 14 | 15 | private static final AtomicInteger refCount = new AtomicInteger(0); 16 | 17 | private static final TestServer instance = new TestServer(); 18 | 19 | private TestServer() { 20 | logger.info("TestServer is constructed!"); 21 | } 22 | 23 | public static TestServer getInstance () { 24 | return instance; 25 | } 26 | 27 | @@Override 28 | protected void before() { 29 | try { 30 | if (refCount.get() == 0) { 31 | Server.init(); 32 | logger.info("TestServer is initialized!"); 33 | } 34 | } 35 | finally { 36 | refCount.getAndIncrement(); 37 | } 38 | } 39 | 40 | @@Override 41 | protected void after() { 42 | refCount.getAndDecrement(); 43 | if (refCount.get() == 0) { 44 | Server.stop(); 45 | logger.info("TestServer is stopped!"); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /light-graphql-4j/src/main/resources/templates/graphql/validatorYml.rocker.raw: -------------------------------------------------------------------------------- 1 | # This is specific GraphQL validator configuration file. It is introduced to support multiple 2 | # frameworks in the same server instance and it is recommended. If this file cannot be found, 3 | # the generic validator.yml will be loaded as a fallback. 4 | --- 5 | # Enable request validation against the specification 6 | enabled: true 7 | # Log error message if validation error occurs 8 | logError: true 9 | -------------------------------------------------------------------------------- /light-graphql-4j/src/test/resources/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "starwars", 3 | "version": "1.0.1", 4 | "groupId": "com.networknt", 5 | "artifactId": "starwars", 6 | "schemaPackage": "com.networknt.starwars.schema", 7 | "schemaClass": "StarWarsSchema", 8 | "overwriteSchemaClass": true, 9 | "useLightProxy": false, 10 | "httpPort": 8080, 11 | "enableHttp": true, 12 | "httpsPort": 8443, 13 | "enableHttps": false, 14 | "enableHttp2": false, 15 | "enableRegistry": false, 16 | "supportDb": true, 17 | "eclipseIDE": false, 18 | "dbInfo": { 19 | "name": "mysql", 20 | "driverClassName": "com.mysql.jdbc.Driver", 21 | "jdbcUrl": "jdbc:mysql://mysqldb:3306/oauth2?useSSL=false", 22 | "username": "root", 23 | "password": "my-secret-pw" 24 | }, 25 | "supportH2ForTest": false, 26 | "supportClient": false, 27 | "buildMaven": true, 28 | "dockerOrganization": "networknt" 29 | } 30 | -------------------------------------------------------------------------------- /light-graphql-4j/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /light-graphql-4j/src/test/resources/schema.graphqls: -------------------------------------------------------------------------------- 1 | schema { 2 | query: QueryType 3 | } 4 | 5 | type QueryType { 6 | hero(episode: Episode): Character 7 | human(id : String) : Human 8 | droid(id: ID!): Droid 9 | } 10 | 11 | 12 | enum Episode { 13 | NEWHOPE 14 | EMPIRE 15 | JEDI 16 | } 17 | 18 | interface Character { 19 | id: ID! 20 | name: String! 21 | friends: [Character] 22 | appearsIn: [Episode]! 23 | } 24 | 25 | type Human implements Character { 26 | id: ID! 27 | name: String! 28 | friends: [Character] 29 | appearsIn: [Episode]! 30 | homePlanet: String 31 | } 32 | 33 | type Droid implements Character { 34 | id: ID! 35 | name: String! 36 | friends: [Character] 37 | appearsIn: [Episode]! 38 | primaryFunction: String 39 | } 40 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/java/com/networknt/codegen/hybrid/HybridGenerator.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen.hybrid; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.node.ObjectNode; 5 | import com.networknt.codegen.Generator; 6 | 7 | public interface HybridGenerator extends Generator { 8 | default String getJsonPath(JsonNode config, String defaultValue) { 9 | String jsonPath = defaultValue == null ? "/api/json" : defaultValue; 10 | JsonNode jsonNode = config.get("jsonPath"); 11 | if(jsonNode == null) { 12 | ((ObjectNode)config).put("jsonPath", jsonPath); 13 | } else { 14 | jsonPath = jsonNode.textValue(); 15 | } 16 | return jsonPath; 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/binaries/client.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-hybrid-4j/src/main/resources/binaries/client.keystore -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/binaries/client.truststore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-hybrid-4j/src/main/resources/binaries/client.truststore -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/binaries/server.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-hybrid-4j/src/main/resources/binaries/server.keystore -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/binaries/server.truststore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-hybrid-4j/src/main/resources/binaries/server.truststore -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/light-hybrid-4j-server.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "definitions": {}, 4 | "id": "http://example.com/example.json", 5 | "properties": { 6 | "artifactId": { 7 | "id": "/properties/artifactId", 8 | "type": "string" 9 | }, 10 | "groupId": { 11 | "id": "/properties/groupId", 12 | "type": "string" 13 | }, 14 | "handlerPackage": { 15 | "id": "/properties/handlerPackage", 16 | "type": "string" 17 | }, 18 | "modelPackage": { 19 | "id": "/properties/modelPackage", 20 | "type": "string" 21 | }, 22 | "name": { 23 | "id": "/properties/name", 24 | "type": "string" 25 | }, 26 | "overwriteHandler": { 27 | "id": "/properties/overwriteHandler", 28 | "type": "boolean" 29 | }, 30 | "overwriteHandlerTest": { 31 | "id": "/properties/overwriteHandlerTest", 32 | "type": "boolean" 33 | }, 34 | "rootPackage": { 35 | "id": "/properties/rootPackage", 36 | "type": "string" 37 | }, 38 | "version": { 39 | "id": "/properties/version", 40 | "type": "string" 41 | } 42 | }, 43 | "type": "object" 44 | } 45 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/light-hybrid-4j-service.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "definitions": {}, 4 | "id": "http://example.com/example.json", 5 | "properties": { 6 | "artifactId": { 7 | "id": "/properties/artifactId", 8 | "type": "string" 9 | }, 10 | "groupId": { 11 | "id": "/properties/groupId", 12 | "type": "string" 13 | }, 14 | "handlerPackage": { 15 | "id": "/properties/handlerPackage", 16 | "type": "string" 17 | }, 18 | "modelPackage": { 19 | "id": "/properties/modelPackage", 20 | "type": "string" 21 | }, 22 | "name": { 23 | "id": "/properties/name", 24 | "type": "string" 25 | }, 26 | "overwriteHandler": { 27 | "id": "/properties/overwriteHandler", 28 | "type": "boolean" 29 | }, 30 | "overwriteHandlerTest": { 31 | "id": "/properties/overwriteHandlerTest", 32 | "type": "boolean" 33 | }, 34 | "rootPackage": { 35 | "id": "/properties/rootPackage", 36 | "type": "string" 37 | }, 38 | "version": { 39 | "id": "/properties/version", 40 | "type": "string" 41 | } 42 | }, 43 | "type": "object" 44 | } 45 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/maven/mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-hybrid-4j/src/main/resources/maven/mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/maven/mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar 3 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/templates/hybrid/appStatusYml.rocker.raw: -------------------------------------------------------------------------------- 1 | # Put your application specific error code into this file instead of status.yml 2 | # This file will be merge into the status.yml during the server startup. 3 | # Please allocate the range for the application error codes within your organization 4 | # to ensure no reused for an error code across the organization for tracing. 5 | 6 | # 20000-29999 common error codes within your business domain. 7 | # It is highly recommended to have common error codes shared within your organization 8 | # or your line of business and put them into the externalized status.yml file. 9 | 10 | # 30000-99999 customize error code that cannot be found in common range. 11 | # Only use this section if you cannot make your error code into 20000-29999 range on time. 12 | # In this case, the error code defined here will be merged to the status.yml during startup. 13 | # To ensure there is no reuse of error code, this application will use the range 30000-31000. 14 | ERR30000: 15 | statusCode: 400 16 | code: ERR30000 17 | message: FIRST_ERROR_IN_APP 18 | description: This is is the first error in this example application. 19 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/templates/hybrid/classpath.rocker.raw: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/templates/hybrid/gitignore.rocker.raw: -------------------------------------------------------------------------------- 1 | target/ 2 | bower_components/ 3 | node_modules/ 4 | dist/ 5 | .idea/ 6 | .tmp/ 7 | .project 8 | .classpath 9 | .settings 10 | .metadata/ 11 | *.iml 12 | *.log 13 | *.tmp 14 | *.bak 15 | dependency-reduced-pom.xml 16 | 17 | # Compiled class file 18 | *.class 19 | 20 | # BlueJ files 21 | *.ctxt 22 | 23 | # Package Files # 24 | *.jar 25 | *.war 26 | *.nar 27 | *.ear 28 | *.tar.gz 29 | *.rar 30 | *.zip 31 | 32 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 33 | hs_err_pid* 34 | replay_pid* 35 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/templates/hybrid/handler.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (String handlerPackage, String host, String service, JsonNode item, String example) 3 | package @handlerPackage; 4 | 5 | import com.networknt.utility.NioUtils; 6 | import com.networknt.rpc.HybridHandler; 7 | import com.networknt.rpc.router.ServiceHandler; 8 | import java.nio.ByteBuffer; 9 | import io.undertow.server.HttpServerExchange; 10 | 11 | /** 12 | For more information on how to write business handlers, please check the link below. 13 | https://doc.networknt.com/development/business-handler/hybrid/ 14 | */ 15 | @@ServiceHandler(id="@host/@service/@item.get("name").textValue()/@item.get("version").textValue()") 16 | public class @item.get("handler").textValue() implements HybridHandler { 17 | @@Override 18 | public ByteBuffer handle(HttpServerExchange exchange, Object input) { 19 | return NioUtils.toByteBuffer("@example"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/templates/hybrid/project.rocker.raw: -------------------------------------------------------------------------------- 1 | 2 | 3 | light-hybrid-4j 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/templates/hybrid/server/README.md.rocker.raw: -------------------------------------------------------------------------------- 1 | # Light Hybrid 4J Server 2 | 3 | ## Start server 4 | 5 | If you only have one service jar file, then your can include the jar file into the 6 | class path as below. 7 | 8 | ``` 9 | java -cp petstore-1.0.1.jar:target/petstore-1.0.1.jar com.networknt.server.Server 10 | ``` 11 | 12 | If you have multiple service jar files, you'd better create a directory and include 13 | that directory into the classpath when starting the server. 14 | 15 | ``` 16 | java -cp petstore-1.0.1.jar:/service com.networknt.server.Server 17 | ``` 18 | 19 | 20 | ## Test 21 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/templates/hybrid/server/buildSh.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config, String serviceId) 3 | #!/bin/bash 4 | 5 | set -ex 6 | 7 | VERSION=$1 8 | IMAGE_NAME="@config.get("dockerOrganization").textValue()/@serviceId" 9 | 10 | showHelp() { 11 | echo " " 12 | echo "Error: $1" 13 | echo " " 14 | echo " build.sh [VERSION]" 15 | echo " " 16 | echo " where [VERSION] version of the docker image that you want to publish (example: 0.0.1)" 17 | echo " " 18 | echo " example: ./build.sh 0.0.1" 19 | echo " " 20 | } 21 | 22 | build() { 23 | echo "Building ..." 24 | @if(config.get("buildMaven").booleanValue()){ 25 | mvn clean install -Prelease 26 | }else{ 27 | ./gradlew clean build 28 | } 29 | echo "Successfully built!" 30 | } 31 | 32 | cleanup() { 33 | if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" != "" ]]; then 34 | echo "Removing old $IMAGE_NAME images" 35 | docker images | grep $IMAGE_NAME | awk '{print $3}' | xargs docker rmi -f 36 | echo "Cleanup completed!" 37 | fi 38 | } 39 | 40 | publish() { 41 | echo "Building Docker image with version $VERSION" 42 | docker build -t $IMAGE_NAME:$VERSION -t $IMAGE_NAME:latest -f ./docker/Dockerfile . --no-cache=true 43 | docker build -t $IMAGE_NAME:$VERSION-slim -f ./docker/Dockerfile-Slim . --no-cache=true 44 | echo "Images built with version $VERSION" 45 | echo "Pushing image to DockerHub" 46 | docker push $IMAGE_NAME -a 47 | echo "Image successfully published!" 48 | } 49 | 50 | if [ -z $VERSION ]; then 51 | showHelp "[VERSION] parameter is missing" 52 | exit 53 | fi 54 | 55 | build; 56 | cleanup; 57 | publish; 58 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/templates/hybrid/server/dockerfile.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config, String expose) 3 | FROM azul/zulu-openjdk-alpine:11 as packager 4 | 5 | RUN { \ 6 | java --version ; \ 7 | echo "jlink version:" && \ 8 | $JAVA_HOME/bin/jlink --version ; \ 9 | } 10 | 11 | ENV JAVA_MINIMAL=/opt/jre 12 | 13 | # build modules distribution 14 | RUN $JAVA_HOME/bin/jlink \ 15 | --verbose \ 16 | --add-modules \ 17 | java.base,java.sql,java.naming,java.desktop,java.xml,jdk.crypto.cryptoki,jdk.crypto.ec,jdk.unsupported,java.management,java.security.jgss,java.net.http \ 18 | --compress 2 \ 19 | --strip-debug \ 20 | --no-header-files \ 21 | --no-man-pages \ 22 | --output "$JAVA_MINIMAL" 23 | 24 | # Second stage, add only our minimal "JRE" distr and our app 25 | FROM alpine 26 | 27 | ENV JAVA_MINIMAL=/opt/jre 28 | ENV PATH="$PATH:$JAVA_MINIMAL/bin" 29 | 30 | COPY --from=packager "$JAVA_MINIMAL" "$JAVA_MINIMAL" 31 | @if(config.get("buildMaven").booleanValue()){ 32 | @with (name = config.get("artifactId").textValue() + "-" + config.get("version").textValue() + ".jar") {COPY /target/@name server.jar} 33 | }else{ 34 | @with (name = config.get("artifactId").textValue() + ".jar") {COPY /build/libs/@name server.jar} 35 | } 36 | CMD ["/bin/sh","-c","exec java -Dlight-4j-config-dir=/config -Dlogback.configurationFile=/config/logback.xml -cp /server.jar:/service/* com.networknt.server.Server"] 37 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/templates/hybrid/server/dockerfileslim.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config, String expose) 3 | FROM openjdk:11.0.3-slim 4 | @if(config.get("buildMaven").booleanValue()){ 5 | @with (name = config.get("artifactId").textValue() + "-" + config.get("version").textValue() + ".jar") {COPY /target/@name server.jar} 6 | }else{ 7 | @with (name = config.get("artifactId").textValue() + ".jar") {COPY /build/libs/@name server.jar} 8 | } 9 | CMD ["/bin/sh","-c","exec java -Dlight-4j-config-dir=/config -Dlogback.configurationFile=/config/logback.xml -cp /server.jar:/service/* com.networknt.server.Server"] 10 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/templates/hybrid/service/README.md.rocker.raw: -------------------------------------------------------------------------------- 1 | # Light Hybrid 4J Service 2 | 3 | This project is a testing platform for developing light-hybrid-4j services. You can build and test your service 4 | here and then build a small jar file that contains only your handler classes. To deploy your service, just drop 5 | the jar into a directory and start light-hybrid-4j server. 6 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/main/resources/templates/hybrid/testServer.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String handlerPackage) 2 | package @handlerPackage; 3 | 4 | import com.networknt.server.Server; 5 | import com.networknt.server.ServerConfig; 6 | import org.junit.jupiter.api.extension.AfterAllCallback; 7 | import org.junit.jupiter.api.extension.BeforeAllCallback; 8 | import org.junit.jupiter.api.extension.ExtensionContext; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | import java.util.concurrent.atomic.AtomicInteger; 12 | 13 | public class TestServer implements BeforeAllCallback, AfterAllCallback { 14 | static final Logger logger = LoggerFactory.getLogger(TestServer.class); 15 | 16 | private static final AtomicInteger refCount = new AtomicInteger(0); 17 | private static Server server; 18 | 19 | private static final TestServer instance = new TestServer(); 20 | 21 | public static TestServer getInstance () { 22 | return instance; 23 | } 24 | 25 | private TestServer() { 26 | 27 | } 28 | 29 | public void restartServer() { 30 | try { 31 | if (refCount.get() == 0) { 32 | Server.start(); 33 | } 34 | } 35 | finally { 36 | refCount.getAndIncrement(); 37 | } 38 | } 39 | 40 | @@Override 41 | public void beforeAll(ExtensionContext context) { 42 | try { 43 | if (refCount.get() == 0) { 44 | Server.start(); 45 | logger.info("TestServer is started"); 46 | } 47 | } 48 | finally { 49 | refCount.getAndIncrement(); 50 | } 51 | Runtime.getRuntime().addShutdownHook(new Thread(() -> clean())); 52 | } 53 | 54 | @@Override 55 | public void afterAll(ExtensionContext context) { 56 | clean(); 57 | } 58 | 59 | protected void clean() { 60 | refCount.getAndDecrement(); 61 | if (refCount.get() == 0) { 62 | Server.stop(); 63 | logger.info("TestServer is stopped"); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/test/java/com/networknt/codegen/hybrid/HybridServerGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen.hybrid; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import com.networknt.codegen.Generator; 6 | import org.junit.jupiter.api.Test; 7 | import org.junit.jupiter.api.BeforeAll; 8 | import static org.junit.jupiter.api.Assertions.*; 9 | 10 | import java.io.IOException; 11 | import java.nio.file.Files; 12 | import java.nio.file.Paths; 13 | 14 | /** 15 | * Created by steve on 28/04/17. 16 | */ 17 | public class HybridServerGeneratorTest { 18 | 19 | public static String targetPath = "/tmp/hybridserver"; 20 | public static String configName = "/serverConfig.json"; 21 | 22 | ObjectMapper mapper = new ObjectMapper(); 23 | 24 | @BeforeAll 25 | public static void setUp() throws IOException { 26 | // create the output directory 27 | Files.createDirectories(Paths.get(targetPath)); 28 | } 29 | 30 | //@AfterClass 31 | public static void tearDown() throws IOException { 32 | Files.deleteIfExists(Paths.get(targetPath)); 33 | } 34 | 35 | @Test 36 | public void testGenerator() throws IOException { 37 | JsonNode config = Generator.jsonMapper.readTree(HybridServerGeneratorTest.class.getResourceAsStream(configName)); 38 | HybridServerGenerator generator = new HybridServerGenerator(); 39 | generator.generate(targetPath, null, config); 40 | } 41 | 42 | @Test 43 | public void testGetFramework() { 44 | HybridServerGenerator generator = new HybridServerGenerator(); 45 | assertEquals("light-hybrid-4j-server", generator.getFramework()); 46 | } 47 | 48 | @Test 49 | public void testGetConfigSchema() throws IOException { 50 | HybridServerGenerator generator = new HybridServerGenerator(); 51 | assertNotNull(generator.getConfigSchema()); 52 | System.out.println(generator.getConfigSchema().toString()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/test/java/com/networknt/codegen/hybrid/HybridServiceGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen.hybrid; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.networknt.codegen.Generator; 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.BeforeAll; 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | import java.io.IOException; 10 | import java.nio.file.Files; 11 | import java.nio.file.Paths; 12 | 13 | /** 14 | * Created by steve on 28/04/17. 15 | */ 16 | public class HybridServiceGeneratorTest { 17 | public static String targetPath = "/tmp/hybridservice"; 18 | public static String configName = "/service.yaml"; 19 | public static String schemaName = "/spec.yaml"; 20 | 21 | @BeforeAll 22 | public static void setUp() throws IOException { 23 | // create the output directory 24 | Files.createDirectories(Paths.get(targetPath)); 25 | } 26 | 27 | //@AfterClass 28 | public static void tearDown() throws IOException { 29 | Files.deleteIfExists(Paths.get(targetPath)); 30 | } 31 | 32 | @Test 33 | public void testGenerator() throws IOException { 34 | JsonNode config = Generator.yamlMapper.readTree(HybridServiceGeneratorTest.class.getResourceAsStream(configName)); 35 | JsonNode model = Generator.yamlMapper.readTree(HybridServiceGeneratorTest.class.getResourceAsStream(schemaName)); 36 | HybridServiceGenerator generator = new HybridServiceGenerator(); 37 | generator.generate(targetPath, model, config); 38 | } 39 | 40 | @Test 41 | public void testGetFramework() { 42 | HybridServiceGenerator generator = new HybridServiceGenerator(); 43 | assertEquals("light-hybrid-4j-service", generator.getFramework()); 44 | } 45 | 46 | @Test 47 | public void testGetConfigSchema() throws IOException { 48 | HybridServiceGenerator generator = new HybridServiceGenerator(); 49 | assertNotNull(generator.getConfigSchema()); 50 | System.out.println(generator.getConfigSchema().toString()); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/test/resources/serverConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "petstore", 3 | "version": "1.0.1", 4 | "groupId": "com.networknt", 5 | "artifactId": "petstore", 6 | "rootPackage": "com.networknt.petstore", 7 | "handlerPackage":"com.networknt.petstore.handler", 8 | "modelPackage":"com.networknt.petstore.model", 9 | "httpPort": 8080, 10 | "enableHttp": true, 11 | "httpsPort": 8443, 12 | "enableHttps": false, 13 | "enableHttp2": false, 14 | "enableRegistry": false, 15 | "supportDb": true, 16 | "dbInfo": { 17 | "name": "mysql", 18 | "driverClassName": "com.mysql.jdbc.Driver", 19 | "jdbcUrl": "jdbc:mysql://mysqldb:3306/oauth2?useSSL=false", 20 | "username": "root", 21 | "password": "my-secret-pw" 22 | }, 23 | "supportH2ForTest": false, 24 | "supportClient": false, 25 | "buildMaven": true, 26 | "dockerOrganization": "networknt" 27 | } 28 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/test/resources/service.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | name: rule-command 3 | version: 1.0.1 4 | groupId: net.lightapi 5 | artifactId: rule-command 6 | rootPackage: com.networknt.rule 7 | handlerPackage: com.networknt.rule.handler 8 | modelPackage: com.networknt.rule.model 9 | overwriteHandler: true 10 | overwriteHandlerTest: true 11 | httpPort: 8080 12 | enableHttp: true 13 | httpsPort: 8443 14 | enableHttps: false 15 | enableHttp2: false 16 | enableRegistry: false 17 | supportDb: true 18 | jsonPath: "/portal/command" 19 | dbInfo: 20 | name: mysql 21 | driverClassName: com.mysql.jdbc.Driver 22 | jdbcUrl: jdbc:mysql://mysqldb:3306/oauth2?useSSL=false 23 | username: root 24 | password: my-secret-pw 25 | supportH2ForTest: false 26 | supportClient: false 27 | buildMaven: true 28 | -------------------------------------------------------------------------------- /light-hybrid-4j/src/test/resources/serviceConfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "petstore", 3 | "version": "1.0.1", 4 | "groupId": "com.networknt", 5 | "artifactId": "petstore", 6 | "rootPackage": "com.networknt.petstore", 7 | "handlerPackage":"com.networknt.petstore.handler", 8 | "modelPackage":"com.networknt.petstore.model", 9 | "overwriteHandler": true, 10 | "overwriteHandlerTest": true, 11 | "httpPort": 8080, 12 | "enableHttp": true, 13 | "httpsPort": 8443, 14 | "enableHttps": false, 15 | "enableHttp2": false, 16 | "enableRegistry": false, 17 | "supportDb": true, 18 | "dbInfo": { 19 | "name": "mysql", 20 | "driverClassName": "com.mysql.jdbc.Driver", 21 | "jdbcUrl": "jdbc:mysql://mysqldb:3306/oauth2?useSSL=false", 22 | "username": "root", 23 | "password": "my-secret-pw" 24 | }, 25 | "supportH2ForTest": false, 26 | "supportClient": false, 27 | "buildMaven": true 28 | } 29 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/java/com/networknt/codegen/rest/ModelCallback.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen.rest; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public interface ModelCallback { 7 | void callback(boolean multipleModule, String targetPath, String modelPackage, String modelFileName, String enumsIfClass, String parentClassName, String classVarName, boolean abstractIfClass, List> props, List> parentClassProps); 8 | } 9 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/java/com/networknt/codegen/rest/OpenApiSpecGenerator.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen.rest; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | import com.networknt.codegen.Generator; 5 | import io.github.classgraph.ClassGraph; 6 | import io.github.classgraph.ScanResult; 7 | import org.apache.commons.lang3.StringUtils; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | import java.nio.file.Files; 14 | import java.nio.file.Paths; 15 | import java.util.HashMap; 16 | import java.util.List; 17 | import java.util.Map; 18 | 19 | public class OpenApiSpecGenerator implements Generator { 20 | private static final Logger logger = LoggerFactory.getLogger(OpenApiSpecGenerator.class); 21 | 22 | private static final String FRAMEWORK="openapi-spec"; 23 | 24 | @Override 25 | public String getFramework() { 26 | return FRAMEWORK; 27 | } 28 | 29 | @SuppressWarnings("rawtypes") 30 | @Override 31 | public void generate(String targetPath, Object model, JsonNode config) throws IOException { 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/java/com/networknt/codegen/rest/OpenApiSpringGenerator.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen.rest; 2 | 3 | public class OpenApiSpringGenerator { 4 | } 5 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/binaries/client.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-rest-4j/src/main/resources/binaries/client.keystore -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/binaries/client.truststore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-rest-4j/src/main/resources/binaries/client.truststore -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/binaries/server.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-rest-4j/src/main/resources/binaries/server.keystore -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/binaries/server.truststore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-rest-4j/src/main/resources/binaries/server.truststore -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/gradle/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-rest-4j/src/main/resources/gradle/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/gradle/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | zipStoreBase=GRADLE_USER_HOME 4 | zipStorePath=wrapper/dists 5 | distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip 6 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/maven/mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/networknt/light-codegen/00de4bd3c80dfe87e5ddd3b1af0f3c185fe54b9b/light-rest-4j/src/main/resources/maven/mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/maven/mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.3/maven-wrapper-0.5.3.jar 3 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/openapi.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "definitions": {}, 4 | "id": "http://example.com/example.json", 5 | "properties": { 6 | "artifactId": { 7 | "id": "/properties/artifactId", 8 | "type": "string" 9 | }, 10 | "groupId": { 11 | "id": "/properties/groupId", 12 | "type": "string" 13 | }, 14 | "handlerPackage": { 15 | "id": "/properties/handlerPackage", 16 | "type": "string" 17 | }, 18 | "modelPackage": { 19 | "id": "/properties/modelPackage", 20 | "type": "string" 21 | }, 22 | "name": { 23 | "id": "/properties/name", 24 | "type": "string" 25 | }, 26 | "overwriteHandler": { 27 | "id": "/properties/overwriteHandler", 28 | "type": "boolean" 29 | }, 30 | "overwriteHandlerTest": { 31 | "id": "/properties/overwriteHandlerTest", 32 | "type": "boolean" 33 | }, 34 | "rootPackage": { 35 | "id": "/properties/rootPackage", 36 | "type": "string" 37 | }, 38 | "version": { 39 | "id": "/properties/version", 40 | "type": "string" 41 | } 42 | }, 43 | "type": "object" 44 | } 45 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/openapikotlin.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "definitions": {}, 4 | "id": "http://example.com/example.json", 5 | "properties": { 6 | "artifactId": { 7 | "id": "/properties/artifactId", 8 | "type": "string" 9 | }, 10 | "groupId": { 11 | "id": "/properties/groupId", 12 | "type": "string" 13 | }, 14 | "handlerPackage": { 15 | "id": "/properties/handlerPackage", 16 | "type": "string" 17 | }, 18 | "modelPackage": { 19 | "id": "/properties/modelPackage", 20 | "type": "string" 21 | }, 22 | "name": { 23 | "id": "/properties/name", 24 | "type": "string" 25 | }, 26 | "overwriteHandler": { 27 | "id": "/properties/overwriteHandler", 28 | "type": "boolean" 29 | }, 30 | "overwriteHandlerTest": { 31 | "id": "/properties/overwriteHandlerTest", 32 | "type": "boolean" 33 | }, 34 | "rootPackage": { 35 | "id": "/properties/rootPackage", 36 | "type": "string" 37 | }, 38 | "version": { 39 | "id": "/properties/version", 40 | "type": "string" 41 | } 42 | }, 43 | "type": "object" 44 | } 45 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/openapilambda.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "definitions": {}, 4 | "id": "http://example.com/example.json", 5 | "properties": { 6 | "artifactId": { 7 | "id": "/properties/artifactId", 8 | "type": "string" 9 | }, 10 | "groupId": { 11 | "id": "/properties/groupId", 12 | "type": "string" 13 | }, 14 | "handlerPackage": { 15 | "id": "/properties/handlerPackage", 16 | "type": "string" 17 | }, 18 | "modelPackage": { 19 | "id": "/properties/modelPackage", 20 | "type": "string" 21 | }, 22 | "name": { 23 | "id": "/properties/name", 24 | "type": "string" 25 | }, 26 | "overwriteHandler": { 27 | "id": "/properties/overwriteHandler", 28 | "type": "boolean" 29 | }, 30 | "overwriteHandlerTest": { 31 | "id": "/properties/overwriteHandlerTest", 32 | "type": "boolean" 33 | }, 34 | "rootPackage": { 35 | "id": "/properties/rootPackage", 36 | "type": "string" 37 | }, 38 | "version": { 39 | "id": "/properties/version", 40 | "type": "string" 41 | } 42 | }, 43 | "type": "object" 44 | } 45 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/swagger.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-04/schema#", 3 | "definitions": {}, 4 | "id": "http://example.com/example.json", 5 | "properties": { 6 | "artifactId": { 7 | "id": "/properties/artifactId", 8 | "type": "string" 9 | }, 10 | "groupId": { 11 | "id": "/properties/groupId", 12 | "type": "string" 13 | }, 14 | "handlerPackage": { 15 | "id": "/properties/handlerPackage", 16 | "type": "string" 17 | }, 18 | "modelPackage": { 19 | "id": "/properties/modelPackage", 20 | "type": "string" 21 | }, 22 | "name": { 23 | "id": "/properties/name", 24 | "type": "string" 25 | }, 26 | "overwriteHandler": { 27 | "id": "/properties/overwriteHandler", 28 | "type": "boolean" 29 | }, 30 | "overwriteHandlerTest": { 31 | "id": "/properties/overwriteHandlerTest", 32 | "type": "boolean" 33 | }, 34 | "rootPackage": { 35 | "id": "/properties/rootPackage", 36 | "type": "string" 37 | }, 38 | "version": { 39 | "id": "/properties/version", 40 | "type": "string" 41 | } 42 | }, 43 | "type": "object" 44 | } 45 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/AppGateway.java.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String handlerPackage) 2 | package @handlerPackage; 3 | 4 | import com.amazonaws.services.lambda.runtime.Context; 5 | import com.amazonaws.services.lambda.runtime.RequestHandler; 6 | import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; 7 | import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; 8 | import com.fasterxml.jackson.databind.ObjectMapper; 9 | import com.networknt.aws.lambda.LightRequestHandler; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | /** 14 | * App for requests to Lambda function. This class is generated, so please don't modify it. For developers, you need to 15 | * put your business logic in the BusinessHandler so that it won't be overwritten with regeneration. 16 | * 17 | * @@author Steve Hu 18 | */ 19 | public class App extends LightRequestHandler implements RequestHandler { 20 | private static final Logger logger = LoggerFactory.getLogger(App.class); 21 | private static ObjectMapper objectMapper = new ObjectMapper(); 22 | 23 | public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) { 24 | try { 25 | if(logger.isDebugEnabled()) logger.debug(objectMapper.writeValueAsString(input)); 26 | } catch (Exception e) { 27 | e.printStackTrace(); 28 | } 29 | APIGatewayProxyResponseEvent response = interceptRequest(input, context); 30 | if(response != null) { 31 | return interceptResponse(response); 32 | } 33 | BusinessHandler handler = new BusinessHandler(); 34 | return interceptResponse(handler.handleRequest(input, context)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/AppProxy.java.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String handlerPackage) 2 | package @handlerPackage; 3 | 4 | import com.amazonaws.services.lambda.runtime.Context; 5 | import com.amazonaws.services.lambda.runtime.RequestHandler; 6 | import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; 7 | import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; 8 | import com.networknt.aws.lambda.LightLambdaInterceptor; 9 | 10 | /** 11 | * App for requests to Lambda function. This class is generated, so please don't modify it. For developers, you need to 12 | * put your business logic in the BusinessHandler so that it won't be overwritten with regeneration. 13 | * 14 | * @@author Steve Hu 15 | */ 16 | public class App extends LightLambdaInterceptor implements RequestHandler { 17 | public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, final Context context) { 18 | input = interceptRequest(input, context); 19 | BusinessHandler handler = new BusinessHandler(); 20 | return interceptResponse(handler.handleRequest(input, context)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/AppTest.java.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String handlerPackage) 2 | package @handlerPackage; 3 | 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import java.lang.reflect.Field; 6 | import java.util.Map; 7 | 8 | /** 9 | * This is a generated stub for unit test cases. It contains some useful methods that will assist 10 | * developers to write test cases in BusinessHandlerTest. Please don't modify this class as it 11 | * might be overwritten in the next generation. 12 | * 13 | * @@author Steve Hu 14 | */ 15 | public class AppTest { 16 | ObjectMapper objectMapper = new ObjectMapper(); 17 | 18 | public void setEnv(String key, String value) { 19 | try { 20 | Map env = System.getenv(); 21 | Class cl = env.getClass(); 22 | Field field = cl.getDeclaredField("m"); 23 | field.setAccessible(true); 24 | Map writableEnv = (Map) field.get(env); 25 | writableEnv.put(key, value); 26 | } catch (Exception e) { 27 | throw new IllegalStateException("Failed to set environment variable", e); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/BusinessHandler.java.rocker.raw: -------------------------------------------------------------------------------- 1 | @import org.apache.commons.text.StringEscapeUtils 2 | @args (String handlerPackage, String example) 3 | package @handlerPackage; 4 | 5 | import com.amazonaws.services.lambda.runtime.Context; 6 | import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; 7 | import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * This is the generated BusinessHandler for developers to write business logic for the Lambda function. Once this file 16 | * is generated, it won't be overwritten with another generation in the same folder. 17 | */ 18 | public class BusinessHandler { 19 | private static final Logger logger = LoggerFactory.getLogger(BusinessHandler.class); 20 | public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) { 21 | Map headers = new HashMap<>(); 22 | headers.put("Content-Type", "application/json"); 23 | APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent().withHeaders(headers); 24 | String output = ""; 25 | @with (e = StringEscapeUtils.escapeJson(example)) {output = "@e";} 26 | response.withStatusCode(200) 27 | .withBody(output); 28 | return response; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/Dockerfile.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String handlerPackage) 2 | FROM amd64/maven as build-image 3 | 4 | WORKDIR "/task" 5 | COPY src/ src/ 6 | COPY pom.xml ./ 7 | 8 | RUN mvn -q clean install 9 | RUN mvn dependency:copy-dependencies -DincludeScope=compile 10 | 11 | FROM public.ecr.aws/lambda/java:11 12 | 13 | COPY --from=build-image /task/target/classes /var/task/ 14 | COPY --from=build-image /task/target/dependency /var/task/lib 15 | # Command can be overwritten by providing a different command in the template directly. 16 | @with(s = "CMD [\"" + handlerPackage + ".App::handleRequest\"]"){@s} 17 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/DockerfileProxy.rocker.raw: -------------------------------------------------------------------------------- 1 | FROM azul/zulu-openjdk-alpine:11 as packager 2 | 3 | RUN { \ 4 | java --version ; \ 5 | echo "jlink version:" && \ 6 | $JAVA_HOME/bin/jlink --version ; \ 7 | } 8 | 9 | ENV JAVA_MINIMAL=/opt/jre 10 | 11 | # build modules distribution 12 | RUN $JAVA_HOME/bin/jlink \ 13 | --verbose \ 14 | --add-modules \ 15 | java.base,java.sql,java.naming,java.desktop,java.xml,jdk.crypto.cryptoki,jdk.crypto.ec,jdk.unsupported,java.management,java.security.jgss,java.net.http \ 16 | --compress 2 \ 17 | --strip-debug \ 18 | --no-header-files \ 19 | --no-man-pages \ 20 | --output "$JAVA_MINIMAL" 21 | 22 | # Second stage, add only our minimal "JRE" distr and our app 23 | FROM alpine 24 | 25 | ENV JAVA_MINIMAL=/opt/jre 26 | ENV PATH="$PATH:$JAVA_MINIMAL/bin" 27 | 28 | COPY --from=packager "$JAVA_MINIMAL" "$JAVA_MINIMAL" 29 | COPY /light-proxy.jar server.jar 30 | COPY /proxy /config 31 | CMD ["/bin/sh","-c","exec java -Dlight-4j-config-dir=/config -Dlogback.configurationFile=/config/logback.xml -jar /server.jar"] 32 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/Makefile.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String functionName) 2 | CUR_DIR := $(abspath $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))) 3 | 4 | build-@functionName: 5 | cd $(CUR_DIR) && ./gradlew build 6 | cp $(CUR_DIR)/build/graalvm/server $(ARTIFACTS_DIR) 7 | cp $(CUR_DIR)/bootstrap $(ARTIFACTS_DIR) 8 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/appYml.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (boolean useLightProxy) 2 | Dev: 3 | Sit: 4 | Stage: 5 | Prod: 6 | @if(!useLightProxy) { 7 | truststoreName: prod.truststore 8 | truststorePass: password 9 | } 10 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/bootstrap.rocker.raw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -euo pipefail 3 | ./server 4 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/buildGraalvmSh.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String functionName) 2 | #!/bin/bash 3 | 4 | docker run --rm --name graal -v $(pwd):/working springci/graalvm-ce:master-java11 \ 5 | /bin/bash -c "native-image \ 6 | --enable-url-protocols=http,https \ 7 | --no-fallback \ 8 | --allow-incomplete-classpath \ 9 | --enable-all-security-services \ 10 | -H:ReflectionConfigurationFiles=/working/reflect.json \ 11 | -H:ResourceConfigurationFiles=/working/resource-config.json \ 12 | -H:+ReportExceptionStackTraces \ 13 | -jar /working/build/libs/@functionName-all.jar \ 14 | ; \ 15 | cp @functionName-all /working/build/graalvm/server" 16 | 17 | mkdir -p build/graalvm 18 | if [ ! -f "build/graalvm/server" ]; then 19 | echo "there was an error building graalvm image" 20 | exit 1 21 | fi 22 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/buildGradle.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | plugins { 4 | id 'java' 5 | id "com.github.johnrengelman.shadow" version "5.2.0" 6 | } 7 | 8 | repositories { 9 | mavenCentral() 10 | mavenLocal() 11 | maven { 12 | url 'https://oss.sonatype.org/content/repositories/snapshots/' 13 | } 14 | } 15 | 16 | dependencies { 17 | implementation "com.networknt:utility:$light4jVersion" 18 | implementation "com.networknt:slf4j-logback:$light4jVersion" 19 | implementation "com.networknt:custom-runtime:$light4jVersion" 20 | implementation "com.networknt:@if(config.get("useLightProxy").booleanValue()){lambda-interceptor}else{request-handler}:$light4jVersion" 21 | implementation "com.amazonaws:aws-lambda-java-core:$lambdaCoreVersion" 22 | implementation "com.amazonaws:aws-lambda-java-events:$lambdaEventsVersion" 23 | testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion" 24 | testImplementation "org.junit.jupiter:junit-jupiter-engine:$junitVersion" 25 | } 26 | 27 | jar { 28 | manifest { 29 | attributes 'Main-Class': 'com.networknt.aws.lambda.Runtime' 30 | } 31 | } 32 | 33 | task buildGraalvmImage { 34 | inputs.files("${project.projectDir}/src/main", configurations.compileClasspath) 35 | outputs.upToDateWhen {file("${buildDir}/graalvm/server").exists()} 36 | outputs.file file("${buildDir}/graalvm/server") 37 | 38 | doLast { 39 | exec { 40 | commandLine "bash", "-c", "chmod +x build_graalvm.sh; chmod +x bootstrap; ./build_graalvm.sh" 41 | } 42 | } 43 | } 44 | 45 | buildGraalvmImage.dependsOn shadowJar, test 46 | build.dependsOn buildGraalvmImage 47 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/buildSh.rocker.raw: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | VERSION=$1 6 | IMAGE_NAME="lambda-proxy" 7 | 8 | showHelp() { 9 | echo " " 10 | echo "Error: $1" 11 | echo " " 12 | echo " build.sh [VERSION]" 13 | echo " " 14 | echo " where [VERSION] version of the docker image that you want to publish (example: 0.0.1)" 15 | echo " " 16 | echo " example: ./build.sh 0.0.1" 17 | echo " " 18 | } 19 | 20 | build() { 21 | echo "Copying ..." 22 | # download from github release page 23 | wget https://github.com/networknt/light-proxy/releases/download/2.0.23/light-proxy.jar 24 | echo "Successfully copied!" 25 | } 26 | 27 | remove() { 28 | if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" != "" ]]; then 29 | echo "Removing old $IMAGE_NAME images" 30 | docker images | grep $IMAGE_NAME | awk '{print $3}' | xargs docker rmi -f 31 | echo "Cleanup completed!" 32 | fi 33 | } 34 | 35 | publish() { 36 | echo "Building Docker image with version $VERSION" 37 | docker build -t $IMAGE_NAME -f ./Dockerfile-proxy . 38 | echo "Images built with version $VERSION" 39 | docker tag $IMAGE_NAME:latest 964637446810.dkr.ecr.us-east-2.amazonaws.com/lambda-proxy:latest 40 | echo "Pushing image to DockerHub" 41 | docker push 964637446810.dkr.ecr.us-east-2.amazonaws.com/lambda-proxy:latest 42 | echo "Image successfully published!" 43 | } 44 | 45 | cleanup() { 46 | echo "Clean up the proxy.jar" 47 | rm light-proxy.jar 48 | } 49 | 50 | if [ -z $VERSION ]; then 51 | showHelp "[VERSION] parameter is missing" 52 | exit 53 | fi 54 | 55 | build; 56 | remove; 57 | publish; 58 | cleanup; 59 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/gitignore.rocker.raw: -------------------------------------------------------------------------------- 1 | target/ 2 | bower_components/ 3 | node_modules/ 4 | dist/ 5 | build/ 6 | .idea/ 7 | .tmp/ 8 | .settings 9 | .metadata/ 10 | .aws-sam/ 11 | .gradle/ 12 | 13 | *.iml 14 | *.log 15 | *.tmp 16 | *.zip 17 | *.bak 18 | dependency-reduced-pom.xml 19 | samconfig.toml 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/gradleProperties.rocker.raw: -------------------------------------------------------------------------------- 1 | # Versions of Frequently used Libraries 2 | light4jVersion=2.2.2 3 | lambdaCoreVersion=1.2.3 4 | lambdaEventsVersion=3.15.0 5 | jacksonVersion=2.18.3 6 | logbackVersion=1.5.18 7 | junitVersion=5.11.3 8 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/logback.rocker.raw: -------------------------------------------------------------------------------- 1 | @args(String rootPackage) 2 | 17 | 18 | 19 | http://stackoverflow.com/questions/2488558/logback-to-log-different-messages-to-two-files 20 | 21 | PROFILER 22 | 23 | NEUTRAL 24 | 25 | 26 | 27 | 29 | 30 | %d{HH:mm:ss.SSS} [%thread] %X{sId} %X{cId} %-5level %class{36}:%L %M - %msg%n 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/proxy/lambdaInvokerYml.rocker.raw: -------------------------------------------------------------------------------- 1 | @import java.util.Map 2 | @import java.util.List 3 | @args (String region, List> items) 4 | # The aws region that is used to create the LambdaClient. 5 | region: @region 6 | # The LogType of the execution log of Lambda. Set Tail to include and None to not include. 7 | logType: Tail 8 | # mapping of the endpoints to Lambda functions 9 | functions: 10 | @for(item: items){ 11 | @item.get("endpoint"): @item.get("functionName") 12 | } 13 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/proxy/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | TODO create logger for audit only. 20 | http://stackoverflow.com/questions/2488558/logback-to-log-different-messages-to-two-files 21 | 22 | PROFILER 23 | 24 | NEUTRAL 25 | 26 | 27 | 28 | 30 | 31 | %d{HH:mm:ss.SSS} [%thread] %X{sId} %X{cId} %-5level %class{36}:%L %M - %msg%n 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/proxy/proxy.yml.rocker.raw: -------------------------------------------------------------------------------- 1 | --- 2 | # Reverse Proxy Handler Configuration 3 | 4 | # If HTTP 2.0 protocol will be used to connect to target servers 5 | http2Enabled: true 6 | 7 | # If TLS is enabled when connecting to the target servers 8 | httpsEnabled: true 9 | 10 | # Target URIs 11 | hosts: https://freedom:8081,https://freedom:8082,https://freedom:8083 12 | 13 | # Connections per thread to the target servers 14 | connectionsPerThread: 20 15 | 16 | # Max request time in milliseconds before timeout 17 | maxRequestTime: 1000 18 | 19 | # Rewrite Host Header with the target host and port and write X_FORWARDED_HOST with original host 20 | rewriteHostHeader: true 21 | 22 | # Reuse XForwarded for the target XForwarded header 23 | reuseXForwarded: false 24 | 25 | # Max Connection Retries 26 | maxConnectionRetries: 3 27 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/resourceJson.rocker.raw: -------------------------------------------------------------------------------- 1 | { 2 | "resources": { 3 | "includes": [ 4 | {"pattern": "app.yml"}, 5 | {"pattern": "logback.xml"} 6 | ], 7 | "excludes": [ 8 | ] 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambda/values.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String serviceId, Boolean enableHttp, String httpPort, Boolean enableHttps, String httpsPort, Boolean enableHttp2, Boolean enableRegistry, String version) 2 | # server.yml 3 | server.httpPort: @httpPort 4 | server.enableHttp: @enableHttp 5 | server.httpsPort: @httpsPort 6 | server.enableHttps: @enableHttps 7 | server.enableHttp2: @enableHttp2 8 | server.enableRegistry: @enableRegistry 9 | server.serviceId: @serviceId 10 | server.buildNumber: @version 11 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/App.java.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String handlerPackage) 2 | package @handlerPackage; 3 | 4 | import com.amazonaws.services.lambda.runtime.Context; 5 | import com.amazonaws.services.lambda.runtime.RequestHandler; 6 | import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; 7 | import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; 8 | import com.fasterxml.jackson.databind.ObjectMapper; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | /** 13 | * App is the entry point for requests to Lambda function. This class is generated, so please don't modify it. 14 | * For developers, you need to put business logic in the BusinessHandler so that it won't be overwritten with 15 | * regeneration. 16 | * 17 | * @@author Steve Hu 18 | */ 19 | public class App implements RequestHandler { 20 | private static final Logger logger = LoggerFactory.getLogger(App.class); 21 | private static final ObjectMapper objectMapper = new ObjectMapper(); 22 | 23 | public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent request, final Context context) { 24 | try { 25 | if(logger.isDebugEnabled()) logger.debug("request = {}", objectMapper.writeValueAsString(request)); 26 | } catch (Exception e) { 27 | logger.error("Exception:", e); 28 | } 29 | BusinessHandler handler = BusinessHandler.getInstance(); 30 | APIGatewayProxyResponseEvent response = handler.handleRequest(request, context); 31 | try { 32 | if(logger.isDebugEnabled()) logger.debug("response = {}", objectMapper.writeValueAsString(response)); 33 | } catch (Exception e) { 34 | logger.error("Exception:", e); 35 | } 36 | return response; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/AppTest.java.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String handlerPackage) 2 | package @handlerPackage; 3 | 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import java.lang.reflect.Field; 6 | import java.util.Map; 7 | 8 | /** 9 | * This is a generated stub for unit test cases. It contains some useful methods that will assist 10 | * developers to write test cases in BusinessHandlerTest. Please don't modify this class as it 11 | * might be overwritten in the next generation. 12 | * 13 | * @@author Steve Hu 14 | */ 15 | public class AppTest { 16 | ObjectMapper objectMapper = new ObjectMapper(); 17 | 18 | public void setEnv(String key, String value) { 19 | try { 20 | Map env = System.getenv(); 21 | Class cl = env.getClass(); 22 | Field field = cl.getDeclaredField("m"); 23 | field.setAccessible(true); 24 | Map writableEnv = (Map) field.get(env); 25 | writableEnv.put(key, value); 26 | } catch (Exception e) { 27 | throw new IllegalStateException("Failed to set environment variable", e); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/BusinessHandler.java.rocker.raw: -------------------------------------------------------------------------------- 1 | @import org.apache.commons.text.StringEscapeUtils 2 | @args (String handlerPackage, String example) 3 | package @handlerPackage; 4 | 5 | import com.amazonaws.services.lambda.runtime.Context; 6 | import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; 7 | import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | /** 15 | * This is the generated BusinessHandler for developers to write business logic for the Lambda function. Once this file 16 | * is generated, it won't be overwritten with another generation in the same folder. 17 | */ 18 | public class BusinessHandler { 19 | private static final Logger logger = LoggerFactory.getLogger(BusinessHandler.class); 20 | 21 | private BusinessHandler() { 22 | } 23 | 24 | private static final class InstanceHolder { 25 | private static final BusinessHandler INSTANCE = new BusinessHandler(); 26 | } 27 | 28 | public static BusinessHandler getInstance() { 29 | return InstanceHolder.INSTANCE; 30 | } 31 | 32 | public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) { 33 | Map headers = new HashMap<>(); 34 | headers.put("Content-Type", "application/json"); 35 | APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent().withHeaders(headers); 36 | String output = ""; 37 | @with (e = StringEscapeUtils.escapeJson(example)) {output = "@e";} 38 | response.withStatusCode(200) 39 | .withIsBase64Encoded(false) 40 | .withBody(output); 41 | return response; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/Dockerfile.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String handlerPackage) 2 | FROM amd64/maven as build-image 3 | 4 | WORKDIR "/task" 5 | COPY src/ src/ 6 | COPY pom.xml ./ 7 | 8 | RUN mvn -q clean install 9 | RUN mvn dependency:copy-dependencies -DincludeScope=compile 10 | 11 | FROM public.ecr.aws/lambda/java:11 12 | 13 | COPY --from=build-image /task/target/classes /var/task/ 14 | COPY --from=build-image /task/target/dependency /var/task/lib 15 | # Command can be overwritten by providing a different command in the template directly. 16 | @with(s = "CMD [\"" + handlerPackage + ".App::handleRequest\"]"){@s} 17 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/DockerfileProxy.rocker.raw: -------------------------------------------------------------------------------- 1 | FROM azul/zulu-openjdk-alpine:11 as packager 2 | 3 | RUN { \ 4 | java --version ; \ 5 | echo "jlink version:" && \ 6 | $JAVA_HOME/bin/jlink --version ; \ 7 | } 8 | 9 | ENV JAVA_MINIMAL=/opt/jre 10 | 11 | # build modules distribution 12 | RUN $JAVA_HOME/bin/jlink \ 13 | --verbose \ 14 | --add-modules \ 15 | java.base,java.sql,java.naming,java.desktop,java.xml,jdk.crypto.cryptoki,jdk.crypto.ec,jdk.unsupported,java.management,java.security.jgss,java.net.http \ 16 | --compress 2 \ 17 | --strip-debug \ 18 | --no-header-files \ 19 | --no-man-pages \ 20 | --output "$JAVA_MINIMAL" 21 | 22 | # Second stage, add only our minimal "JRE" distr and our app 23 | FROM alpine 24 | 25 | ENV JAVA_MINIMAL=/opt/jre 26 | ENV PATH="$PATH:$JAVA_MINIMAL/bin" 27 | 28 | COPY --from=packager "$JAVA_MINIMAL" "$JAVA_MINIMAL" 29 | COPY /light-proxy.jar server.jar 30 | COPY /proxy /config 31 | CMD ["/bin/sh","-c","exec java -Dlight-4j-config-dir=/config -Dlogback.configurationFile=/config/logback.xml -jar /server.jar"] 32 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/Makefile.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String functionName) 2 | CUR_DIR := $(abspath $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))) 3 | 4 | build-@functionName: 5 | cd $(CUR_DIR) && ./gradlew build 6 | cp $(CUR_DIR)/build/graalvm/server $(ARTIFACTS_DIR) 7 | cp $(CUR_DIR)/bootstrap $(ARTIFACTS_DIR) 8 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/appYml.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (boolean useLightProxy) 2 | Dev: 3 | Sit: 4 | Stage: 5 | Prod: 6 | @if(!useLightProxy) { 7 | truststoreName: prod.truststore 8 | truststorePass: password 9 | } 10 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/bootstrap.rocker.raw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -euo pipefail 3 | ./server 4 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/buildGraalvmSh.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String functionName) 2 | #!/bin/bash 3 | 4 | docker run --rm --name graal -v $(pwd):/working springci/graalvm-ce:master-java11 \ 5 | /bin/bash -c "native-image \ 6 | --enable-url-protocols=http,https \ 7 | --no-fallback \ 8 | --allow-incomplete-classpath \ 9 | --enable-all-security-services \ 10 | -H:ReflectionConfigurationFiles=/working/reflect.json \ 11 | -H:ResourceConfigurationFiles=/working/resource-config.json \ 12 | -H:+ReportExceptionStackTraces \ 13 | -jar /working/build/libs/@functionName-all.jar \ 14 | ; \ 15 | cp @functionName-all /working/build/graalvm/server" 16 | 17 | mkdir -p build/graalvm 18 | if [ ! -f "build/graalvm/server" ]; then 19 | echo "there was an error building graalvm image" 20 | exit 1 21 | fi 22 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/buildGradle.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | plugins { 4 | id 'java' 5 | id "com.github.johnrengelman.shadow" version "5.2.0" 6 | } 7 | 8 | repositories { 9 | mavenCentral() 10 | mavenLocal() 11 | maven { 12 | url 'https://oss.sonatype.org/content/repositories/snapshots/' 13 | } 14 | } 15 | 16 | dependencies { 17 | implementation "com.networknt:custom-runtime:$light4jVersion" 18 | implementation "org.slf4j:slf4j-api:$slf4jVersion" 19 | implementation "ch.qos.logback:logback-classic:$logbackVersion" 20 | implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion" 21 | implementation "com.amazonaws:aws-lambda-java-core:$lambdaCoreVersion" 22 | implementation "com.amazonaws:aws-lambda-java-events:$lambdaEventsVersion" 23 | testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion" 24 | testImplementation "org.junit.jupiter:junit-jupiter-engine:$junitVersion" 25 | } 26 | 27 | test { 28 | useJUnitPlatform() 29 | } 30 | 31 | jar { 32 | manifest { 33 | attributes 'Main-Class': 'com.networknt.aws.lambda.Runtime' 34 | } 35 | } 36 | 37 | task buildGraalvmImage { 38 | inputs.files("${project.projectDir}/src/main", configurations.compileClasspath) 39 | outputs.upToDateWhen {file("${buildDir}/graalvm/server").exists()} 40 | outputs.file file("${buildDir}/graalvm/server") 41 | 42 | doLast { 43 | exec { 44 | commandLine "bash", "-c", "chmod +x build_graalvm.sh; chmod +x bootstrap; ./build_graalvm.sh" 45 | } 46 | } 47 | } 48 | 49 | buildGraalvmImage.dependsOn shadowJar, test 50 | build.dependsOn buildGraalvmImage 51 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/buildSh.rocker.raw: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ex 4 | 5 | VERSION=$1 6 | IMAGE_NAME="lambda-proxy" 7 | 8 | showHelp() { 9 | echo " " 10 | echo "Error: $1" 11 | echo " " 12 | echo " build.sh [VERSION]" 13 | echo " " 14 | echo " where [VERSION] version of the docker image that you want to publish (example: 0.0.1)" 15 | echo " " 16 | echo " example: ./build.sh 0.0.1" 17 | echo " " 18 | } 19 | 20 | build() { 21 | echo "Copying ..." 22 | # download from github release page 23 | wget https://github.com/networknt/light-proxy/releases/download/2.0.23/light-proxy.jar 24 | echo "Successfully copied!" 25 | } 26 | 27 | remove() { 28 | if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" != "" ]]; then 29 | echo "Removing old $IMAGE_NAME images" 30 | docker images | grep $IMAGE_NAME | awk '{print $3}' | xargs docker rmi -f 31 | echo "Cleanup completed!" 32 | fi 33 | } 34 | 35 | publish() { 36 | echo "Building Docker image with version $VERSION" 37 | docker build -t $IMAGE_NAME -f ./Dockerfile-proxy . 38 | echo "Images built with version $VERSION" 39 | docker tag $IMAGE_NAME:latest 964637446810.dkr.ecr.us-east-2.amazonaws.com/lambda-proxy:latest 40 | echo "Pushing image to DockerHub" 41 | docker push 964637446810.dkr.ecr.us-east-2.amazonaws.com/lambda-proxy:latest 42 | echo "Image successfully published!" 43 | } 44 | 45 | cleanup() { 46 | echo "Clean up the proxy.jar" 47 | rm light-proxy.jar 48 | } 49 | 50 | if [ -z $VERSION ]; then 51 | showHelp "[VERSION] parameter is missing" 52 | exit 53 | fi 54 | 55 | build; 56 | remove; 57 | publish; 58 | cleanup; 59 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/gitattributes.rocker.raw: -------------------------------------------------------------------------------- 1 | * text eol=lf 2 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/gitignore.rocker.raw: -------------------------------------------------------------------------------- 1 | target/ 2 | bower_components/ 3 | node_modules/ 4 | dist/ 5 | build/ 6 | .idea/ 7 | .tmp/ 8 | .settings 9 | .metadata/ 10 | .aws-sam/ 11 | .gradle/ 12 | 13 | *.iml 14 | *.log 15 | *.tmp 16 | *.zip 17 | *.bak 18 | dependency-reduced-pom.xml 19 | samconfig.toml 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/gradleProperties.rocker.raw: -------------------------------------------------------------------------------- 1 | # Versions of Frequently used Libraries 2 | light4jVersion=2.1.34-SNAPSHOT 3 | lambdaCoreVersion=1.2.3 4 | lambdaEventsVersion=3.15.0 5 | jacksonVersion=2.18.3 6 | slf4jVersion=2.0.17 7 | logbackVersion=1.5.18 8 | junitVersion=5.11.3 9 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/logback.rocker.raw: -------------------------------------------------------------------------------- 1 | @args(String rootPackage) 2 | 17 | 18 | 19 | 20 | PROFILER 21 | NEUTRAL 22 | 23 | 24 | 25 | 26 | %d{HH:mm:ss.SSS} [%thread] %X{sId} %X{cId} %-5level %class{36}:%L %M - %msg%n 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/proxy/lambdaInvokerYml.rocker.raw: -------------------------------------------------------------------------------- 1 | @import java.util.Map 2 | @import java.util.List 3 | @args (String region, List> items) 4 | # The aws region that is used to create the LambdaClient. 5 | region: @region 6 | # The LogType of the execution log of Lambda. Set Tail to include and None to not include. 7 | logType: Tail 8 | # mapping of the endpoints to Lambda functions 9 | functions: 10 | @for(item: items){ 11 | @item.get("endpoint"): @item.get("functionName") 12 | } 13 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/proxy/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | TODO create logger for audit only. 20 | http://stackoverflow.com/questions/2488558/logback-to-log-different-messages-to-two-files 21 | 22 | PROFILER 23 | 24 | NEUTRAL 25 | 26 | 27 | 28 | 30 | 31 | %d{HH:mm:ss.SSS} [%thread] %X{sId} %X{cId} %-5level %class{36}:%L %M - %msg%n 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/proxy/proxy.yml.rocker.raw: -------------------------------------------------------------------------------- 1 | --- 2 | # Reverse Proxy Handler Configuration 3 | 4 | # If HTTP 2.0 protocol will be used to connect to target servers 5 | http2Enabled: true 6 | 7 | # If TLS is enabled when connecting to the target servers 8 | httpsEnabled: true 9 | 10 | # Target URIs 11 | hosts: https://freedom:8081,https://freedom:8082,https://freedom:8083 12 | 13 | # Connections per thread to the target servers 14 | connectionsPerThread: 20 15 | 16 | # Max request time in milliseconds before timeout 17 | maxRequestTime: 1000 18 | 19 | # Rewrite Host Header with the target host and port and write X_FORWARDED_HOST with original host 20 | rewriteHostHeader: true 21 | 22 | # Reuse XForwarded for the target XForwarded header 23 | reuseXForwarded: false 24 | 25 | # Max Connection Retries 26 | maxConnectionRetries: 3 27 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/lambdanative/resourceJson.rocker.raw: -------------------------------------------------------------------------------- 1 | { 2 | "resources": { 3 | "includes": [ 4 | {"pattern": "logback.xml"} 5 | ], 6 | "excludes": [ 7 | ] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/classpath.rocker.raw: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/client/buildGradleKts.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | plugins { 4 | java 5 | } 6 | 7 | dependencies { 8 | val light4jVersion: String by project 9 | compile("com.networknt", "service", light4jVersion) 10 | compile("com.networknt", "client", light4jVersion) 11 | val jacksonVersion: String by project 12 | compile("com.fasterxml.jackson.core", "jackson-databind", jacksonVersion) 13 | val slf4jVersion: String by project 14 | compile("org.slf4j", "slf4j-api", slf4jVersion) 15 | val undertowVersion: String by project 16 | compile("io.undertow", "undertow-core", undertowVersion) 17 | val logbackVersion: String by project 18 | compile("ch.qos.logback", "logback-classic", logbackVersion) 19 | val junitVersion: String by project 20 | testImplementation("org.junit.jupiter", "junit-jupiter", junitVersion) 21 | } 22 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/client/pom.xml.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | 6 | 7 | @config.get("groupId").textValue() 8 | @config.get("artifactId").textValue() 9 | @config.get("version").textValue() 10 | ../pom.xml 11 | 12 | 13 | 4.0.0 14 | client 15 | jar 16 | Client generated from the specification that can be used by the consumers. 17 | 18 | 19 | 20 | com.fasterxml.jackson.core 21 | jackson-databind 22 | 23 | 24 | org.slf4j 25 | slf4j-api 26 | 27 | 28 | ch.qos.logback 29 | logback-classic 30 | test 31 | 32 | 33 | org.junit.jupiter 34 | junit-jupiter 35 | test 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/client/settingsGradleKts.rocker.raw: -------------------------------------------------------------------------------- 1 | // Mark the folder as a Gradle project 2 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/dockerfile.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config, String expose) 3 | FROM azul/zulu-openjdk-alpine:11 as packager 4 | 5 | RUN { \ 6 | java --version ; \ 7 | echo "jlink version:" && \ 8 | $JAVA_HOME/bin/jlink --version ; \ 9 | } 10 | 11 | ENV JAVA_MINIMAL=/opt/jre 12 | 13 | # build modules distribution 14 | RUN $JAVA_HOME/bin/jlink \ 15 | --verbose \ 16 | --add-modules \ 17 | java.base,java.sql,java.naming,java.desktop,java.xml,jdk.crypto.cryptoki,jdk.crypto.ec,jdk.unsupported,java.management,java.security.jgss,java.net.http \ 18 | --compress 2 \ 19 | --strip-debug \ 20 | --no-header-files \ 21 | --no-man-pages \ 22 | --output "$JAVA_MINIMAL" 23 | 24 | # Second stage, add only our minimal "JRE" distr and our app 25 | FROM alpine 26 | 27 | ENV JAVA_MINIMAL=/opt/jre 28 | ENV PATH="$PATH:$JAVA_MINIMAL/bin" 29 | 30 | COPY --from=packager "$JAVA_MINIMAL" "$JAVA_MINIMAL" 31 | @if(config.get("multipleModule").booleanValue()){ 32 | @if(config.get("buildMaven").booleanValue()){ 33 | COPY /server/target/server.jar server.jar 34 | }else{ 35 | @with (name = config.get("artifactId").textValue() + ".jar") {COPY /server/build/libs/@name server.jar} 36 | } 37 | }else{ 38 | @if(config.get("buildMaven").booleanValue()){ 39 | COPY /target/server.jar server.jar 40 | }else{ 41 | @with (name = config.get("artifactId").textValue() + ".jar") {COPY /build/libs/@name server.jar} 42 | } 43 | } 44 | CMD ["/bin/sh","-c","exec java -Dlight-4j-config-dir=/config -Dlogback.configurationFile=/config/logback.xml -jar /server.jar"] 45 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/dockerfileslim.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config, String expose) 3 | FROM amazoncorretto:11.0.21 4 | @if(config.get("multipleModule").booleanValue()){ 5 | @if(config.get("buildMaven").booleanValue()){ 6 | COPY /server/target/server.jar server.jar 7 | }else{ 8 | @with (name = config.get("artifactId").textValue() + ".jar") {COPY /server/build/libs/@name server.jar} 9 | } 10 | }else{ 11 | @if(config.get("buildMaven").booleanValue()){ 12 | COPY /target/server.jar server.jar 13 | }else{ 14 | @with (name = config.get("artifactId").textValue() + ".jar") {COPY /build/libs/@name server.jar} 15 | } 16 | } 17 | CMD ["/bin/sh","-c","exec java -Dlight-4j-config-dir=/config -Dlogback.configurationFile=/config/logback.xml -jar /server.jar"] 18 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/enumClass.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String modelPackage, String className, String enums) 2 | package @modelPackage; 3 | import java.util.Enumeration; 4 | 5 | public enum @className { 6 | @enums; 7 | 8 | } 9 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/enumInline.rocker.raw: -------------------------------------------------------------------------------- 1 | @import java.util.Map 2 | @import java.util.List 3 | @args (Map prop) 4 | @with (v = prop.get("nameWithEnum") + ".values()", value = (Map)prop.get("value")) { 5 | public enum @prop.get("nameWithEnum") { 6 | @for((i, key, item) : value) { 7 | @@JsonProperty("@item") 8 | @if (!(Boolean)prop.get("isNumEnum")) {@if (i.index() < value.size() - 1) {@key ("@item"),}@if(i.index() == value.size() - 1) {@key ("@item");}} @if ((Boolean)prop.get("isNumEnum")) {@if (i.index() < value.size() - 1) {@key (new @prop.get("type")("@item")),}@if(i.index() == value.size() - 1) {@key (new @prop.get("type")("@item"));}} 9 | } 10 | 11 | private final @prop.get("type") value; 12 | 13 | @prop.get("nameWithEnum")(@prop.get("type") value) { 14 | this.value = value; 15 | } 16 | 17 | @@Override 18 | public String toString() { 19 | return String.valueOf(value); 20 | } 21 | 22 | public static @prop.get("nameWithEnum") fromValue(String text) { 23 | for (@prop.get("nameWithEnum") b : @v) { 24 | if (String.valueOf(b.value).equals(text)) { 25 | return b; 26 | } 27 | } 28 | return null; 29 | } 30 | } 31 | 32 | private @prop.get("nameWithEnum") @prop.get("name"); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/gitignore.rocker.raw: -------------------------------------------------------------------------------- 1 | target/ 2 | bower_components/ 3 | node_modules/ 4 | dist/ 5 | .idea/ 6 | .tmp/ 7 | log/ 8 | .settings 9 | .metadata/ 10 | *.iml 11 | *.log 12 | *.tmp 13 | *.zip 14 | *.bak 15 | dependency-reduced-pom.xml 16 | 17 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 18 | hs_err_pid* 19 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/handlerService.rocker.raw: -------------------------------------------------------------------------------- 1 | @import org.apache.commons.text.StringEscapeUtils 2 | @import java.util.Map 3 | @import java.util.List 4 | @option discardLogicWhitespace=true 5 | @args (String handlerPackage, String modelPackage, String serviceName, String statusCode, String requestModelName, String example, List parameters) 6 | package @handlerPackage; 7 | 8 | import com.networknt.http.HttpStatus; 9 | import com.networknt.http.MediaType; 10 | import com.networknt.http.RequestEntity; 11 | import com.networknt.http.ResponseEntity; 12 | import com.networknt.http.HttpService; 13 | @if(requestModelName != null){import @modelPackage.@requestModelName;} 14 | import io.undertow.util.HeaderMap; 15 | import io.undertow.util.Headers; 16 | import org.slf4j.Logger; 17 | import org.slf4j.LoggerFactory; 18 | 19 | public class @serviceName implements HttpService<@if(requestModelName != null ){@requestModelName, String}else{Void, String}> { 20 | private static final Logger logger = LoggerFactory.getLogger(@with(loggerName = serviceName + ".class"){@loggerName}); 21 | 22 | @@Override 23 | public ResponseEntity invoke(RequestEntity<@if(requestModelName != null){@requestModelName}else{Void}> requestEntity) { 24 | @if(requestModelName != null) { 25 | @requestModelName requestBody = requestEntity.getBody(); 26 | logger.debug(requestBody.toString()); 27 | } 28 | HeaderMap responseHeaders = new HeaderMap(); 29 | responseHeaders.add(Headers.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); 30 | @if(example != null) { 31 | @with (e = StringEscapeUtils.escapeJson(example)) {String body = "@e";} 32 | } else { 33 | String body = ""; 34 | } 35 | ResponseEntity responseEntity = new ResponseEntity<>(body, responseHeaders, HttpStatus.OK); 36 | return responseEntity; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/kafkaProducerYml.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String kafkaTopic) 2 | acks: all 3 | retries: 3 4 | batchSize: 16384 5 | lingerMs: 1 6 | bufferMemory: 33554432 7 | keySerializer: org.apache.kafka.common.serialization.ByteArraySerializer 8 | valueSerializer: org.apache.kafka.common.serialization.ByteArraySerializer 9 | keyDeSerializer: org.apache.kafka.common.serialization.ByteArraySerializer 10 | valueDeSerializer: org.apache.kafka.common.serialization.ByteArrayDeserializer 11 | sessionTimeout: 30000 12 | autoOffsetreset: earliest 13 | enableAutoCommit: false 14 | bootstrapServers: localhost:9092 15 | topic: @kafkaTopic 16 | # every server instance will have a unique transactionId 17 | transactionId: T1000 18 | transactionTimeoutMs: 900000 19 | transactionalIdExpirationMs: 2073600000 20 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/kafkaStreamsYml.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String kafkaTopic) 2 | applicationId: hybrid-query 3 | bootstrapServers: localhost:9092 4 | processingGuarantee: exactly_once 5 | replicationFactor: 3 6 | # Only set to true right after the streams reset. 7 | cleanUp: false 8 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/kubernetes.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String org, String serviceId, String artifact, String expose, String version) 2 | #change the image tag before you deploy, if using minikube, please use any tag other than "latest" 3 | apiVersion: apps/v1 4 | kind: Deployment 5 | metadata: 6 | name: @artifact-deployment 7 | labels: 8 | app: @artifact 9 | environment: dev 10 | spec: 11 | replicas: 1 12 | selector: 13 | matchLabels: 14 | app: @artifact 15 | template: 16 | metadata: 17 | labels: 18 | app: @artifact 19 | spec: 20 | containers: 21 | - name: @artifact 22 | image: @org/@serviceId:@version 23 | ports: 24 | - containerPort: @expose 25 | resources: 26 | requests: 27 | memory: "64Mi" 28 | #0.25 cpu 29 | cpu: "250m" 30 | limits: 31 | #0.5 cpu 32 | memory: "128Mi" 33 | cpu: "500m" 34 | #cannot use httpcheck due to the server can be https 35 | readinessProbe: 36 | tcpSocket: 37 | port: @expose 38 | initialDelaySeconds: 3 39 | periodSeconds: 3 40 | livenessProbe: 41 | tcpSocket: 42 | port: @expose 43 | initialDelaySeconds: 5 44 | periodSeconds: 20 45 | --- 46 | apiVersion: v1 47 | kind: Service 48 | metadata: 49 | name: @artifact-service 50 | labels: 51 | app: @artifact 52 | spec: 53 | selector: 54 | app: @artifact 55 | type: NodePort 56 | ports: 57 | - protocol: TCP 58 | port: @expose 59 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/model/buildGradleKts.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | plugins { 4 | java 5 | } 6 | 7 | dependencies { 8 | val jacksonVersion: String by project 9 | compile("com.fasterxml.jackson.core", "jackson-databind", jacksonVersion) 10 | val slf4jVersion: String by project 11 | compile("org.slf4j", "slf4j-api", slf4jVersion) 12 | val junitVersion: String by project 13 | testImplementation("org.junit.jupiter", "junit-jupiter", junitVersion) 14 | } 15 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/model/pom.xml.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | 6 | 7 | @config.get("groupId").textValue() 8 | @config.get("artifactId").textValue() 9 | @config.get("version").textValue() 10 | ../pom.xml 11 | 12 | 13 | 4.0.0 14 | model 15 | jar 16 | Model generated from the specification that can be shared with the consumers. 17 | 18 | 19 | 20 | com.fasterxml.jackson.core 21 | jackson-databind 22 | 23 | 24 | org.slf4j 25 | slf4j-api 26 | 27 | 28 | ch.qos.logback 29 | logback-classic 30 | test 31 | 32 | 33 | org.junit.jupiter 34 | junit-jupiter 35 | test 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/model/settingsGradleKts.rocker.raw: -------------------------------------------------------------------------------- 1 | // Mark the folder as a Gradle project 2 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/parent/buildGradleKts.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | plugins { 4 | base 5 | java 6 | } 7 | 8 | java { 9 | sourceCompatibility = JavaVersion.VERSION_11 10 | targetCompatibility = JavaVersion.VERSION_11 11 | } 12 | 13 | allprojects { 14 | @with(groupId = config.get("groupId").textValue()){group = "@groupId"} 15 | @with(version = config.get("version").textValue()){version = "@version"} 16 | repositories { 17 | mavenLocal() // mavenLocal must be added first. 18 | jcenter() 19 | @if(config.get("supportAvro").booleanValue()){ 20 | maven { 21 | url = uri("http://packages.confluent.io/maven/") 22 | } 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | // Make the root project archives configuration depend on every sub-project 29 | subprojects.forEach { 30 | archives(it) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/parent/gradleProperties.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | # Versions of Frequently used Libraries 4 | kafkaVersion=3.9.1 5 | light4jVersion=2.2.2 6 | jacksonVersion=2.18.3 7 | slf4jVersion=2.0.17 8 | undertowVersion=2.3.18.Final 9 | logbackVersion=1.5.18 10 | jsonSchemaValidatorVersion=1.5.1 11 | junitVersion=5.11.3 12 | @if(config.get("supportDb").booleanValue() || config.get("supportH2ForTest").booleanValue()){ 13 | hikaricpVersion=3.1.0 14 | } 15 | @if(config.get("supportDb").booleanValue() && "oracle".equalsIgnoreCase(config.path("dbInfo").path("name").textValue())){ 16 | oracleVersion=11.2.0.3 17 | } 18 | @if(config.get("supportDb").booleanValue() && "mysql".equalsIgnoreCase(config.path("dbInfo").path("name").textValue())){ 19 | mysqlVersion=8.0.32 20 | } 21 | @if(config.get("supportDb").booleanValue() && "postgres".equalsIgnoreCase(config.path("dbInfo").path("name").textValue())){ 22 | postgresVersion=42.7.5 23 | } 24 | @if(config.get("supportH2ForTest").booleanValue()){ 25 | h2Version=1.3.176 26 | } 27 | @if(config.get("supportAvro").booleanValue()){ 28 | avroVersion=5.3.3 29 | } 30 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/parent/settingsGradleKts.rocker.raw: -------------------------------------------------------------------------------- 1 | include("model", "service", "client", "server") 2 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/project.rocker.raw: -------------------------------------------------------------------------------- 1 | @option discardLogicWhitespace=true 2 | @import com.fasterxml.jackson.databind.JsonNode 3 | @args (JsonNode config) 4 | 5 | 6 | @config.get("artifactId").textValue() 7 | 8 | 9 | 10 | 11 | 12 | org.eclipse.jdt.core.javabuilder 13 | 14 | 15 | 16 | 17 | org.eclipse.m2e.core.maven2Builder 18 | 19 | 20 | 21 | 22 | 23 | org.eclipse.jdt.core.javanature 24 | org.eclipse.m2e.core.maven2Nature 25 | 26 | 27 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/schemaRegistryYml.rocker.raw: -------------------------------------------------------------------------------- 1 | serverUrls: 2 | - http://localhost:8081 3 | autoRegisterSchema: true 4 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/server/settingsGradleKts.rocker.raw: -------------------------------------------------------------------------------- 1 | // Mark the folder as a Gradle project 2 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/service/buildGradleKts.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | plugins { 4 | java 5 | } 6 | 7 | dependencies { 8 | compile(project(":model")) 9 | val light4jVersion: String by project 10 | compile("com.networknt", "utility", light4jVersion) 11 | compile("com.networknt", "http-entity", light4jVersion) 12 | val jacksonVersion: String by project 13 | compile("com.fasterxml.jackson.core", "jackson-databind", jacksonVersion) 14 | val slf4jVersion: String by project 15 | compile("org.slf4j", "slf4j-api", slf4jVersion) 16 | val undertowVersion: String by project 17 | compile("io.undertow", "undertow-core", undertowVersion) 18 | val logbackVersion: String by project 19 | compile("ch.qos.logback", "logback-classic", logbackVersion) 20 | val junitVersion: String by project 21 | testImplementation("org.junit.jupiter", "junit-jupiter", junitVersion) 22 | } 23 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/service/pom.xml.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | 6 | 7 | @config.get("groupId").textValue() 8 | @config.get("artifactId").textValue() 9 | @config.get("version").textValue() 10 | ../pom.xml 11 | 12 | 4.0.0 13 | 14 | service 15 | jar 16 | The generated handler service interfaces that will be implemented by the service implementations in domain with business logic. 17 | 18 | 19 | 20 | @config.get("groupId").textValue() 21 | model 22 | 23 | 24 | com.networknt 25 | utility 26 | 27 | 28 | com.networknt 29 | http-entity 30 | 31 | 32 | com.fasterxml.jackson.core 33 | jackson-databind 34 | 35 | 36 | org.slf4j 37 | slf4j-api 38 | 39 | 40 | ch.qos.logback 41 | logback-classic 42 | test 43 | 44 | 45 | org.junit.jupiter 46 | junit-jupiter 47 | test 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/service/settingsGradleKts.rocker.raw: -------------------------------------------------------------------------------- 1 | // Mark the folder as a Gradle project 2 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/single/gradleProperties.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | # Versions of Frequently used Libraries 4 | kafkaVersion=3.9.1 5 | light4jVersion=2.2.2 6 | jacksonVersion=2.18.3 7 | slf4jVersion=2.0.17 8 | undertowVersion=2.3.18.Final 9 | logbackVersion=1.5.18 10 | jsonSchemaValidatorVersion=1.5.1 11 | junitVersion=5.11.3 12 | @if(config.get("supportDb").booleanValue() || config.get("supportH2ForTest").booleanValue()){ 13 | hikaricpVersion=3.1.0 14 | } 15 | @if(config.get("supportDb").booleanValue() && "oracle".equalsIgnoreCase(config.path("dbInfo").path("name").textValue())){ 16 | oracleVersion=11.2.0.3 17 | } 18 | @if(config.get("supportDb").booleanValue() && "mysql".equalsIgnoreCase(config.path("dbInfo").path("name").textValue())){ 19 | mysqlVersion=8.0.32 20 | } 21 | @if(config.get("supportDb").booleanValue() && "postgres".equalsIgnoreCase(config.path("dbInfo").path("name").textValue())){ 22 | postgresVersion=42.7.5 23 | } 24 | @if(config.get("supportH2ForTest").booleanValue()){ 25 | h2Version=1.3.176 26 | } 27 | @if(config.get("supportAvro").booleanValue()){ 28 | avroVersion=5.3.3 29 | } 30 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/single/settingsGradleKts.rocker.raw: -------------------------------------------------------------------------------- 1 | // Mark the folder as a Gradle project 2 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/rest/testServer.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String handlerPackage) 2 | package @handlerPackage; 3 | 4 | import com.networknt.server.Server; 5 | import com.networknt.server.ServerConfig; 6 | import org.junit.jupiter.api.extension.AfterAllCallback; 7 | import org.junit.jupiter.api.extension.BeforeAllCallback; 8 | import org.junit.jupiter.api.extension.ExtensionContext; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.util.concurrent.atomic.AtomicInteger; 13 | 14 | public class TestServer implements BeforeAllCallback, AfterAllCallback { 15 | static final Logger logger = LoggerFactory.getLogger(TestServer.class); 16 | 17 | private static final AtomicInteger refCount = new AtomicInteger(0); 18 | 19 | private static final TestServer instance = new TestServer(); 20 | 21 | private TestServer() { 22 | logger.info("TestServer is constructed!"); 23 | } 24 | 25 | public static TestServer getInstance () { 26 | return instance; 27 | } 28 | 29 | @@Override 30 | public void beforeAll(ExtensionContext context) throws Exception { 31 | try { 32 | if (refCount.get() == 0) { 33 | Server.start(); 34 | } 35 | } 36 | finally { 37 | refCount.getAndIncrement(); 38 | } 39 | 40 | Runtime.getRuntime().addShutdownHook(new Thread(() -> clean())); 41 | } 42 | 43 | @@Override 44 | public void afterAll(ExtensionContext context) throws Exception { 45 | clean(); 46 | } 47 | 48 | protected void clean() { 49 | refCount.getAndDecrement(); 50 | if (refCount.get() == 0) { 51 | Server.stop(); 52 | } 53 | 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/README.md.rocker.raw: -------------------------------------------------------------------------------- 1 | # OpenAPI Kotlin Light-4J Server 2 | 3 | ## Start server 4 | 5 | On Linux or Mac, the gradlew need to change the mode to executable. 6 | 7 | ``` 8 | chmod +x gradlew 9 | ``` 10 | 11 | To build the server 12 | 13 | ``` 14 | ./gradlew build 15 | ``` 16 | 17 | 18 | To start the server 19 | 20 | ``` 21 | ./gradlew run 22 | ``` 23 | 24 | ## Test 25 | 26 | By default, all endpoints are protected by OAuth jwt token verifier. It can be turned off with config change through for development. 27 | 28 | 29 | In order to access the server, there is a long lived token below issued by my 30 | oauth2 server [light-oauth2](https://github.com/networknt/light-oauth2) 31 | 32 | ``` 33 | Bearer eyJraWQiOiIxMDAiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJ1cm46Y29tOm5ldHdvcmtudDpvYXV0aDI6djEiLCJhdWQiOiJ1cm46Y29tLm5ldHdvcmtudCIsImV4cCI6MTc5MDAzNTcwOSwianRpIjoiSTJnSmdBSHN6NzJEV2JWdUFMdUU2QSIsImlhdCI6MTQ3NDY3NTcwOSwibmJmIjoxNDc0Njc1NTg5LCJ2ZXJzaW9uIjoiMS4wIiwidXNlcl9pZCI6InN0ZXZlIiwidXNlcl90eXBlIjoiRU1QTE9ZRUUiLCJjbGllbnRfaWQiOiJmN2Q0MjM0OC1jNjQ3LTRlZmItYTUyZC00YzU3ODc0MjFlNzIiLCJzY29wZSI6WyJ3cml0ZTpwZXRzIiwicmVhZDpwZXRzIl19.mue6eh70kGS3Nt2BCYz7ViqwO7lh_4JSFwcHYdJMY6VfgKTHhsIGKq2uEDt3zwT56JFAePwAxENMGUTGvgceVneQzyfQsJeVGbqw55E9IfM_uSM-YcHwTfR7eSLExN4pbqzVDI353sSOvXxA98ZtJlUZKgXNE1Ngun3XFORCRIB_eH8B0FY_nT_D1Dq2WJrR-re-fbR6_va95vwoUdCofLRa4IpDfXXx19ZlAtfiVO44nw6CS8O87eGfAm7rCMZIzkWlCOFWjNHnCeRsh7CVdEH34LF-B48beiG5lM7h4N12-EME8_VDefgMjZ8eqs1ICvJMxdIut58oYbdnkwTjkA 34 | ``` 35 | 36 | Postman is the best tool to test REST APIs 37 | 38 | Add "Authorization" header with value as above token and a dummy message will return from the generated stub. 39 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/appStatusYml.rocker.raw: -------------------------------------------------------------------------------- 1 | # Put your application specific error code into this file instead of status.yml 2 | # This file will be merge into the status.yml during the server startup. 3 | # Please allocate the range for the application error codes within your organization 4 | # to ensure no reused for an error code across the organization for tracing. 5 | 6 | # 20000-29999 common error codes within your business domain. 7 | # It is highly recommended to have common error codes shared within your organization 8 | # or your line of business and put them into the externalized status.yml file. 9 | 10 | # 30000-99999 customize error code that cannot be found in common range. 11 | # Only use this section if you cannot make your error code into 20000-29999 range on time. 12 | # In this case, the error code defined here will be merged to the status.yml during startup. 13 | # To ensure there is no reuse of error code, this application will use the range 30000-31000. 14 | ERR30000: 15 | statusCode: 400 16 | code: ERR30000 17 | message: FIRST_ERROR_IN_APP 18 | description: This is is the first error in this example application. 19 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/buildSh.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config, String serviceId) 3 | #!/bin/bash 4 | 5 | set -ex 6 | 7 | VERSION=$1 8 | IMAGE_NAME="@config.get("dockerOrganization").textValue()/@serviceId" 9 | 10 | showHelp() { 11 | echo " " 12 | echo "Error: $1" 13 | echo " " 14 | echo " build.sh [VERSION]" 15 | echo " " 16 | echo " where [VERSION] version of the docker image that you want to publish (example: 0.0.1)" 17 | echo " " 18 | echo " example: ./build.sh 0.0.1" 19 | echo " " 20 | } 21 | 22 | build() { 23 | echo "Building ..." 24 | @if(config.get("buildMaven").booleanValue()){ 25 | mvn clean install -Prelease 26 | }else{ 27 | ./gradlew clean build 28 | } 29 | echo "Successfully built!" 30 | } 31 | 32 | cleanup() { 33 | if [[ "$(docker images -q $IMAGE_NAME 2> /dev/null)" != "" ]]; then 34 | echo "Removing old $IMAGE_NAME images" 35 | docker images | grep $IMAGE_NAME | awk '{print $3}' | xargs docker rmi -f 36 | echo "Cleanup completed!" 37 | fi 38 | } 39 | 40 | publish() { 41 | echo "Building Docker image with version $VERSION" 42 | docker build -t $IMAGE_NAME:$VERSION -t $IMAGE_NAME:latest -f ./docker/Dockerfile . --no-cache=true 43 | docker build -t $IMAGE_NAME:$VERSION-slim -f ./docker/Dockerfile-Slim . --no-cache=true 44 | echo "Images built with version $VERSION" 45 | echo "Pushing image to DockerHub" 46 | docker push $IMAGE_NAME -a 47 | echo "Image successfully published!" 48 | } 49 | 50 | if [ -z $VERSION ]; then 51 | showHelp "[VERSION] parameter is missing" 52 | exit 53 | fi 54 | 55 | build; 56 | cleanup; 57 | publish; 58 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/dockerfile.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config, String expose) 3 | FROM azul/zulu-openjdk-alpine:11 as packager 4 | 5 | RUN { \ 6 | java --version ; \ 7 | echo "jlink version:" && \ 8 | $JAVA_HOME/bin/jlink --version ; \ 9 | } 10 | 11 | ENV JAVA_MINIMAL=/opt/jre 12 | 13 | # build modules distribution 14 | RUN $JAVA_HOME/bin/jlink \ 15 | --verbose \ 16 | --add-modules \ 17 | java.base,java.sql,java.naming,java.desktop,java.xml,jdk.crypto.cryptoki,jdk.crypto.ec,jdk.unsupported,java.management,java.security.jgss,java.net.http \ 18 | --compress 2 \ 19 | --strip-debug \ 20 | --no-header-files \ 21 | --no-man-pages \ 22 | --output "$JAVA_MINIMAL" 23 | 24 | # Second stage, add only our minimal "JRE" distr and our app 25 | FROM alpine 26 | 27 | ENV JAVA_MINIMAL=/opt/jre 28 | ENV PATH="$PATH:$JAVA_MINIMAL/bin" 29 | 30 | COPY --from=packager "$JAVA_MINIMAL" "$JAVA_MINIMAL" 31 | @if(config.get("buildMaven").booleanValue()){ 32 | @with (name = config.get("artifactId").textValue() + "-" + config.get("version").textValue() + ".jar") {COPY /target/@name server.jar} 33 | }else{ 34 | @with (name = config.get("artifactId").textValue() + ".jar") {COPY /build/libs/@name server.jar} 35 | } 36 | CMD ["/bin/sh","-c","exec java -Dlight-4j-config-dir=/config -Dlogback.configurationFile=/config/logback.xml -jar /server.jar"] 37 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/dockerfileslim.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config, String expose) 3 | FROM openjdk:11.0.3-slim 4 | @if(config.get("buildMaven").booleanValue()){ 5 | @with (name = config.get("artifactId").textValue() + "-" + config.get("version").textValue() + ".jar") {COPY /target/@name server.jar} 6 | }else{ 7 | @with (name = config.get("artifactId").textValue() + ".jar") {COPY /build/libs/@name server.jar} 8 | } 9 | CMD ["/bin/sh","-c","exec java -Dlight-4j-config-dir=/config -Dlogback.configurationFile=/config/logback.xml -jar /server.jar"] 10 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/enumClass.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String modelPackage, String className, String enums) 2 | package @modelPackage; 3 | 4 | enum class @className { 5 | @enums 6 | } 7 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/enumInline.rocker.raw: -------------------------------------------------------------------------------- 1 | @import java.util.Map 2 | @import java.util.List 3 | @args (Map prop) 4 | @with (v = prop.get("nameWithEnum") + ".values()", value = (List)prop.get("value")) { 5 | public enum @prop.get("nameWithEnum") { 6 | @for((i, item) : value) { 7 | @with(u = item.toString().toUpperCase().replaceAll("-", "_")) {@if (i.index() < value.size() - 1) {@u ("@item"),}@if(i.index() == value.size() - 1) {@u ("@item");}} 8 | } 9 | 10 | private final @prop.get("type") value; 11 | 12 | @prop.get("nameWithEnum")(@prop.get("type") value) { 13 | this.value = value; 14 | } 15 | 16 | @@Override 17 | public String toString() { 18 | return String.valueOf(value); 19 | } 20 | 21 | public static @prop.get("nameWithEnum") fromValue(String text) { 22 | for (@prop.get("nameWithEnum") b : @v) { 23 | if (String.valueOf(b.value).equals(text)) { 24 | return b; 25 | } 26 | } 27 | return null; 28 | } 29 | } 30 | 31 | private @prop.get("nameWithEnum") @prop.get("name"); 32 | 33 | } 34 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/gitignore.rocker.raw: -------------------------------------------------------------------------------- 1 | target/ 2 | bower_components/ 3 | node_modules/ 4 | dist/ 5 | build/ 6 | out/ 7 | .idea/ 8 | .tmp/ 9 | .project 10 | .classpath 11 | .settings 12 | .gradle 13 | .metadata/ 14 | *.iml 15 | *.log 16 | *.tmp 17 | *.zip 18 | *.bak 19 | *.versionsBackup 20 | dependency-reduced-pom.xml 21 | 22 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 23 | hs_err_pid* 24 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/gradleProperties.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | # Versions of Frequently used Libraries 4 | kafkaVersion=3.9.1 5 | light4jVersion=2.2.2 6 | jacksonVersion=2.18.3 7 | undertowVersion=2.3.18.Final 8 | logbackVersion=1.5.18 9 | jsonSchemaValidatorVersion=1.5.1 10 | junitVersion=5.3.1 11 | kotlinLoggingVersion=1.6.22 12 | assertkVersion=0.13 13 | @if(config.get("supportDb").booleanValue() || config.get("supportH2ForTest").booleanValue()){ 14 | hikaricpVersion=3.1.0 15 | } 16 | @if(config.get("supportDb").booleanValue() && "oracle".equalsIgnoreCase(config.path("dbInfo").path("name").textValue())){ 17 | oracleVersion=11.2.0.3 18 | } 19 | @if(config.get("supportDb").booleanValue() && "mysql".equalsIgnoreCase(config.path("dbInfo").path("name").textValue())){ 20 | mysqlVersion=8.0.32 21 | } 22 | @if(config.get("supportDb").booleanValue() && "postgres".equalsIgnoreCase(config.path("dbInfo").path("name").textValue())){ 23 | postgresVersion=42.7.5 24 | } 25 | @if(config.get("supportH2ForTest").booleanValue()){ 26 | h2Version=1.3.176 27 | } 28 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/handler.rocker.raw: -------------------------------------------------------------------------------- 1 | @import org.apache.commons.text.StringEscapeUtils 2 | @import java.util.Map 3 | @import java.util.List 4 | @option discardLogicWhitespace=true 5 | @args (String handlerPackage, String className, String example, List parameters) 6 | package @handlerPackage 7 | 8 | import com.networknt.handler.LightHttpHandler 9 | import io.undertow.server.HttpServerExchange 10 | import io.undertow.util.HttpString 11 | 12 | class @className : LightHttpHandler { 13 | @if(parameters != null && !parameters.isEmpty()) {/**@for (parameter : parameters) { 14 | * @@param @?parameter.get("name") @if(parameter.get("type") != null) 15 | { @with (String typeStr = ((String)parameter.get("type")).substring(0, 1).toUpperCase()+((String)parameter.get("type")).substring(1)) 16 | { @?typeStr }} @if ( parameter.get("required").equals("true") ) {@@Required } else{@@Optional }@if(parameter.get("minLength") != null){minLength:@parameter.get("minLength");}@if(parameter.get("maxLength") != null) {maxLength:@parameter.get("maxLength");}@if(parameter.get("description") != null ){ 17 | * @parameter.get("description")}} 18 | */} 19 | @@Throws(Exception::class) 20 | override fun handleRequest(exchange: HttpServerExchange) { 21 | @if(example != null) { 22 | exchange.responseHeaders.add(HttpString("Content-Type"), "application/json") 23 | @with (e = StringEscapeUtils.escapeJson(example)) {exchange.responseSender.send("@e")} 24 | } else { 25 | exchange.endExchange() 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/handlerTest.rocker.raw: -------------------------------------------------------------------------------- 1 | @import java.util.Map 2 | @import java.util.stream.Collectors 3 | @args (String handlerPackage, Map map) 4 | package @handlerPackage 5 | import assertk.all 6 | import assertk.assertThat 7 | import mu.KotlinLogging 8 | import org.junit.jupiter.api.Test 9 | import org.junit.jupiter.api.extension.ExtendWith 10 | 11 | @with (className = map.get("handlerName") + "Test", 12 | method = map.get("handlerName") + "Test()", 13 | handlerName = map.get("handlerName"), 14 | loggerName = map.get("handlerName") + "Test" + ".class", 15 | httpMethod = map.get("method"), 16 | hasBody = ("POST".equals(map.get("method").toString()) || "PUT".equals(map.get("method").toString()) || "PATCH".equals(map.get("method").toString())), 17 | path = map.get("normalizedPath")) { 18 | @@ExtendWith(LightTestServer::class) 19 | class @className { 20 | companion object { 21 | val log = KotlinLogging.logger {} 22 | } 23 | 24 | @@Test 25 | fun `test @method @handlerName success` () { 26 | /* 27 | @if(hasBody) { 28 | val response = LightTestServer.makePostRequest("@path", "request body to be replaced") 29 | } else { 30 | val response = LightTestServer.makeGetRequest("@path") 31 | } 32 | assertThat(response).all { 33 | rcIsEqualTo(200) 34 | bodyContains("any string from the body to be replaced") 35 | } 36 | */ 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/junitPlatformProperties.rocker.raw: -------------------------------------------------------------------------------- 1 | # suppress inspection "UnusedProperty" 2 | junit.jupiter.testinstance.lifecycle.default=per_class 3 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/maskYml.rocker.raw: -------------------------------------------------------------------------------- 1 | description: mask configuration for different type of inputs 2 | string: 3 | uri: 4 | # password=[^&]*: password=****** 5 | # number=\d{1,16}: number=---------------- 6 | # sin=\d{1,9}: sin=masked 7 | regex: 8 | queryParameter: 9 | # accountNo: "(.*)" 10 | requestHeader: 11 | # header1: "(.*)" 12 | # header2: "(.*)" 13 | responseHeader: 14 | # header3: "(.*)" 15 | requestCookies: 16 | # userName: "(.*)" 17 | responseCookies: 18 | # sensitiveData: "(.*)" 19 | json: 20 | requestBody: 21 | # "$.*.email": "(.*)" 22 | # "$.product[*].item[*].name": "(.*)" 23 | responseBody: 24 | # "$.product[*].item[*].name": "(.*)" 25 | # "$.product[*].item[*].name[0]": "(.*)" 26 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/model.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String modelPackage, String className) 2 | package @modelPackage; 3 | import java.io.Serializable; 4 | 5 | public class @className implements Serializable { 6 | public @className () { 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/openapi/config.rocker.raw: -------------------------------------------------------------------------------- 1 | #---------------------------------------------------------------------------------------------------------------- 2 | # Scalable Config file 3 | # 4 | # This file serves as a configuration extension platform. Functions are list below: 5 | # 6 | # [1] exclusionConfigFileList: this configuration will be used by the light-4j/config module, when reading 7 | # config files. it allows the listing of files which will be excluded from parameterized values set at 8 | # the command-line or in a values.yml file 9 | # Notes: 10 | # File name included in the list will be excluded 11 | # If the file is not provided, the config module will safely ignore it 12 | # Simply list the config file names without extensions(.json, .yaml, .yml) 13 | #---------------------------------------------------------------------------------------------------------------- 14 | exclusionConfigFileList: 15 | - openapi 16 | - values 17 | - status 18 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/openapi/service.yml.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | # Singleton service factory configuration/IoC injection 4 | singletons: 5 | # StartupHookProvider implementations, there are one to many and they are called in the same sequence defined. 6 | # - com.networknt.server.StartupHookProvider: 7 | # If you are using mask module to remove sensitive info before logging, uncomment the following line. 8 | # - com.networknt.server.JsonPathStartupHookProvider 9 | # - com.networknt.server.Test1StartupHook 10 | # - com.networknt.server.Test2StartupHook 11 | # ShutdownHookProvider implementations, there are one to many and they are called in the same sequence defined. 12 | # - com.networknt.server.ShutdownHookProvider: 13 | # - com.networknt.server.Test1ShutdownHook 14 | @if(config.get("supportDb").booleanValue()){ 15 | @with (driverClassName = config.path("dbInfo").path("driverClassName").textValue(), jdbcUrl=config.path("dbInfo").path("jdbcUrl").textValue(), username=config.path("dbInfo").path("username").textValue(), password=config.path("dbInfo").path("password").textValue()) { 16 | - javax.sql.DataSource: 17 | - com.zaxxer.hikari.HikariDataSource: 18 | DriverClassName: @driverClassName 19 | jdbcUrl: @jdbcUrl 20 | username: @username 21 | password: @password 22 | maximumPoolSize: 10 23 | useServerPrepStmts: true 24 | cachePrepStmts: true 25 | cacheCallableStmts: true 26 | prepStmtCacheSize: 10 27 | prepStmtCacheSqlLimit: 2048 28 | connectionTimeout: 2000 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/openapiSecurity.yml.rocker.raw: -------------------------------------------------------------------------------- 1 | # Security configuration for openapi-security in light-rest-4j. It is a specific config 2 | # for OpenAPI framework security. It is introduced to support multiple frameworks in the 3 | # same server instance. If this file cannot be found, the generic security.yml will be 4 | # loaded for backward compatibility. 5 | --- 6 | # Enable JWT verification flag. 7 | enableVerifyJwt: false 8 | 9 | # Enable JWT scope verification. Only valid when enableVerifyJwt is true. 10 | enableVerifyScope: true 11 | 12 | # User for test only. should be always be false on official environment. 13 | enableMockJwt: false 14 | 15 | # JWT signature public certificates. kid and certificate path mappings. 16 | jwt: 17 | certificate: 18 | '100': primary.crt 19 | '101': secondary.crt 20 | clockSkewInSeconds: 60 21 | 22 | # Enable or disable JWT token logging 23 | logJwtToken: true 24 | 25 | # Enable or disable client_id, user_id and scope logging. 26 | logClientUserScope: false 27 | 28 | # Enable JWT token cache to speed up verification. This will only verify expired time 29 | # and skip the signature verification as it takes more CPU power and long time. 30 | enableJwtCache: true 31 | 32 | # If you are using light-oauth2, then you don't need to have oauth subfolder for public 33 | # key certificate to verify JWT token, the key will be retrieved from key endpoint once 34 | # the first token is arrived. Default to false for dev environment without oauth2 server 35 | # or official environment that use other OAuth 2.0 providers. 36 | bootstrapFromKeyService: false 37 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/openapiValidator.yml.rocker.raw: -------------------------------------------------------------------------------- 1 | # This is specific OpenAPI validator configuration file. It is introduced to support multiple 2 | # frameworks in the same server instance and it is recommended. If this file cannot be found, 3 | # the generic validator.yml will be loaded as a fallback. 4 | --- 5 | # Enable request validation. Response validation is not done on the server but client. 6 | enabled: ${openapi-validator.enabled:true} 7 | # Log error message if validation error occurs 8 | logError: ${openapi-validator.logError:true} 9 | # Skip body validation set to true if used in light-router, light-proxy and light-spring-boot. 10 | skipBodyValidation: ${openapi-validator.skipBodyValidation:false} 11 | # Enable response validation. 12 | validateResponse: ${openapi-validator.validateResponse:false} 13 | # When a field is set as nullable in the OpenAPI specification, the schema validator validates that it is nullable 14 | # however continues with validation against the nullable field 15 | 16 | # If handleNullableField is set to true && incoming field is nullable && value is field: null --> succeed 17 | # If handleNullableField is set to false && incoming field is nullable && value is field: null --> it is up to the type 18 | # validator using the SchemaValidator to handle it. 19 | handleNullableField: ${openapi-validator.handleNullableField:true} 20 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/pojo.rocker.raw: -------------------------------------------------------------------------------- 1 | @option discardLogicWhitespace=true 2 | @import java.util.Map 3 | @import java.util.List 4 | @args (String modelPackage, String className, String classVarName, List> props) 5 | package @modelPackage; 6 | data class @className ( 7 | @for ((i, prop): props) { 8 | @if(i.index() < props.size() - 1) {val @prop.get("name"): @prop.get("type"),} 9 | @if(i.index() == props.size() - 1) {val @prop.get("name"): @prop.get("type")} 10 | } 11 | ) 12 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/settingsGradleKts.rocker.raw: -------------------------------------------------------------------------------- 1 | @import com.fasterxml.jackson.databind.JsonNode 2 | @args (JsonNode config) 3 | rootProject.name = "@config.get("artifactId").textValue()" 4 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/swaggerValidator.yml.rocker.raw: -------------------------------------------------------------------------------- 1 | # This is specific Swagger validator configuration file. It is introduced to support multiple 2 | # frameworks in the same server instance and it is recommended. If this file cannot be found, 3 | # the generic validator.yml will be loaded as a fallback. 4 | --- 5 | # Enable request validation. Response validation is not done on the server but client. 6 | enabled: true 7 | # Log error message if validation error occurs 8 | logError: true 9 | # Skip body validation set to true if used in light-router, light-proxy and light-spring-boot. 10 | skipBodyValidation: false 11 | -------------------------------------------------------------------------------- /light-rest-4j/src/main/resources/templates/restkotlin/testServer.rocker.raw: -------------------------------------------------------------------------------- 1 | @args (String handlerPackage) 2 | package @handlerPackage; 3 | 4 | import com.networknt.server.Server; 5 | import org.junit.rules.ExternalResource; 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import java.util.concurrent.atomic.AtomicInteger; 9 | 10 | import com.networknt.server.Server; 11 | import com.networknt.server.ServerConfig; 12 | 13 | public class TestServer extends ExternalResource { 14 | static final Logger logger = LoggerFactory.getLogger(TestServer.class); 15 | 16 | private static final AtomicInteger refCount = new AtomicInteger(0); 17 | private static Server server; 18 | 19 | private static final TestServer instance = new TestServer(); 20 | 21 | public static TestServer getInstance () { 22 | return instance; 23 | } 24 | 25 | private TestServer() { 26 | 27 | } 28 | 29 | @@Override 30 | protected void before() { 31 | try { 32 | if (refCount.get() == 0) { 33 | Server.init(); 34 | } 35 | } 36 | finally { 37 | refCount.getAndIncrement(); 38 | } 39 | } 40 | 41 | @@Override 42 | protected void after() { 43 | refCount.getAndDecrement(); 44 | if (refCount.get() == 0) { 45 | Server.stop(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /light-rest-4j/src/test/java/com/networknt/codegen/ConfigTest.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen; 2 | 3 | import com.fasterxml.jackson.databind.JsonNode; 4 | 5 | import org.junit.jupiter.api.Test; 6 | import org.junit.jupiter.api.BeforeAll; 7 | import static org.junit.jupiter.api.Assertions.*; 8 | 9 | import java.io.IOException; 10 | 11 | public class ConfigTest { 12 | public static String configName = "/config.json"; 13 | public static String configYamlName = "/config.yaml"; 14 | public static JsonNode anyConfig = null; 15 | public static JsonNode anyYamlConfig = null; 16 | 17 | @BeforeAll 18 | public static void setUp() throws IOException { 19 | // load config file 20 | anyConfig = Generator.jsonMapper.readTree(OpenApiLightGeneratorTest.class.getResourceAsStream(configName)); 21 | anyYamlConfig = Generator.yamlMapper.readTree(OpenApiLightGeneratorTest.class.getResourceAsStream(configYamlName)); 22 | } 23 | 24 | @Test 25 | public void testDbName() { 26 | assertEquals("mysql", anyConfig.path("dbInfo").path("name").textValue()); 27 | } 28 | 29 | @Test 30 | public void testDbSupport() { 31 | assertTrue(anyConfig.get("supportDb").booleanValue()); 32 | } 33 | 34 | @Test 35 | public void testUseLightProxy() { 36 | assertTrue(anyYamlConfig.get("useLightProxy").booleanValue()); 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /light-rest-4j/src/test/java/com/networknt/codegen/rest/OpenApiSpecGeneratorTest.java: -------------------------------------------------------------------------------- 1 | package com.networknt.codegen.rest; 2 | 3 | import java.io.IOException; 4 | 5 | import com.fasterxml.jackson.databind.JsonNode; 6 | import com.networknt.codegen.Generator; 7 | import org.junit.jupiter.api.Disabled; 8 | import org.junit.jupiter.api.Test; 9 | 10 | import com.networknt.codegen.OpenApiLightGeneratorTest; 11 | 12 | @Disabled 13 | public class OpenApiSpecGeneratorTest { 14 | private static final String configName = "/config.json"; 15 | private static final String outputDir = "/tmp/codegen/"; 16 | 17 | @Test 18 | public void test() throws IOException { 19 | JsonNode config = Generator.jsonMapper.readTree(OpenApiLightGeneratorTest.class.getResourceAsStream(configName)); 20 | 21 | OpenApiSpecGenerator generator = new OpenApiSpecGenerator(); 22 | 23 | generator.generate(outputDir, null, config); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /light-rest-4j/src/test/resources/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "petstore", 3 | "version": "1.0.1", 4 | "groupId": "com.networknt", 5 | "artifactId": "petstore", 6 | "rootPackage": "com.networknt.petstore", 7 | "handlerPackage":"com.networknt.petstore.handler", 8 | "modelPackage":"com.networknt.petstore.model", 9 | "overwriteHandler": false, 10 | "overwriteHandlerTest": false, 11 | "overwriteModel": true, 12 | "useLightProxy": false, 13 | "httpPort": 8080, 14 | "enableHttp": true, 15 | "httpsPort": 8443, 16 | "enableHttps": false, 17 | "enableHttp2": false, 18 | "enableRegistry": false, 19 | "supportDb": true, 20 | "dbInfo": { 21 | "name": "mysql", 22 | "driverClassName": "com.mysql.jdbc.Driver", 23 | "jdbcUrl": "jdbc:mysql://mysqldb:3306/oauth2?useSSL=false", 24 | "username": "root", 25 | "password": "my-secret-pw" 26 | }, 27 | "supportH2ForTest": false, 28 | "supportClient": false, 29 | "dockerOrganization": "networknt", 30 | "enableParamDescription": false, 31 | "generateEnvVars": { 32 | "generate": true, 33 | "skipArray": true, 34 | "skipMap": true, 35 | "exclude": [ 36 | "handler.yml", 37 | "values.yml" 38 | ] 39 | }, 40 | "specGeneration": { 41 | "modelPackages": "com.networknt.petstore.model", 42 | "mergeTo": "/tmp/codegen/openapi.json", 43 | "outputFormat": "yaml, json", 44 | "outputFilename": "openapi_gen_test" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /light-rest-4j/src/test/resources/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 3.0.1 3 | groupId: com.networknt.example 4 | artifactId: petstore 5 | rootPackage: com.networknt.petstore 6 | handlerPackage: com.networknt.petstore.handler 7 | modelPackage: com.networknt.petstore.model 8 | overwriteHandler: true 9 | overwriteHandlerTest: true 10 | overwriteModel: true 11 | useLightProxy: true 12 | httpPort: 8080 13 | enableHttp: false 14 | httpsPort: 8443 15 | enableHttps: true 16 | enableHttp2: true 17 | enableRegistry: false 18 | supportDb: false 19 | supportH2ForTest: false 20 | supportClient: true 21 | dockerOrganization: networknt 22 | -------------------------------------------------------------------------------- /light-rest-4j/src/test/resources/configKafka.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "petstore", 3 | "version": "1.0.1", 4 | "groupId": "com.networknt", 5 | "artifactId": "petstore", 6 | "rootPackage": "com.networknt.petstore", 7 | "handlerPackage":"com.networknt.petstore.handler", 8 | "modelPackage":"com.networknt.petstore.model", 9 | "overwriteHandler": false, 10 | "overwriteHandlerTest": false, 11 | "overwriteModel": true, 12 | "httpPort": 8080, 13 | "enableHttp": true, 14 | "httpsPort": 8443, 15 | "enableHttps": false, 16 | "enableRegistry": false, 17 | "supportDb": true, 18 | "kafkaProducer": true, 19 | "kafkaConsumer": false, 20 | "supportAvro": true, 21 | "kafkaTopic": "event", 22 | "dbInfo": { 23 | "name": "mysql", 24 | "driverClassName": "com.mysql.jdbc.Driver", 25 | "jdbcUrl": "jdbc:mysql://mysqldb:3306/oauth2?useSSL=false", 26 | "username": "root", 27 | "password": "my-secret-pw" 28 | }, 29 | "supportH2ForTest": false, 30 | "supportClient": false, 31 | "dockerOrganization": "networknt", 32 | "generateEnvVars": { 33 | "generate": true, 34 | "skipArray": true, 35 | "skipMap": true, 36 | "exclude": [ 37 | "handler.yml", 38 | "values.yml" 39 | ] 40 | }, 41 | "specGeneration": { 42 | "modelPackages": "com.networknt.petstore.model", 43 | "mergeTo": "/tmp/codegen/openapi.json", 44 | "outputFormat": "yaml, json", 45 | "outputFilename": "openapi_gen_test" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /light-rest-4j/src/test/resources/configProxyLambda.json: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "petstore", 3 | "version": "1.0.1", 4 | "groupId": "com.networknt", 5 | "artifactId": "petstore", 6 | "rootPackage": "com.networknt.petstore", 7 | "handlerPackage":"com.networknt.petstore.handler", 8 | "modelPackage":"com.networknt.petstore.model", 9 | "useLightProxy": true, 10 | "launchType": "EC2", 11 | "publicVpc": true, 12 | "packageDocker": false, 13 | "region": "us-east-2", 14 | "overwriteHandler": true, 15 | "overwriteHandlerTest": true, 16 | "overwriteModel": true, 17 | "enableRegistry": false, 18 | "enableParamDescription": false, 19 | "generateModelOnly": false 20 | } 21 | -------------------------------------------------------------------------------- /light-rest-4j/src/test/resources/configlambda.json: -------------------------------------------------------------------------------- 1 | { 2 | "artifactId": "petstore", 3 | "version": "1.0.1", 4 | "groupId": "com.networknt", 5 | "rootPackage": "com.networknt.petstore", 6 | "handlerPackage":"com.networknt.petstore.handler", 7 | "modelPackage":"com.networknt.petstore.model", 8 | "packageDocker": false, 9 | "useLightProxy": false, 10 | "overwriteHandler": true, 11 | "overwriteHandlerTest": true, 12 | "overwriteModel": true, 13 | "generateModelOnly": false 14 | } 15 | -------------------------------------------------------------------------------- /light-rest-4j/src/test/resources/configlambdamaven.json: -------------------------------------------------------------------------------- 1 | { 2 | "projectName": "petstore", 3 | "version": "1.0.1", 4 | "groupId": "com.networknt", 5 | "artifactId": "petstore", 6 | "rootPackage": "com.networknt.petstore", 7 | "handlerPackage":"com.networknt.petstore.handler", 8 | "modelPackage":"com.networknt.petstore.model", 9 | "buildMaven": true, 10 | "useLightProxy": true, 11 | "launchType": "EC2", 12 | "publicVpc": true, 13 | "packageDocker": false, 14 | "region": "us-east-2", 15 | "overwriteHandler": true, 16 | "overwriteHandlerTest": true, 17 | "overwriteModel": true, 18 | "enableRegistry": false, 19 | "generateModelOnly": false 20 | } 21 | -------------------------------------------------------------------------------- /light-rest-4j/src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | --------------------------------------------------------------------------------