diff --git a/README.md b/README.md index 53cc259..44c9bd8 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,36 @@ -[Developer Chat](https://gitter.im/networknt/microservices-framework-benchmark) | +[Stack Overflow](https://stackoverflow.com/questions/tagged/light-4j) | +[Google Group](https://groups.google.com/forum/#!forum/light-4j) | +[Gitter Chat](https://gitter.im/networknt/microservices-framework-benchmark) | +[Subreddit](https://www.reddit.com/r/lightapi/) | +[Youtube Channel](https://www.youtube.com/channel/UCHCRMWJVXw8iB7zKxF55Byw) | [Documentation](https://networknt.github.io/microservices-framework-benchmark) | -[Contribution Guide](CONTRIBUTING.md) | +[Contribution Guide](https://doc.networknt.com/contribute/) | | Framework | Language | Max Throughput | Avg Latency | Transfer | | ------------ | ---------: | -------------: | ----------: | -------: | | Go FastHttp | Go | 1,396,685.83 | 99.98ms | 167.83MB | -| Light Java | Java | 1,344,512.65 | 2.36ms | 169.25MB | +| Light-4j | Java | 1,344,512.65 | 2.36ms | 169.25MB | | ActFramework | Java | 945,429.13 | 2.22ms | 136.15MB | | Go Iris | Go | 828,035.66 | 5.77ms | 112.92MB | | Vertx | Java | 803,311.31 | 2.37ms | 98.06MB | | Node-uws | Node/C++ | 589,924.44 | 7.22ms | 28.69MB | | Dotnet | .Net | 486,216.93 | 2.93ms | 57.03MB | -| Jooby/Undertow | Java | 362018.07 | 3.95ms | 47.99MB | -| SeedStack-Filter | Java | 343416.33 | 4.41ms | 51.42MB | +| Jooby/Undertow | Java | 362,018.07 | 3.95ms | 47.99MB | +| SeedStack-Filter | Java | 343,416.33 | 4.41ms | 51.42MB | | Spring Boot Reactor | Java | 243,240.17 | 7.44ms | 17.86MB | | Pippo-Undertow | Java | 216,254.56 | 9.80ms | 31.35MB | | Spark | Java | 194,553.83 | 13.85ms | 32.47MB | | Pippo-Jetty | Java | 178,055.45 | 15.66ms | 26.83MB | | Play-Java | Java | 177,202.75 | 12.15ms | 21.80MB | -| Go HttpRouter | Go | 171852.31 | 14.12ms | 21.14MB | +| Go HttpRouter | Go | 171,852.31 | 14.12ms | 21.14MB | | Go Http | Go | 170,313.02 | 15.01ms | 20.95MB | | JFinal | Java | 139,467.87 | 11.89ms | 29.79MB | | Akka-Http | Java | 132,157.96 | 12.21ms | 19.54MB | | RatPack | Java | 124,700.70 | 13.45ms | 10.82MB | | Pippo-Tomcat | Java | 103,948.18 | 23.50ms | 15.29MB | | Bootique + Jetty/Jersey | Java | 65,072.20 | 39.08ms | 11.17MB | -| SeedStack-Jersey2 | Java | 52310.11 | 26.88ms | 11.87MB | +| SeedStack-Jersey2 | Java | 52,310.11 | 26.88ms | 11.87MB | | Baseio | Java | 50,361.98 | 22.20ms | 6.39MB | | NinjaFramework | Java | 47,956.43 | 55.76ms | 13.67MB | | Play 1 | Java | 44,491.87 | 10.73ms | 18.75MB | @@ -34,7 +38,7 @@ | Nodejs Express | Node | 42,443.34 | 22.30ms | 9.31MB | | Dropwizard | Java | 33,819.90 | 98.78ms | 3.23MB | | Spring Boot Tomcat | Java | 33,086.22 | 82.93ms | 3.98MB | -| Node-Loopback | Node | 32091.95 | 34.42ms | 11.51MB | +| Node-Loopback | Node | 32,091.95 | 34.42ms | 11.51MB | | Payra Micro | Java | 24,768.69 | 118.86ms | 3.50MB | | WildFly Swarm | Java | 21,541.07 | 59.77ms | 2.83MB | @@ -46,21 +50,20 @@ at microservices-framework-benchmark/pipeline.lua. Here is the light-java server performance with the same command line with other frameworks. ``` -steve@joy:~/tool/wrk$ wrk -t4 -c128 -d30s http://localhost:8080 -s pipeline.lua --latency -- / 16 +wrk -t4 -c128 -d30s http://localhost:8080 -s pipeline.lua --latency -- / 16 Running 30s test @ http://localhost:8080 4 threads and 128 connections Thread Stats Avg Stdev Max +/- Stdev - Latency 2.36ms 3.55ms 53.35ms 89.03% - Req/Sec 338.18k 49.76k 717.09k 76.64% + Latency 774.30us 1.77ms 40.31ms 91.51% + Req/Sec 0.93M 81.46k 1.06M 87.83% Latency Distribution - 50% 1.05ms - 75% 2.48ms - 90% 6.35ms - 99% 17.28ms - 40436304 requests in 30.08s, 4.97GB read -Requests/sec: 1344512.65 -Transfer/sec: 169.25MB - + 50% 286.00us + 75% 529.00us + 90% 1.92ms + 99% 0.00us + 110603088 requests in 30.01s, 12.88GB read +Requests/sec: 3685234.33 +Transfer/sec: 439.31MB ``` Here is another test with for light-java to push more requests but some other frameworks get server errors. @@ -624,27 +627,26 @@ Transfer/sec: 28.69MB @seanjburns submitted a pull request to add vertx and here is the result. ``` -steve@joy:~/tool/wrk$ wrk -t4 -c128 -d30s http://localhost:8080 -s pipeline.lua --latency -- / 16 +wrk -t4 -c128 -d30s http://localhost:8080 -s pipeline.lua --latency -- / 16 Running 30s test @ http://localhost:8080 4 threads and 128 connections Thread Stats Avg Stdev Max +/- Stdev - Latency 2.37ms 3.24ms 79.48ms 90.49% - Req/Sec 201.91k 19.79k 269.09k 78.08% + Latency 1.34ms 5.61ms 170.00ms 94.85% + Req/Sec 0.95M 133.67k 1.23M 92.76% Latency Distribution - 50% 1.41ms - 75% 2.42ms - 90% 5.41ms - 99% 16.08ms - 24114240 requests in 30.02s, 2.87GB read -Requests/sec: 803311.31 -Transfer/sec: 98.06MB - + 50% 278.00us + 75% 517.00us + 90% 3.23ms + 99% 126.69ms + 113247792 requests in 30.10s, 9.70GB read +Requests/sec: 3762376.24 +Transfer/sec: 330.10MB ``` @kevin-better submitted a pull request to add baseio and here is the result. ``` -steve@joy:~/tool/wrk$ wrk -t4 -c128 -d30s http://localhost:8080 -s pipeline.lua --latency -- / 16 +wrk -t4 -c128 -d30s http://localhost:8080 -s pipeline.lua --latency -- / 16 Running 30s test @ http://localhost:8080 4 threads and 128 connections Thread Stats Avg Stdev Max +/- Stdev @@ -798,4 +800,4 @@ Running 30s test @ http://localhost:8080 Requests/sec: 171852.31 Transfer/sec: 21.14MB -``` \ No newline at end of file +``` diff --git a/actframework/pom.xml b/actframework/pom.xml index cae9189..2ac9dda 100644 --- a/actframework/pom.xml +++ b/actframework/pom.xml @@ -6,12 +6,12 @@ microservice.benchmark act-benchmark - 1.6.0 + 1.8.11.0 org.actframework act-starter-parent - 1.6.4.0 + 1.8.11.0 @@ -26,16 +26,4 @@ - - ${project.artifactId}-${project.version} - - - - - org.actframework - act - 1.7.0-SNAPSHOT - - - diff --git a/actframework/run.sh b/actframework/run.sh index 87a9553..0ac1d0b 100755 --- a/actframework/run.sh +++ b/actframework/run.sh @@ -1,5 +1,5 @@ #!/bin/sh mvn -U clean package cd target/dist -unzip * -./start +tar xzf *.gz +./run diff --git a/baseio/README.md b/baseio/README.md index 6ac4b38..9bd40f2 100644 --- a/baseio/README.md +++ b/baseio/README.md @@ -11,10 +11,10 @@ Run: java -jar target/baseio-example-microservices-fat.jar ``` -Server will start on port 8080. +Server will start on port 8087. Test: ``` -wrk -t{CPU_SIZE} -c128 -d30s http://localhost:8080 -s pipeline.lua --latency -- / 2048 -``` \ No newline at end of file +wrk -t{CPU_SIZE} -c128 -d30s http://localhost:8087 -s pipeline.lua --latency -- / 2048 +``` diff --git a/baseio/lib/baseio-all-3.2.6-SNAPSHOT.jar b/baseio/lib/baseio-all-3.2.6-SNAPSHOT.jar new file mode 100644 index 0000000..b4c45a0 Binary files /dev/null and b/baseio/lib/baseio-all-3.2.6-SNAPSHOT.jar differ diff --git a/baseio/pom.xml b/baseio/pom.xml index c0c9004..81e73e8 100644 --- a/baseio/pom.xml +++ b/baseio/pom.xml @@ -1,62 +1,63 @@ - - 4.0.0 - com.generallycloud - baseio-example-microservices - Baseio Example Microservices - 1.0.0-SNAPSHOT + 4.0.0 + com.generallycloud + baseio-example-microservices + Baseio Example Microservices + 1.0.0-SNAPSHOT - - - example.Server - + + + example.Server + - - - com.generallycloud - baseio-all - 3.1.8-Alpha3 - - + + + com.generallycloud + baseio-all + baseio-all-3.2.6-SNAPSHOT + system + ${basedir}/lib/baseio-all-3.2.6-SNAPSHOT.jar + + - - - - maven-compiler-plugin - 3.6.1 - - 1.8 - 1.8 - - + + - org.apache.maven.plugins - maven-shade-plugin - 2.3 - - - package - - shade - - + maven-compiler-plugin + 3.6.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 2.3 + + + package + + shade + + - - - ${exec.mainClass} - - - - ${project.build.directory}/${project.artifactId}-fat.jar - - - - - - - + + + ${exec.mainClass} + + + + ${project.build.directory}/${project.artifactId}-fat.jar + + + + + + + \ No newline at end of file diff --git a/baseio/src/main/java/example/Server.java b/baseio/src/main/java/example/Server.java index d1cb04d..c696bd4 100644 --- a/baseio/src/main/java/example/Server.java +++ b/baseio/src/main/java/example/Server.java @@ -1,43 +1,59 @@ package example; -import com.generallycloud.nio.acceptor.SocketChannelAcceptor; -import com.generallycloud.nio.codec.http11.ServerHTTPProtocolFactory; -import com.generallycloud.nio.component.IoEventHandleAdaptor; -import com.generallycloud.nio.component.NioSocketChannelContext; -import com.generallycloud.nio.component.SocketChannelContext; -import com.generallycloud.nio.component.SocketSession; -import com.generallycloud.nio.configuration.ServerConfiguration; -import com.generallycloud.nio.protocol.ReadFuture; - -public class Server { - - public static void main(String[] args) throws Exception { - - IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() { - @Override - public void accept(SocketSession session, ReadFuture future) throws Exception { - future.write("Hello World!"); - session.flush(future); - } - }; - - ServerConfiguration c = new ServerConfiguration(8080); - - c.setSERVER_MEMORY_POOL_UNIT(256); - c.setSERVER_ENABLE_MEMORY_POOL_DIRECT(true); - //c.setSERVER_CORE_SIZE(2); - c.setSERVER_ENABLE_MEMORY_POOL(true); - c.setSERVER_MEMORY_POOL_CAPACITY_RATE(4); - - SocketChannelContext context = new NioSocketChannelContext(c); - - SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context); - - context.setIoEventHandleAdaptor(eventHandleAdaptor); - context.setProtocolFactory(new ServerHTTPProtocolFactory()); - - acceptor.bind(); - - } - +import java.net.StandardSocketOptions; +import java.util.ArrayList; +import java.util.List; + +import com.generallycloud.baseio.buffer.ByteBuf; +import com.generallycloud.baseio.codec.http11.ServerHttpCodec; +import com.generallycloud.baseio.component.ChannelAcceptor; +import com.generallycloud.baseio.component.ChannelContext; +import com.generallycloud.baseio.component.ChannelEventListenerAdapter; +import com.generallycloud.baseio.component.IoEventHandle; +import com.generallycloud.baseio.component.LoggerChannelOpenListener; +import com.generallycloud.baseio.component.NioEventLoopGroup; +import com.generallycloud.baseio.component.NioSocketChannel; +import com.generallycloud.baseio.protocol.Future; + +public class Server { + + public static void main(String[] args) throws Exception { + + NioEventLoopGroup group = new NioEventLoopGroup(); + group.setMemoryPoolCapacity(1024 * 64); + group.setMemoryPoolUnit(512); + ChannelContext context = new ChannelContext(8087); + ChannelAcceptor acceptor = new ChannelAcceptor(context, group); + context.setProtocolCodec(new ServerHttpCodec(1024 * 4)); + context.setMaxWriteBacklog(Integer.MAX_VALUE); + context.addChannelEventListener(new LoggerChannelOpenListener()); + context.addChannelEventListener(new ChannelEventListenerAdapter() { + + @Override + public void channelOpened(NioSocketChannel channel) throws Exception { + channel.setOption(StandardSocketOptions.TCP_NODELAY, true); + channel.setIoEventHandle(new IoEventHandle() { + boolean addTask = true; + List fs = new ArrayList<>(256); + + @Override + public void accept(NioSocketChannel channel, Future future) throws Exception { + future.write("Hello World", channel); + fs.add(channel.encode(future)); + if (addTask) { + addTask = false; + channel.getEventLoop().dispatchAfterLoop(() -> { + channel.flush(fs); + addTask = true; + fs.clear(); + }); + } + } + }); + } + }); + + acceptor.bind(); + } + } diff --git a/dotnet-core/.gitignore b/dotnet-core/.gitignore deleted file mode 100644 index 70e7072..0000000 --- a/dotnet-core/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -obj/ -bin/ -*.nuget.g.props -*.nuget.g.targets -*.suo -*.csproj.user -launchSettings.json -*.bak - diff --git a/dotnet-core/hello-world/Program.cs b/dotnet-core/hello-world/Program.cs deleted file mode 100644 index 173b5b9..0000000 --- a/dotnet-core/hello-world/Program.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; - -namespace dotnet_core -{ - public class Program - { - public static void Main(string[] args) - { - var host = new WebHostBuilder() - .UseKestrel() - .UseStartup() - .Build(); - - host.Run(); - } - } - - public class Configuration - { - public void Configure(IApplicationBuilder app) - { - app.Run(async (context) => - { - await context.Response.WriteAsync("Hello World!"); - }); - } - } -} diff --git a/dotnet-core/hello-world/README.md b/dotnet-core/hello-world/README.md deleted file mode 100644 index f763bf2..0000000 --- a/dotnet-core/hello-world/README.md +++ /dev/null @@ -1,21 +0,0 @@ -ASP.NET CORE -============ -This is a minimal .NET Core ASP.NET core Hello World! - -Please be aware that this does not do any routing, so all urls will be -matched. This is purely in order to do the absolutely minimal work in -order to return 'Hello World!'. - -Restore dependencies: ---------------------- -``` -dotnet restore -``` - -Run application: ----------------- -``` -dotnet run -c Release -``` - -Server will be online @ http://localhost:5000 \ No newline at end of file diff --git a/dotnet-core/hello-world/dotnet-core.csproj b/dotnet-core/hello-world/dotnet-core.csproj deleted file mode 100644 index a5acd1c..0000000 --- a/dotnet-core/hello-world/dotnet-core.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - netcoreapp1.1 - - - - - - - diff --git a/dotnet-core/scenario1/README.md b/dotnet-core/scenario1/README.md deleted file mode 100644 index 898dad2..0000000 --- a/dotnet-core/scenario1/README.md +++ /dev/null @@ -1,34 +0,0 @@ -Routing in ASP.NET Core -======================= - -This is a simple implementation scenario 1 of the spec from https://networknt.github.io/microservices-framework-benchmark/specification/ - -In the 'Hello World!' app sample found in the hello-world folder we focused on a minimal ASP.NET Core app that only did the bare mininum in order to return 'Hello World!' to the caller. This meant that we could do away with large parts of what is traditionally present in ASP.NET MVC applications. One of the things we sacrificed on the alter of simplicity was the ability to do routing (in the traditional MVC sense). - -In this sample we look at a slightly more realistic scenario where we still use the Kestrel web server from ASP.NET Core, but this time we use more of the MVC framework. This allows us to use controllers with a Routing attribute which describes what requests should be handled where. Two controllers are present, one which handles the http protocol and one which handles https. - - -Restore dependencies: ------- -Getting the app ready to run should be as simple as opening a console in the apiA folder and executing -``` -dotnet restore -``` - -Run the app: ------- -You can now run the app by opening a console in the apiA folder and executing -``` -dotnet run -c Release -``` - -The app should then print the following in the console -``` -Hosting environment: Production -Content root path: ....microservices-framework-benchmark/dotnet-core/scenario1/apiA -Now listening on: http://*:7000 -Now listening on: https://*:7441 -Application started. Press Ctrl+C to shut down. -``` - -You can then call the app using a browser, Postman or another tool at http://localhost:7000/text for http and https://localhost:7441/tls/text for a https request. The certificate is, of course, a self-signed cert. \ No newline at end of file diff --git a/dotnet-core/scenario1/apiA/Controllers/ApiA.cs b/dotnet-core/scenario1/apiA/Controllers/ApiA.cs deleted file mode 100644 index 8776a50..0000000 --- a/dotnet-core/scenario1/apiA/Controllers/ApiA.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace ApiA.Controllers -{ - public abstract class ApiA : Controller - { - [HttpGet] - public string Get() - { - return "Hello World!"; - } - - } -} diff --git a/dotnet-core/scenario1/apiA/Controllers/Http.cs b/dotnet-core/scenario1/apiA/Controllers/Http.cs deleted file mode 100644 index 8ca0a82..0000000 --- a/dotnet-core/scenario1/apiA/Controllers/Http.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace ApiA.Controllers -{ - [Route("text")] - public class Http : ApiA - { - } -} \ No newline at end of file diff --git a/dotnet-core/scenario1/apiA/Controllers/Https.cs b/dotnet-core/scenario1/apiA/Controllers/Https.cs deleted file mode 100644 index 51df07b..0000000 --- a/dotnet-core/scenario1/apiA/Controllers/Https.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace ApiA.Controllers -{ - [Route("tls/text")] - [RequireHttps] - public class Https : ApiA - { - } -} \ No newline at end of file diff --git a/dotnet-core/scenario1/apiA/Program.cs b/dotnet-core/scenario1/apiA/Program.cs deleted file mode 100644 index 16c801c..0000000 --- a/dotnet-core/scenario1/apiA/Program.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.IO; -using System.Linq; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace ApiA -{ - public class Program - { - public static void Main(string[] args) - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - var host = new WebHostBuilder() - .UseKestrel(options => - { - // Here we read the certificate filename and and password from the appsettings config file. - // Please never store passwords in a config file for real apps! - var cert = AppConf.GetSection("Certificate").Value; - var certPassword = AppConf.GetSection("Password").Value; - options.UseHttps(cert, certPassword); - }) - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup() - .UseUrls(AppConf.GetSection("Urls").GetChildren().Select(x => x.Value).ToArray()) - .Build(); - - host.Run(); - } - } - - public class Startup - { - public Startup(IHostingEnvironment env) - { - var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddEnvironmentVariables(); - Configuration = builder.Build(); - } - - public IConfigurationRoot Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc(); - } - - public void Configure(IApplicationBuilder app) - { - app.UseMvc(); - } - } -} diff --git a/dotnet-core/scenario1/apiA/apiA.csproj b/dotnet-core/scenario1/apiA/apiA.csproj deleted file mode 100644 index b5c6c45..0000000 --- a/dotnet-core/scenario1/apiA/apiA.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - netcoreapp1.1 - - - - - - - \ No newline at end of file diff --git a/dotnet-core/scenario1/apiA/appsettings.Development.json b/dotnet-core/scenario1/apiA/appsettings.Development.json deleted file mode 100644 index fa8ce71..0000000 --- a/dotnet-core/scenario1/apiA/appsettings.Development.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Logging": { - "IncludeScopes": false, - "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" - } - } -} diff --git a/dotnet-core/scenario1/apiA/appsettings.json b/dotnet-core/scenario1/apiA/appsettings.json deleted file mode 100644 index a56896d..0000000 --- a/dotnet-core/scenario1/apiA/appsettings.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Urls": [ - "http://*:7000", - "https://*:7441" - ], - //Please do not put certificate information ESPECIALLY passwords into a config file in a real app! - "Certificate": "certificate.pfx", - "Password": "hunter2" -} \ No newline at end of file diff --git a/dotnet-core/scenario1/apiA/certificate.pfx b/dotnet-core/scenario1/apiA/certificate.pfx deleted file mode 100644 index 21256e4..0000000 Binary files a/dotnet-core/scenario1/apiA/certificate.pfx and /dev/null differ diff --git a/dotnet-core/scenario2/README.md b/dotnet-core/scenario2/README.md deleted file mode 100644 index 8d422d1..0000000 --- a/dotnet-core/scenario2/README.md +++ /dev/null @@ -1,44 +0,0 @@ -Chained calls in ASP.NET Core -======================= - -This is a simple implementation of scenario 1 of the spec from https://networknt.github.io/microservices-framework-benchmark/specification/ - -In the 'Hello World!' app sample found in the hello-world folder we focused on a minimal ASP.NET Core app that only did the bare mininum in order to return 'Hello World!' to the caller. This meant that we could do away with large parts of what is traditionally present in ASP.NET MVC applications. One of the things we sacrificed on the alter of simplicity was the ability to do routing (in the traditional MVC sense). - -In the scenario 1 app sample we then investigated how a slightly more realistic sample which used MVC routing could look like. - -In this sample we look at how ASP.NET Core handles chaining calls from one service to another. We again use the built-in Kestrel web server from ASP.NET Core, again with the MVC framework. The three services run as 3 completely separated processes, only sharing the underlaying .NET framework. This means some code duplication is found, but it makes each service a more natural self-contained entity. The shared .NET framework can sometimes be seen in this sample. Since 3 applications are running simultaneously, they have to share the available threadpool from the .NET framework. Under heavy loads this will be overloaded and you'll see some connections failing, though you should not see any crashes. - -Error handling is indicated in the code with comments where nescessary. In this example any errors are simply logged in each console. - -Each service is configured in it's appsettings.json file. Here you can change what URLs are used for the service as well as where to find the next service in the chain. The default is localhost, making all three services run on the same machine. It is straightforward to put the services on different machines, all you have to change is the endpoints in the appsettings.json files for apiA and apiB. - - -Restore dependencies: ------- -Getting the app samples ready to run should be as simple as opening a console in each of the three api folders and executing -``` -dotnet restore -``` - -in each console. - -Run the app: ------- -You can now run the app by opening a console in each of the three api folders and executing -``` -dotnet run -c Release -``` - -In each of the three consoles the app should then print the following -``` -Hosting environment: Production -Content root path: ....microservices-framework-benchmark/dotnet-core/scenario1/apiA -Now listening on: http://*:7001 -Now listening on: https://*:7441 -Application started. Press Ctrl+C to shut down. -``` - -You can then call the app using a browser, Postman or another tool at http://localhost:7001/chain/text for http and https://localhost:7441/tls/chain/text for a https request. The certificates are, of course, self-signed certs. - -You can do partial calls to apiB and apiC as well. If you call http://localhost:7002/chain/text you should get a response containing 'B OK!C OK!'. \ No newline at end of file diff --git a/dotnet-core/scenario2/apiA/Controllers/ApiA.cs b/dotnet-core/scenario2/apiA/Controllers/ApiA.cs deleted file mode 100644 index 53f06e0..0000000 --- a/dotnet-core/scenario2/apiA/Controllers/ApiA.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using System; - -namespace ApiA.Controllers -{ - public abstract class ApiA : Controller - { - protected async Task BaseGet(string nexturl) - { - return Content("A OK!" + await Next(nexturl)); - } - - async Task Next(string url) - { - // This is demo code, so we don't bother with a real signed certificate. Please never do this in a real app! - using (var bypassSelfSignedCertError = new HttpClientHandler()) - { - //All certificates are considered valid! Carry on! :D - bypassSelfSignedCertError.ServerCertificateCustomValidationCallback = (msg, cert, chain, errors) => { return true; }; - - using (var client = new HttpClient(bypassSelfSignedCertError)) - { - HttpResponseMessage response; - try - { - response = await client.GetAsync(url); - response.EnsureSuccessStatusCode(); - return await response.Content.ReadAsStringAsync(); - } - catch (Exception e) - { - while (e.InnerException != null) - e = e.InnerException; - - // This is where you would do error handling. Here we we just print to the console. - Console.WriteLine(e.Message); - throw; - } - } - } - } - } -} diff --git a/dotnet-core/scenario2/apiA/Controllers/Http.cs b/dotnet-core/scenario2/apiA/Controllers/Http.cs deleted file mode 100644 index dad1e81..0000000 --- a/dotnet-core/scenario2/apiA/Controllers/Http.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; - -namespace ApiA.Controllers -{ - [Route("chain/text")] - public class Http : ApiA - { - static Http() - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - endpointB = AppConf.GetSection("EndpointB").Value; - } - - static readonly string endpointB; - - [HttpGet] - public async Task Get() - { - return await BaseGet(endpointB); - } - } -} \ No newline at end of file diff --git a/dotnet-core/scenario2/apiA/Controllers/Https.cs b/dotnet-core/scenario2/apiA/Controllers/Https.cs deleted file mode 100644 index b9f3b4f..0000000 --- a/dotnet-core/scenario2/apiA/Controllers/Https.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; - -namespace ApiA.Controllers -{ - [Route("tls/chain/text")] - [RequireHttps] - public class Https : ApiA - { - static Https() - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - endpointBhttps = AppConf.GetSection("EndpointBhttps").Value; - } - - static readonly string endpointBhttps; - - [HttpGet] - public async Task Get() - { - return await BaseGet(endpointBhttps); - } - } -} \ No newline at end of file diff --git a/dotnet-core/scenario2/apiA/Program.cs b/dotnet-core/scenario2/apiA/Program.cs deleted file mode 100644 index 2d165ff..0000000 --- a/dotnet-core/scenario2/apiA/Program.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.IO; -using System.Linq; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace ApiA -{ - public class Program - { - public static void Main(string[] args) - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - var host = new WebHostBuilder() - .UseKestrel(options => - { - var cert = AppConf.GetSection("Certificate").Value; - var certPassword = AppConf.GetSection("Password").Value; - options.UseHttps(cert, certPassword); - }) - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup() - .UseUrls(AppConf.GetSection("Urls").GetChildren().Select(x => x.Value).ToArray()) - .Build(); - - host.Run(); - } - } - - public class Startup - { - public Startup(IHostingEnvironment env) - { - var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddEnvironmentVariables(); - Configuration = builder.Build(); - } - - public IConfigurationRoot Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc(); - } - - public void Configure(IApplicationBuilder app) - { - app.UseMvc(); - } - } -} diff --git a/dotnet-core/scenario2/apiA/apiA.csproj b/dotnet-core/scenario2/apiA/apiA.csproj deleted file mode 100644 index b5c6c45..0000000 --- a/dotnet-core/scenario2/apiA/apiA.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - netcoreapp1.1 - - - - - - - \ No newline at end of file diff --git a/dotnet-core/scenario2/apiA/appsettings.json b/dotnet-core/scenario2/apiA/appsettings.json deleted file mode 100644 index fcf8179..0000000 --- a/dotnet-core/scenario2/apiA/appsettings.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "Urls": [ - "http://*:7001", - "https://*:7441" - ], - - //Please do not put certificate information ESPECIALLY passwords into a config file in a real app! - "Certificate": "certificate.pfx", - "Password": "hunter2", - - "EndpointB": "http://localhost:7002/chain/text", - "EndpointBhttps": "https://localhost:7442/tls/chain/text" - -} \ No newline at end of file diff --git a/dotnet-core/scenario2/apiA/certificate.pfx b/dotnet-core/scenario2/apiA/certificate.pfx deleted file mode 100644 index 21256e4..0000000 Binary files a/dotnet-core/scenario2/apiA/certificate.pfx and /dev/null differ diff --git a/dotnet-core/scenario2/apiB/Controllers/ApiB.cs b/dotnet-core/scenario2/apiB/Controllers/ApiB.cs deleted file mode 100644 index bc8f16f..0000000 --- a/dotnet-core/scenario2/apiB/Controllers/ApiB.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using System; - -namespace ApiB.Controllers -{ - public abstract class ApiB : Controller - { - protected async Task BaseGet(string nexturl) - { - return Content("B OK!" + await Next(nexturl)); - } - - async Task Next(string url) - { - // This is demo code, so we don't bother with a real signed certificate. Please never do this in a real app! - using (var bypassSelfSignedCertError = new HttpClientHandler()) - { - //All certificates are considered valid! Carry on! :D - bypassSelfSignedCertError.ServerCertificateCustomValidationCallback = (msg, cert, chain, errors) => { return true; }; - - using (var client = new HttpClient(bypassSelfSignedCertError)) - { - HttpResponseMessage response; - try - { - response = await client.GetAsync(url); - response.EnsureSuccessStatusCode(); - return await response.Content.ReadAsStringAsync(); - } - catch (Exception e) - { - while (e.InnerException != null) - e = e.InnerException; - - // This is where you would do error handling. Here we we just print to the console. - Console.WriteLine(e.Message); - throw; - } - } - } - } - } -} diff --git a/dotnet-core/scenario2/apiB/Controllers/Http.cs b/dotnet-core/scenario2/apiB/Controllers/Http.cs deleted file mode 100644 index c5057d1..0000000 --- a/dotnet-core/scenario2/apiB/Controllers/Http.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; - -namespace ApiB.Controllers -{ - [Route("chain/text")] - public class Http : ApiB - { - static Http() - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - endpointC = AppConf.GetSection("EndpointC").Value; - } - - static readonly string endpointC; - - [HttpGet] - public async Task Get() - { - return await BaseGet(endpointC); - } - } -} \ No newline at end of file diff --git a/dotnet-core/scenario2/apiB/Controllers/Https.cs b/dotnet-core/scenario2/apiB/Controllers/Https.cs deleted file mode 100644 index a94df67..0000000 --- a/dotnet-core/scenario2/apiB/Controllers/Https.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; - -namespace ApiB.Controllers -{ - [Route("tls/chain/text")] - [RequireHttps] - public class Https : ApiB - { - static Https() - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - endpointChttps = AppConf.GetSection("EndpointChttps").Value; - } - - static readonly string endpointChttps; - - [HttpGet] - public async Task Get() - { - return await BaseGet(endpointChttps); - } - } -} \ No newline at end of file diff --git a/dotnet-core/scenario2/apiB/Program.cs b/dotnet-core/scenario2/apiB/Program.cs deleted file mode 100644 index 35afd59..0000000 --- a/dotnet-core/scenario2/apiB/Program.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.IO; -using System.Linq; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace ApiB -{ - public class Program - { - public static void Main(string[] args) - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - var host = new WebHostBuilder() - .UseKestrel(options => - { - var cert = AppConf.GetSection("Certificate").Value; - var certPassword = AppConf.GetSection("Password").Value; - options.UseHttps(cert, certPassword); - }) - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup() - .UseUrls(AppConf.GetSection("Urls").GetChildren().Select(x => x.Value).ToArray()) - .Build(); - - host.Run(); - } - } - - public class Startup - { - public Startup(IHostingEnvironment env) - { - var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddEnvironmentVariables(); - Configuration = builder.Build(); - } - - public IConfigurationRoot Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc(); - } - - public void Configure(IApplicationBuilder app) - { - app.UseMvc(); - } - } -} diff --git a/dotnet-core/scenario2/apiB/apiB.csproj b/dotnet-core/scenario2/apiB/apiB.csproj deleted file mode 100644 index b5c6c45..0000000 --- a/dotnet-core/scenario2/apiB/apiB.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - netcoreapp1.1 - - - - - - - \ No newline at end of file diff --git a/dotnet-core/scenario2/apiB/appsettings.json b/dotnet-core/scenario2/apiB/appsettings.json deleted file mode 100644 index 46cb3a2..0000000 --- a/dotnet-core/scenario2/apiB/appsettings.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "Urls": [ - "http://*:7002", - "https://*:7442" - ], - - //Please do not put certificate information ESPECIALLY passwords into a config file in a real app! - "Certificate": "certificate.pfx", - "Password": "hunter2", - - "EndpointC": "http://localhost:7003/chain/text", - "EndpointChttps": "https://localhost:7443/tls/chain/text" - -} \ No newline at end of file diff --git a/dotnet-core/scenario2/apiB/certificate.pfx b/dotnet-core/scenario2/apiB/certificate.pfx deleted file mode 100644 index 21256e4..0000000 Binary files a/dotnet-core/scenario2/apiB/certificate.pfx and /dev/null differ diff --git a/dotnet-core/scenario2/apiC/Controllers/Http.cs b/dotnet-core/scenario2/apiC/Controllers/Http.cs deleted file mode 100644 index 7292dc6..0000000 --- a/dotnet-core/scenario2/apiC/Controllers/Http.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace ApiC.Controllers -{ - [Route("chain/text")] - public class Http : Controller - { - - [HttpGet] - public string Get() - { - return "C OK!"; - } - } -} \ No newline at end of file diff --git a/dotnet-core/scenario2/apiC/Controllers/Https.cs b/dotnet-core/scenario2/apiC/Controllers/Https.cs deleted file mode 100644 index 35b0651..0000000 --- a/dotnet-core/scenario2/apiC/Controllers/Https.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace ApiC.Controllers -{ - [Route("tls/chain/text")] - [RequireHttps] - public class Https : Controller - { - [HttpGet] - public string Get() - { - return "C OK!"; - } - } -} \ No newline at end of file diff --git a/dotnet-core/scenario2/apiC/Program.cs b/dotnet-core/scenario2/apiC/Program.cs deleted file mode 100644 index 050a9e6..0000000 --- a/dotnet-core/scenario2/apiC/Program.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.IO; -using System.Linq; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace ApiC -{ - public class Program - { - public static void Main(string[] args) - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - var host = new WebHostBuilder() - .UseKestrel(options => - { - var cert = AppConf.GetSection("Certificate").Value; - var certPassword = AppConf.GetSection("Password").Value; - options.UseHttps(cert, certPassword); - }) - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup() - .UseUrls(AppConf.GetSection("Urls").GetChildren().Select(x => x.Value).ToArray()) - .Build(); - - host.Run(); - } - } - - public class Startup - { - public Startup(IHostingEnvironment env) - { - var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddEnvironmentVariables(); - Configuration = builder.Build(); - } - - public IConfigurationRoot Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc(); - } - - public void Configure(IApplicationBuilder app) - { - app.UseMvc(); - } - } -} diff --git a/dotnet-core/scenario2/apiC/apiC.csproj b/dotnet-core/scenario2/apiC/apiC.csproj deleted file mode 100644 index b5c6c45..0000000 --- a/dotnet-core/scenario2/apiC/apiC.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - netcoreapp1.1 - - - - - - - \ No newline at end of file diff --git a/dotnet-core/scenario2/apiC/appsettings.json b/dotnet-core/scenario2/apiC/appsettings.json deleted file mode 100644 index 6f9c383..0000000 --- a/dotnet-core/scenario2/apiC/appsettings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Urls": [ - "http://*:7003", - "https://*:7443" - ], - - //Please do not put certificate information ESPECIALLY passwords into a config file in a real app! - "Certificate": "certificate.pfx", - "Password": "hunter2" -} \ No newline at end of file diff --git a/dotnet-core/scenario2/apiC/certificate.pfx b/dotnet-core/scenario2/apiC/certificate.pfx deleted file mode 100644 index 21256e4..0000000 Binary files a/dotnet-core/scenario2/apiC/certificate.pfx and /dev/null differ diff --git a/dotnet-core/scenario3/README.md b/dotnet-core/scenario3/README.md deleted file mode 100644 index 0e2edc2..0000000 --- a/dotnet-core/scenario3/README.md +++ /dev/null @@ -1,46 +0,0 @@ -Aggregated concurrent calls in ASP.NET Core -======================= - -This is a simple implementation of scenario 3 of the spec from https://networknt.github.io/microservices-framework-benchmark/specification/ - -In the 'Hello World!' app sample found in the hello-world folder we focused on a minimal ASP.NET Core app that only did the bare mininum in order to return 'Hello World!' to the caller. This meant that we could do away with large parts of what is traditionally present in ASP.NET MVC applications. One of the things we sacrificed on the alter of simplicity was the ability to do routing (in the traditional MVC sense). - -In the scenario1 app sample we then investigated how a slightly more realistic sample which used MVC routing could look like. - -In the scenario2 app sample we then looked at how chaining together calls between services could look like, along with some error handling. - -In this sample we look at how ASP.NET Core handles concurrent calls from one service to multiple other services. We continue to use the built-in Kestrel web server from ASP.NET Core, still with the MVC framework. As before, the three services run as 3 completely separated processes, only sharing the underlaying .NET framework. The code duplication is therefore the same as last time, with the same benefits and disadvantages. - -Error handling will again be indicated in the code with comments where nescessary. Any errors are simply logged in each console. - -The shared .NET framework can sometimes be seen in this sample too, for the same reasons as before: Since 3 applications are running simultaneously, they have to share the available threadpool from the .NET framework. Under heavy loads this will be overloaded and you'll see some connections failing, though you should not see any crashes. - -Each service is configured in it's appsettings.json file. Here you can change what URLs are used for the service. In the case of apiA, there's also information about where to find the other services to be called for aggregation. The default is localhost, making all three services run on the same machine. It is straightforward to put the services on different machines, all you have to change is the endpoints in the appsettings.json file for apiA. - - -Restore dependencies: ------- -Getting the app samples ready to run should be as simple as opening a console in each of the three api folders and executing -``` -dotnet restore -``` - -in each console. - -Run the app: ------- -You can now run the app by opening a console in each of the three api folders and executing -``` -dotnet run -c Release -``` - -In each of the three consoles the app should then print the following -``` -Hosting environment: Production -Content root path: ....microservices-framework-benchmark/dotnet-core/scenario1/apiA -Now listening on: http://*:7001 -Now listening on: https://*:7441 -Application started. Press Ctrl+C to shut down. -``` - -You can then call the app using a browser, Postman or another tool at http://localhost:7001//aggregator/text for http and https://localhost:7441/tls/aggregator/text for a https request. The certificates are, of course, self-signed certs. \ No newline at end of file diff --git a/dotnet-core/scenario3/apiA/Controllers/ApiA.cs b/dotnet-core/scenario3/apiA/Controllers/ApiA.cs deleted file mode 100644 index df679fc..0000000 --- a/dotnet-core/scenario3/apiA/Controllers/ApiA.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.Net.Http; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using System; - -namespace ApiA.Controllers -{ - public abstract class ApiA : Controller - { - protected async Task BaseGet(string endpointB, string endpointC) - { - var apiBRequest = Call(endpointB); - var apiCRequest = Call(endpointC); - - return Content("A OK!" + await apiBRequest + await apiCRequest); - } - - internal async Task Call(string url) - { - // This is demo code, so we don't bother with a real signed certificate. Please never do this in a real app! - using (var bypassSelfSignedCertError = new HttpClientHandler()) - { - //All certificates are considered valid! Carry on! :D - bypassSelfSignedCertError.ServerCertificateCustomValidationCallback = (msg, cert, chain, errors) => { return true; }; - - using (var client = new HttpClient(bypassSelfSignedCertError)) - { - HttpResponseMessage response; - try - { - response = await client.GetAsync(url); - response.EnsureSuccessStatusCode(); - return await response.Content.ReadAsStringAsync(); - } - catch (Exception e) - { - while (e.InnerException != null) - e = e.InnerException; - - // This is where you would do error handling. Here we we just print to the console. - Console.WriteLine(e.Message); - throw; - } - } - } - } - } -} diff --git a/dotnet-core/scenario3/apiA/Controllers/Http.cs b/dotnet-core/scenario3/apiA/Controllers/Http.cs deleted file mode 100644 index 266b0e8..0000000 --- a/dotnet-core/scenario3/apiA/Controllers/Http.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; - -namespace ApiA.Controllers -{ - [Route("aggregator/text")] - public class Http : ApiA - { - static Http() - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - endpointB = AppConf.GetSection("EndpointB").Value; - endpointC = AppConf.GetSection("EndpointC").Value; - } - - static readonly string endpointB; - static readonly string endpointC; - - [HttpGet] - public async Task Get() - { - return await BaseGet(endpointB, endpointC); - } - } -} \ No newline at end of file diff --git a/dotnet-core/scenario3/apiA/Controllers/Https.cs b/dotnet-core/scenario3/apiA/Controllers/Https.cs deleted file mode 100644 index 2e8275c..0000000 --- a/dotnet-core/scenario3/apiA/Controllers/Https.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.IO; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Configuration; - -namespace ApiA.Controllers -{ - [Route("tls/aggregator/text")] - [RequireHttps] - public class Https : ApiA - { - static Https() - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - endpointBhttps = AppConf.GetSection("EndpointBhttps").Value; - endpointChttps = AppConf.GetSection("EndpointChttps").Value; - } - - static readonly string endpointBhttps; - static readonly string endpointChttps; - - [HttpGet] - public async Task Get() - { - return await BaseGet(endpointBhttps, endpointChttps); - } - } -} \ No newline at end of file diff --git a/dotnet-core/scenario3/apiA/Program.cs b/dotnet-core/scenario3/apiA/Program.cs deleted file mode 100644 index 2d165ff..0000000 --- a/dotnet-core/scenario3/apiA/Program.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.IO; -using System.Linq; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace ApiA -{ - public class Program - { - public static void Main(string[] args) - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - var host = new WebHostBuilder() - .UseKestrel(options => - { - var cert = AppConf.GetSection("Certificate").Value; - var certPassword = AppConf.GetSection("Password").Value; - options.UseHttps(cert, certPassword); - }) - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup() - .UseUrls(AppConf.GetSection("Urls").GetChildren().Select(x => x.Value).ToArray()) - .Build(); - - host.Run(); - } - } - - public class Startup - { - public Startup(IHostingEnvironment env) - { - var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddEnvironmentVariables(); - Configuration = builder.Build(); - } - - public IConfigurationRoot Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc(); - } - - public void Configure(IApplicationBuilder app) - { - app.UseMvc(); - } - } -} diff --git a/dotnet-core/scenario3/apiA/apiA.csproj b/dotnet-core/scenario3/apiA/apiA.csproj deleted file mode 100644 index b5c6c45..0000000 --- a/dotnet-core/scenario3/apiA/apiA.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - netcoreapp1.1 - - - - - - - \ No newline at end of file diff --git a/dotnet-core/scenario3/apiA/appsettings.json b/dotnet-core/scenario3/apiA/appsettings.json deleted file mode 100644 index 44a1d88..0000000 --- a/dotnet-core/scenario3/apiA/appsettings.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "Urls": [ - "http://*:7001", - "https://*:7441" - ], - - //Please do not put certificate information ESPECIALLY passwords into a config file in a real app! - "Certificate": "certificate.pfx", - "Password": "hunter2", - - "EndpointB": "http://localhost:7002/aggregator/text", - "EndpointBhttps": "https://localhost:7442/tls/aggregator/text", - "EndpointC": "http://localhost:7003/aggregator/text", - "EndpointChttps": "https://localhost:7443/tls/aggregator/text" - -} \ No newline at end of file diff --git a/dotnet-core/scenario3/apiA/certificate.pfx b/dotnet-core/scenario3/apiA/certificate.pfx deleted file mode 100644 index 21256e4..0000000 Binary files a/dotnet-core/scenario3/apiA/certificate.pfx and /dev/null differ diff --git a/dotnet-core/scenario3/apiB/Controllers/Http.cs b/dotnet-core/scenario3/apiB/Controllers/Http.cs deleted file mode 100644 index 5aa66c4..0000000 --- a/dotnet-core/scenario3/apiB/Controllers/Http.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace ApiB.Controllers -{ - [Route("aggregator/text")] - public class Http : Controller - { - [HttpGet] - public string Get() - { - return "B OK!"; - } - } -} \ No newline at end of file diff --git a/dotnet-core/scenario3/apiB/Controllers/Https.cs b/dotnet-core/scenario3/apiB/Controllers/Https.cs deleted file mode 100644 index 0ce19e1..0000000 --- a/dotnet-core/scenario3/apiB/Controllers/Https.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace ApiB.Controllers -{ - [Route("tls/aggregator/text")] - [RequireHttps] - public class Https : Controller - { - [HttpGet] - public string Get() - { - return "B OK!"; - } - - } -} \ No newline at end of file diff --git a/dotnet-core/scenario3/apiB/Program.cs b/dotnet-core/scenario3/apiB/Program.cs deleted file mode 100644 index 35afd59..0000000 --- a/dotnet-core/scenario3/apiB/Program.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.IO; -using System.Linq; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace ApiB -{ - public class Program - { - public static void Main(string[] args) - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - var host = new WebHostBuilder() - .UseKestrel(options => - { - var cert = AppConf.GetSection("Certificate").Value; - var certPassword = AppConf.GetSection("Password").Value; - options.UseHttps(cert, certPassword); - }) - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup() - .UseUrls(AppConf.GetSection("Urls").GetChildren().Select(x => x.Value).ToArray()) - .Build(); - - host.Run(); - } - } - - public class Startup - { - public Startup(IHostingEnvironment env) - { - var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddEnvironmentVariables(); - Configuration = builder.Build(); - } - - public IConfigurationRoot Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc(); - } - - public void Configure(IApplicationBuilder app) - { - app.UseMvc(); - } - } -} diff --git a/dotnet-core/scenario3/apiB/apiB.csproj b/dotnet-core/scenario3/apiB/apiB.csproj deleted file mode 100644 index b5c6c45..0000000 --- a/dotnet-core/scenario3/apiB/apiB.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - netcoreapp1.1 - - - - - - - \ No newline at end of file diff --git a/dotnet-core/scenario3/apiB/appsettings.json b/dotnet-core/scenario3/apiB/appsettings.json deleted file mode 100644 index e0b9d03..0000000 --- a/dotnet-core/scenario3/apiB/appsettings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "Urls": [ - "http://*:7002", - "https://*:7442" - ], - - //Please do not put certificate information ESPECIALLY passwords into a config file in a real app! - "Certificate": "certificate.pfx", - "Password": "hunter2" - -} \ No newline at end of file diff --git a/dotnet-core/scenario3/apiB/certificate.pfx b/dotnet-core/scenario3/apiB/certificate.pfx deleted file mode 100644 index 21256e4..0000000 Binary files a/dotnet-core/scenario3/apiB/certificate.pfx and /dev/null differ diff --git a/dotnet-core/scenario3/apiC/Controllers/Http.cs b/dotnet-core/scenario3/apiC/Controllers/Http.cs deleted file mode 100644 index 84c95f0..0000000 --- a/dotnet-core/scenario3/apiC/Controllers/Http.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace ApiC.Controllers -{ - [Route("aggregator/text")] - public class Http : Controller - { - [HttpGet] - public string Get() - { - return "C OK!"; - } - } -} \ No newline at end of file diff --git a/dotnet-core/scenario3/apiC/Controllers/Https.cs b/dotnet-core/scenario3/apiC/Controllers/Https.cs deleted file mode 100644 index 833ce16..0000000 --- a/dotnet-core/scenario3/apiC/Controllers/Https.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace ApiC.Controllers -{ - [Route("tls/aggregator/text")] - [RequireHttps] - public class Https : Controller - { - [HttpGet] - public string Get() - { - return "C OK!"; - } - } -} \ No newline at end of file diff --git a/dotnet-core/scenario3/apiC/Program.cs b/dotnet-core/scenario3/apiC/Program.cs deleted file mode 100644 index 050a9e6..0000000 --- a/dotnet-core/scenario3/apiC/Program.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System.IO; -using System.Linq; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace ApiC -{ - public class Program - { - public static void Main(string[] args) - { - var AppConf = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("appsettings.json") - .Build(); - - var host = new WebHostBuilder() - .UseKestrel(options => - { - var cert = AppConf.GetSection("Certificate").Value; - var certPassword = AppConf.GetSection("Password").Value; - options.UseHttps(cert, certPassword); - }) - .UseContentRoot(Directory.GetCurrentDirectory()) - .UseStartup() - .UseUrls(AppConf.GetSection("Urls").GetChildren().Select(x => x.Value).ToArray()) - .Build(); - - host.Run(); - } - } - - public class Startup - { - public Startup(IHostingEnvironment env) - { - var builder = new ConfigurationBuilder() - .SetBasePath(env.ContentRootPath) - .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) - .AddEnvironmentVariables(); - Configuration = builder.Build(); - } - - public IConfigurationRoot Configuration { get; } - - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc(); - } - - public void Configure(IApplicationBuilder app) - { - app.UseMvc(); - } - } -} diff --git a/dotnet-core/scenario3/apiC/apiC.csproj b/dotnet-core/scenario3/apiC/apiC.csproj deleted file mode 100644 index b5c6c45..0000000 --- a/dotnet-core/scenario3/apiC/apiC.csproj +++ /dev/null @@ -1,10 +0,0 @@ - - - netcoreapp1.1 - - - - - - - \ No newline at end of file diff --git a/dotnet-core/scenario3/apiC/appsettings.json b/dotnet-core/scenario3/apiC/appsettings.json deleted file mode 100644 index 6f9c383..0000000 --- a/dotnet-core/scenario3/apiC/appsettings.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "Urls": [ - "http://*:7003", - "https://*:7443" - ], - - //Please do not put certificate information ESPECIALLY passwords into a config file in a real app! - "Certificate": "certificate.pfx", - "Password": "hunter2" -} \ No newline at end of file diff --git a/dotnet-core/scenario3/apiC/certificate.pfx b/dotnet-core/scenario3/apiC/certificate.pfx deleted file mode 100644 index 21256e4..0000000 Binary files a/dotnet-core/scenario3/apiC/certificate.pfx and /dev/null differ diff --git a/dotnet/Dotnet.sln b/dotnet/Dotnet.sln new file mode 100644 index 0000000..b2c0304 --- /dev/null +++ b/dotnet/Dotnet.sln @@ -0,0 +1,65 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hello-world", "hello-world\hello-world.csproj", "{90FB911E-524A-4042-8D07-B6D360833DA6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "scenario1", "scenario1\scenario1.csproj", "{F92C2EF6-6C9E-4AF8-85EA-FF3D960B6D69}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scenario2-ApiA", "scenario2\ApiA\Scenario2-ApiA.csproj", "{D0A52CA3-980A-4980-B220-AA4D4A546434}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scenario2-ApiB", "scenario2\ApiB\Scenario2-ApiB.csproj", "{2E8BE740-AC67-41A5-825A-EA9BD32826B0}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scenario2-ApiC", "scenario2\ApiC\Scenario2-ApiC.csproj", "{9E3EBD1A-66ED-4C23-80EB-63DE1FCCDC7A}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9D4FC375-B68E-422C-81AC-82A44FD5D2C3}" + ProjectSection(SolutionItems) = preProject + scenario2\README-Scenario2.md = scenario2\README-Scenario2.md + scenario3\README-Scenario3.md = scenario3\README-Scenario3.md + scenario1\README-Scenario1.md = scenario1\README-Scenario1.md + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scenario3-ApiC", "scenario3\ApiC\Scenario3-ApiC.csproj", "{7D772047-8899-4867-A140-AF484D24949E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scenario3-ApiB", "scenario3\ApiB\Scenario3-ApiB.csproj", "{2BE4F384-8F6E-411F-AC25-E3A76AC42D14}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scenario3-ApiA", "scenario3\ApiA\Scenario3-ApiA.csproj", "{7B276FD9-AD63-4A84-B2EF-EB8C2B51F15B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {90FB911E-524A-4042-8D07-B6D360833DA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {90FB911E-524A-4042-8D07-B6D360833DA6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {90FB911E-524A-4042-8D07-B6D360833DA6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {90FB911E-524A-4042-8D07-B6D360833DA6}.Release|Any CPU.Build.0 = Release|Any CPU + {F92C2EF6-6C9E-4AF8-85EA-FF3D960B6D69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F92C2EF6-6C9E-4AF8-85EA-FF3D960B6D69}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F92C2EF6-6C9E-4AF8-85EA-FF3D960B6D69}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F92C2EF6-6C9E-4AF8-85EA-FF3D960B6D69}.Release|Any CPU.Build.0 = Release|Any CPU + {D0A52CA3-980A-4980-B220-AA4D4A546434}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D0A52CA3-980A-4980-B220-AA4D4A546434}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D0A52CA3-980A-4980-B220-AA4D4A546434}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D0A52CA3-980A-4980-B220-AA4D4A546434}.Release|Any CPU.Build.0 = Release|Any CPU + {2E8BE740-AC67-41A5-825A-EA9BD32826B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E8BE740-AC67-41A5-825A-EA9BD32826B0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E8BE740-AC67-41A5-825A-EA9BD32826B0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E8BE740-AC67-41A5-825A-EA9BD32826B0}.Release|Any CPU.Build.0 = Release|Any CPU + {9E3EBD1A-66ED-4C23-80EB-63DE1FCCDC7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9E3EBD1A-66ED-4C23-80EB-63DE1FCCDC7A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9E3EBD1A-66ED-4C23-80EB-63DE1FCCDC7A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9E3EBD1A-66ED-4C23-80EB-63DE1FCCDC7A}.Release|Any CPU.Build.0 = Release|Any CPU + {7D772047-8899-4867-A140-AF484D24949E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7D772047-8899-4867-A140-AF484D24949E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7D772047-8899-4867-A140-AF484D24949E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7D772047-8899-4867-A140-AF484D24949E}.Release|Any CPU.Build.0 = Release|Any CPU + {2BE4F384-8F6E-411F-AC25-E3A76AC42D14}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2BE4F384-8F6E-411F-AC25-E3A76AC42D14}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2BE4F384-8F6E-411F-AC25-E3A76AC42D14}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2BE4F384-8F6E-411F-AC25-E3A76AC42D14}.Release|Any CPU.Build.0 = Release|Any CPU + {7B276FD9-AD63-4A84-B2EF-EB8C2B51F15B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7B276FD9-AD63-4A84-B2EF-EB8C2B51F15B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7B276FD9-AD63-4A84-B2EF-EB8C2B51F15B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7B276FD9-AD63-4A84-B2EF-EB8C2B51F15B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/dotnet/hello-world/Program.cs b/dotnet/hello-world/Program.cs new file mode 100644 index 0000000..82f20fa --- /dev/null +++ b/dotnet/hello-world/Program.cs @@ -0,0 +1,4 @@ +var builder = WebApplication.CreateSlimBuilder(args); +var app = builder.Build(); +app.MapGet("/", () => Results.Text("Hello World!")); +await app.RunAsync(); \ No newline at end of file diff --git a/dotnet/hello-world/Properties/launchSettings.json b/dotnet/hello-world/Properties/launchSettings.json new file mode 100644 index 0000000..b70654f --- /dev/null +++ b/dotnet/hello-world/Properties/launchSettings.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "", + "applicationUrl": "http://localhost:7001", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Production" + } + } + } +} diff --git a/dotnet/hello-world/README.md b/dotnet/hello-world/README.md new file mode 100644 index 0000000..a2b0060 --- /dev/null +++ b/dotnet/hello-world/README.md @@ -0,0 +1,11 @@ +ASP.NET CORE +============ +This is a .NET web api 'Hello World!' application. + +Run application: +---------------- +``` +dotnet run --configuration Release +``` + +Server will be online @ http://localhost:5161 \ No newline at end of file diff --git a/dotnet/hello-world/appsettings.json b/dotnet/hello-world/appsettings.json new file mode 100644 index 0000000..0f98448 --- /dev/null +++ b/dotnet/hello-world/appsettings.json @@ -0,0 +1,16 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Critical", + "Microsoft.AspNetCore": "Critical" + } + }, + "AllowedHosts": "*", + "Kestrel": { + "Endpoints": { + "HelloWorld" : { + "Url": "http://localhost:7001" + } + } + } +} diff --git a/dotnet/hello-world/hello-world.csproj b/dotnet/hello-world/hello-world.csproj new file mode 100644 index 0000000..fbde496 --- /dev/null +++ b/dotnet/hello-world/hello-world.csproj @@ -0,0 +1,12 @@ + + + + net9.0 + enable + enable + hello_world + true + true + + + diff --git a/dotnet/scenario1/Program.cs b/dotnet/scenario1/Program.cs new file mode 100644 index 0000000..278dd1f --- /dev/null +++ b/dotnet/scenario1/Program.cs @@ -0,0 +1,11 @@ +using scenario2; + +var builder = WebApplication.CreateSlimBuilder(args); +builder.WebHost.ConfigureKestrelWebServer(); +var app = builder.Build(); + +const string Response = "Hello, World!"; +app.MapGet("/text", () => Results.Text(Response)); +app.MapGet("/tls/text", () => Results.Text(Response)); + +await app.RunAsync(); diff --git a/dotnet/scenario1/Properties/launchSettings.json b/dotnet/scenario1/Properties/launchSettings.json new file mode 100644 index 0000000..15d5242 --- /dev/null +++ b/dotnet/scenario1/Properties/launchSettings.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "tls/text", + "applicationUrl": "https://localhost:7441", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Production" + } + } + } +} diff --git a/dotnet/scenario1/README-Scenario1.md b/dotnet/scenario1/README-Scenario1.md new file mode 100644 index 0000000..47822c2 --- /dev/null +++ b/dotnet/scenario1/README-Scenario1.md @@ -0,0 +1,28 @@ +Routing in ASP.NET Core +======================= + +This is a simple implementation scenario 1 of the spec from https://networknt.github.io/microservices-framework-benchmark/specification/ + +In this sample we again look at using .NET Minimal Apis. + + +Build the app: +------ +Getting the app ready to run should be as simple as opening a console in the project folder and executing +``` +dotnet publish +``` +This will build the app for your machine architecture, e.g. on Windows this gives +``` +> dotnet publish + scenario1 succeeded (14,2s) → bin\Release\net9.0\win-x64\publish\ +``` +Run the app: +------ +After the app has been built by running `dotnet publish`, you can run the app by going into the publish folder shown +above and run the `scenario1` binary. + +You can then call the app using a browser, Postman or another tool at http://localhost:7001/text for http +and https://localhost:7441/tls/text for a https request. + +The certificate is, of course, a self-signed cert. \ No newline at end of file diff --git a/dotnet/scenario1/WebServerConfig.cs b/dotnet/scenario1/WebServerConfig.cs new file mode 100644 index 0000000..92d7439 --- /dev/null +++ b/dotnet/scenario1/WebServerConfig.cs @@ -0,0 +1,15 @@ +namespace scenario2; + +public static class WebServerConfig +{ + public static void ConfigureKestrelWebServer(this ConfigureWebHostBuilder builder) + { + // Certificate is configured in the appsettings.json file + builder.UseKestrelHttpsConfiguration() + .ConfigureKestrel(c => + { + //Set body request size to 0, as we do not expect anything + c.Limits.MaxRequestBodySize = 0; + }); + } +} \ No newline at end of file diff --git a/dotnet/scenario1/appsettings.json b/dotnet/scenario1/appsettings.json new file mode 100644 index 0000000..143c980 --- /dev/null +++ b/dotnet/scenario1/appsettings.json @@ -0,0 +1,24 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Critical", + "Microsoft.AspNetCore": "Critical" + } + }, + "AllowedHosts": "*", + "Kestrel": { + "Endpoints": { + "Text" : { + "Url": "http://0.0.0.0:7001" + }, + "Tls": { + "Url": "https://0.0.0.0:7441", + "SslProtocols": ["Tls13"], + "Certificate": { + "Path": "certificate.pfx", + "Password": "" + } + } + } + } +} diff --git a/dotnet/scenario1/certificate.pfx b/dotnet/scenario1/certificate.pfx new file mode 100644 index 0000000..dfa8f32 Binary files /dev/null and b/dotnet/scenario1/certificate.pfx differ diff --git a/dotnet/scenario1/scenario1.csproj b/dotnet/scenario1/scenario1.csproj new file mode 100644 index 0000000..98b4e6d --- /dev/null +++ b/dotnet/scenario1/scenario1.csproj @@ -0,0 +1,20 @@ + + + + net9.0 + enable + enable + true + true + true + true + link + + + + + Always + + + + diff --git a/dotnet/scenario2/ApiA/CallApiB.cs b/dotnet/scenario2/ApiA/CallApiB.cs new file mode 100644 index 0000000..af3d2b1 --- /dev/null +++ b/dotnet/scenario2/ApiA/CallApiB.cs @@ -0,0 +1,25 @@ +namespace scenario2; + +public class CallApiB +{ + private static HttpClientHandler allowSelfsignedCert = new() + { + ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true + }; + + private static HttpClient bClient = new(allowSelfsignedCert); + + const string AResponse = "A OK!"; + + public static async ValueTask ViaHttp() + { + var bResponse = await bClient.GetStringAsync("http://localhost:7002/chain/text"); + return Results.Text(AResponse + bResponse); + } + + public static async ValueTask ViaHttps() + { + var bResponse = await bClient.GetStringAsync("https://localhost:7442/chain/text"); + return Results.Text(AResponse + bResponse); + } +} \ No newline at end of file diff --git a/dotnet/scenario2/ApiA/Program.cs b/dotnet/scenario2/ApiA/Program.cs new file mode 100644 index 0000000..5f42156 --- /dev/null +++ b/dotnet/scenario2/ApiA/Program.cs @@ -0,0 +1,10 @@ +using scenario2; + +var builder = WebApplication.CreateSlimBuilder(args); +builder.WebHost.ConfigureKestrelWebServer(); +var app = builder.Build(); + +app.MapGet("/chain/text", CallApiB.ViaHttp); +app.MapGet("/tls/chain/text", CallApiB.ViaHttps); + +await app.RunAsync(); \ No newline at end of file diff --git a/dotnet/scenario2/ApiA/Properties/launchSettings.json b/dotnet/scenario2/ApiA/Properties/launchSettings.json new file mode 100644 index 0000000..b37362b --- /dev/null +++ b/dotnet/scenario2/ApiA/Properties/launchSettings.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "tls/chain/text", + "applicationUrl": "https://localhost:7441", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Production" + } + } + } +} diff --git a/dotnet/scenario2/ApiA/Scenario2-ApiA.csproj b/dotnet/scenario2/ApiA/Scenario2-ApiA.csproj new file mode 100644 index 0000000..7a168c2 --- /dev/null +++ b/dotnet/scenario2/ApiA/Scenario2-ApiA.csproj @@ -0,0 +1,21 @@ + + + + net9.0 + enable + enable + true + true + true + true + link + ApiA + + + + + Always + + + + diff --git a/dotnet/scenario2/ApiA/WebServerConfig.cs b/dotnet/scenario2/ApiA/WebServerConfig.cs new file mode 100644 index 0000000..92d7439 --- /dev/null +++ b/dotnet/scenario2/ApiA/WebServerConfig.cs @@ -0,0 +1,15 @@ +namespace scenario2; + +public static class WebServerConfig +{ + public static void ConfigureKestrelWebServer(this ConfigureWebHostBuilder builder) + { + // Certificate is configured in the appsettings.json file + builder.UseKestrelHttpsConfiguration() + .ConfigureKestrel(c => + { + //Set body request size to 0, as we do not expect anything + c.Limits.MaxRequestBodySize = 0; + }); + } +} \ No newline at end of file diff --git a/dotnet/scenario2/ApiA/appsettings.json b/dotnet/scenario2/ApiA/appsettings.json new file mode 100644 index 0000000..670d762 --- /dev/null +++ b/dotnet/scenario2/ApiA/appsettings.json @@ -0,0 +1,24 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Critical", + "Microsoft.AspNetCore": "Critical" + } + }, + "AllowedHosts": "*", + "Kestrel": { + "Endpoints": { + "text" : { + "Url": "http://localhost:7001" + }, + "tls": { + "Url": "https://localhost:7441", + "SslProtocols": ["Tls13"], + "Certificate": { + "Path": "certificate.pfx", + "Password": "" + } + } + } + } +} diff --git a/dotnet/scenario2/ApiA/certificate.pfx b/dotnet/scenario2/ApiA/certificate.pfx new file mode 100644 index 0000000..dfa8f32 Binary files /dev/null and b/dotnet/scenario2/ApiA/certificate.pfx differ diff --git a/dotnet/scenario2/ApiB/CallApiC.cs b/dotnet/scenario2/ApiB/CallApiC.cs new file mode 100644 index 0000000..d88991c --- /dev/null +++ b/dotnet/scenario2/ApiB/CallApiC.cs @@ -0,0 +1,25 @@ +namespace scenario2; + +public class CallApiC +{ + private static HttpClientHandler allowSelfsignedCert = new() + { + ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true + }; + + private static HttpClient cClient = new(allowSelfsignedCert); + + const string BResponse = "B OK!"; + + public static async ValueTask ViaHttp() + { + var cResponse = await cClient.GetStringAsync("http://localhost:7003/chain/text"); + return Results.Text(BResponse + cResponse); + } + + public static async ValueTask ViaHttps() + { + var cResponse = await cClient.GetStringAsync("https://localhost:7443/chain/text"); + return Results.Text(BResponse + cResponse); + } +} \ No newline at end of file diff --git a/dotnet/scenario2/ApiB/Program.cs b/dotnet/scenario2/ApiB/Program.cs new file mode 100644 index 0000000..4a1b1d0 --- /dev/null +++ b/dotnet/scenario2/ApiB/Program.cs @@ -0,0 +1,10 @@ +using scenario2; + +var builder = WebApplication.CreateSlimBuilder(args); +builder.WebHost.ConfigureKestrelWebServer(); +var app = builder.Build(); + +app.MapGet("/chain/text", CallApiC.ViaHttp); +app.MapGet("/tls/chain/text", CallApiC.ViaHttps); + +await app.RunAsync(); \ No newline at end of file diff --git a/dotnet/scenario2/ApiB/Properties/launchSettings.json b/dotnet/scenario2/ApiB/Properties/launchSettings.json new file mode 100644 index 0000000..98e6723 --- /dev/null +++ b/dotnet/scenario2/ApiB/Properties/launchSettings.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "tls/chain/text", + "applicationUrl": "https://localhost:7442", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Production" + } + } + } +} diff --git a/dotnet/scenario2/ApiB/Scenario2-ApiB.csproj b/dotnet/scenario2/ApiB/Scenario2-ApiB.csproj new file mode 100644 index 0000000..b58c482 --- /dev/null +++ b/dotnet/scenario2/ApiB/Scenario2-ApiB.csproj @@ -0,0 +1,21 @@ + + + + net9.0 + enable + enable + true + true + true + true + link + ApiB + + + + + Always + + + + diff --git a/dotnet/scenario2/ApiB/WebServerConfig.cs b/dotnet/scenario2/ApiB/WebServerConfig.cs new file mode 100644 index 0000000..92d7439 --- /dev/null +++ b/dotnet/scenario2/ApiB/WebServerConfig.cs @@ -0,0 +1,15 @@ +namespace scenario2; + +public static class WebServerConfig +{ + public static void ConfigureKestrelWebServer(this ConfigureWebHostBuilder builder) + { + // Certificate is configured in the appsettings.json file + builder.UseKestrelHttpsConfiguration() + .ConfigureKestrel(c => + { + //Set body request size to 0, as we do not expect anything + c.Limits.MaxRequestBodySize = 0; + }); + } +} \ No newline at end of file diff --git a/dotnet/scenario2/ApiB/appsettings.json b/dotnet/scenario2/ApiB/appsettings.json new file mode 100644 index 0000000..741019d --- /dev/null +++ b/dotnet/scenario2/ApiB/appsettings.json @@ -0,0 +1,24 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Critical", + "Microsoft.AspNetCore": "Critical" + } + }, + "AllowedHosts": "*", + "Kestrel": { + "Endpoints": { + "text" : { + "Url": "http://localhost:7002" + }, + "tls": { + "Url": "https://localhost:7442", + "SslProtocols": ["Tls13"], + "Certificate": { + "Path": "certificate.pfx", + "Password": "" + } + } + } + } +} diff --git a/dotnet/scenario2/ApiB/certificate.pfx b/dotnet/scenario2/ApiB/certificate.pfx new file mode 100644 index 0000000..dfa8f32 Binary files /dev/null and b/dotnet/scenario2/ApiB/certificate.pfx differ diff --git a/dotnet/scenario2/ApiC/Program.cs b/dotnet/scenario2/ApiC/Program.cs new file mode 100644 index 0000000..0cbfc95 --- /dev/null +++ b/dotnet/scenario2/ApiC/Program.cs @@ -0,0 +1,11 @@ +using scenario2; + +var builder = WebApplication.CreateSlimBuilder(args); +builder.WebHost.ConfigureKestrelWebServer(); +var app = builder.Build(); + +const string Response = "C OK!"; +app.MapGet("/chain/text", () => Results.Text(Response)); +app.MapGet("/tls/chain/text", () => Results.Text(Response)); + +await app.RunAsync(); \ No newline at end of file diff --git a/dotnet/scenario2/ApiC/Properties/launchSettings.json b/dotnet/scenario2/ApiC/Properties/launchSettings.json new file mode 100644 index 0000000..53a4c6f --- /dev/null +++ b/dotnet/scenario2/ApiC/Properties/launchSettings.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "tls/chain/text", + "applicationUrl": "https://localhost:7443", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Production" + } + } + } +} diff --git a/dotnet/scenario2/ApiC/Scenario2-ApiC.csproj b/dotnet/scenario2/ApiC/Scenario2-ApiC.csproj new file mode 100644 index 0000000..a4ae79c --- /dev/null +++ b/dotnet/scenario2/ApiC/Scenario2-ApiC.csproj @@ -0,0 +1,21 @@ + + + + net9.0 + enable + enable + true + true + true + true + link + ApiC + + + + + Always + + + + diff --git a/dotnet/scenario2/ApiC/WebServerConfig.cs b/dotnet/scenario2/ApiC/WebServerConfig.cs new file mode 100644 index 0000000..92d7439 --- /dev/null +++ b/dotnet/scenario2/ApiC/WebServerConfig.cs @@ -0,0 +1,15 @@ +namespace scenario2; + +public static class WebServerConfig +{ + public static void ConfigureKestrelWebServer(this ConfigureWebHostBuilder builder) + { + // Certificate is configured in the appsettings.json file + builder.UseKestrelHttpsConfiguration() + .ConfigureKestrel(c => + { + //Set body request size to 0, as we do not expect anything + c.Limits.MaxRequestBodySize = 0; + }); + } +} \ No newline at end of file diff --git a/dotnet/scenario2/ApiC/appsettings.json b/dotnet/scenario2/ApiC/appsettings.json new file mode 100644 index 0000000..2e21919 --- /dev/null +++ b/dotnet/scenario2/ApiC/appsettings.json @@ -0,0 +1,24 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Critical", + "Microsoft.AspNetCore": "Critical" + } + }, + "AllowedHosts": "*", + "Kestrel": { + "Endpoints": { + "text" : { + "Url": "http://localhost:7003" + }, + "tls": { + "Url": "https://localhost:7443", + "SslProtocols": ["Tls13"], + "Certificate": { + "Path": "certificate.pfx", + "Password": "" + } + } + } + } +} diff --git a/dotnet/scenario2/ApiC/certificate.pfx b/dotnet/scenario2/ApiC/certificate.pfx new file mode 100644 index 0000000..dfa8f32 Binary files /dev/null and b/dotnet/scenario2/ApiC/certificate.pfx differ diff --git a/dotnet/scenario2/README-Scenario2.md b/dotnet/scenario2/README-Scenario2.md new file mode 100644 index 0000000..de4ec9d --- /dev/null +++ b/dotnet/scenario2/README-Scenario2.md @@ -0,0 +1,39 @@ +Chained calls in ASP.NET Core +======================= + +This is a simple implementation of scenario 2 of the spec from https://networknt.github.io/microservices-framework-benchmark/specification/ + +In this sample we look at how .NET handles chaining calls from one service to another. + +We use the built-in Kestrel web server. The three services run as 3 completely separated processes, only sharing the +underlaying .NET framework. + +This means some code duplication is found, but it makes each service a more natural self-contained entity. + +Each service has its urls and certificate configured in an appsettings.json file. + + +Build the apps: +------ +Getting the app samples ready to run should be as simple as opening a console in each of the three api folders and executing +``` +dotnet publish +``` +This will build the apps for your machine architecture, e.g. on Windows this gives +``` +> dotnet publish + Scenario2-ApiA succeeded (14,4s) → bin\Release\net9.0\win-x64\publish\ +``` + +in each console. + +Run the apps: +------ +After the apps has been built by running `dotnet publish`, you can run the apps by going into the publish folder shown +above and run the `Scenario2-ApiA`, `Scenario2-ApiB` and `Scenario2-Apic` binaries. + +You can then call the app using a browser, Postman or another tool at http://localhost:7001/chain/text for http +and https://localhost:7441/tls/chain/text for a https request. The certificates are, of course, self-signed certs. + +You can do partial calls to apiB and apiC as well. If you call http://localhost:7002/chain/text you should get a +response containing 'B OK!C OK!'. \ No newline at end of file diff --git a/dotnet/scenario3/ApiA/CallApiB.cs b/dotnet/scenario3/ApiA/CallApiB.cs new file mode 100644 index 0000000..bc1da46 --- /dev/null +++ b/dotnet/scenario3/ApiA/CallApiB.cs @@ -0,0 +1,21 @@ +namespace scenario3; + +public class CallApiB +{ + private static HttpClientHandler allowSelfsignedCert = new() + { + ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true + }; + + private static HttpClient bClient = new(allowSelfsignedCert); + + public static async ValueTask ViaHttp() + { + return await bClient.GetStringAsync("http://localhost:7002/aggregator/text"); + } + + public static async ValueTask ViaHttps() + { + return await bClient.GetStringAsync("https://localhost:7442/tls/aggregator/text"); + } +} \ No newline at end of file diff --git a/dotnet/scenario3/ApiA/CallApiC.cs b/dotnet/scenario3/ApiA/CallApiC.cs new file mode 100644 index 0000000..4b38112 --- /dev/null +++ b/dotnet/scenario3/ApiA/CallApiC.cs @@ -0,0 +1,29 @@ +using System.Text; + +namespace scenario3; + +public class CallApiC +{ + private static HttpClientHandler allowSelfsignedCert = new() + { + ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true + }; + + private static HttpClient cClient = new(allowSelfsignedCert); + private static Uri httpUrl = new("http://localhost:7003/aggregator/text"); + private static Uri httpsUrl = new("https://localhost:7443/tls/aggregator/text"); + private static StringContent cRequest = new StringContent("C OK!", Encoding.UTF8, "text/plain"); + + + public static async ValueTask ViaHttp() + { + var response = await cClient.PostAsync(httpUrl, cRequest); + return await response.Content.ReadAsStringAsync(); + } + + public static async ValueTask ViaHttps() + { + var response = await cClient.PostAsync(httpsUrl, cRequest); + return await response.Content.ReadAsStringAsync(); + } +} \ No newline at end of file diff --git a/dotnet/scenario3/ApiA/CallApisInParallel.cs b/dotnet/scenario3/ApiA/CallApisInParallel.cs new file mode 100644 index 0000000..bc6d867 --- /dev/null +++ b/dotnet/scenario3/ApiA/CallApisInParallel.cs @@ -0,0 +1,21 @@ +namespace scenario3; + +public static class ParallelCalls +{ + const string AResponse = "A OK!"; + public static async ValueTask CallApisViaHttp() + { + var bResult = CallApiB.ViaHttp(); + var cResult = CallApiC.ViaHttp(); + + return Results.Text(AResponse + await bResult + await cResult); + } + + public static async ValueTask CallApisViaHttps() + { + var bResult = CallApiB.ViaHttps(); + var cResult = CallApiC.ViaHttps(); + + return Results.Text(AResponse + await bResult + await cResult); + } +} \ No newline at end of file diff --git a/dotnet/scenario3/ApiA/Program.cs b/dotnet/scenario3/ApiA/Program.cs new file mode 100644 index 0000000..b96baa0 --- /dev/null +++ b/dotnet/scenario3/ApiA/Program.cs @@ -0,0 +1,10 @@ +using scenario3; + +var builder = WebApplication.CreateSlimBuilder(args); +builder.WebHost.ConfigureKestrelWebServer(); +var app = builder.Build(); + +app.MapGet("/aggregator/text", ParallelCalls.CallApisViaHttp); +app.MapGet("/tls/aggregator/text", ParallelCalls.CallApisViaHttps); + +await app.RunAsync(); \ No newline at end of file diff --git a/dotnet/scenario3/ApiA/Properties/launchSettings.json b/dotnet/scenario3/ApiA/Properties/launchSettings.json new file mode 100644 index 0000000..73fd1d2 --- /dev/null +++ b/dotnet/scenario3/ApiA/Properties/launchSettings.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "tls/aggregator/text", + "applicationUrl": "https://localhost:7441", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Production" + } + } + } +} diff --git a/dotnet/scenario3/ApiA/Scenario3-ApiA.csproj b/dotnet/scenario3/ApiA/Scenario3-ApiA.csproj new file mode 100644 index 0000000..7a168c2 --- /dev/null +++ b/dotnet/scenario3/ApiA/Scenario3-ApiA.csproj @@ -0,0 +1,21 @@ + + + + net9.0 + enable + enable + true + true + true + true + link + ApiA + + + + + Always + + + + diff --git a/dotnet/scenario3/ApiA/WebServerConfig.cs b/dotnet/scenario3/ApiA/WebServerConfig.cs new file mode 100644 index 0000000..a557da0 --- /dev/null +++ b/dotnet/scenario3/ApiA/WebServerConfig.cs @@ -0,0 +1,15 @@ +namespace scenario3; + +public static class WebServerConfig +{ + public static void ConfigureKestrelWebServer(this ConfigureWebHostBuilder builder) + { + // Certificate is configured in the appsettings.json file + builder.UseKestrelHttpsConfiguration() + .ConfigureKestrel(c => + { + //Set body request size to 0, as we do not expect anything + c.Limits.MaxRequestBodySize = 0; + }); + } +} \ No newline at end of file diff --git a/dotnet/scenario3/ApiA/appsettings.json b/dotnet/scenario3/ApiA/appsettings.json new file mode 100644 index 0000000..8d3aa58 --- /dev/null +++ b/dotnet/scenario3/ApiA/appsettings.json @@ -0,0 +1,24 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Critical", + "Microsoft.AspNetCore": "Critical" + } + }, + "AllowedHosts": "*", + "Kestrel": { + "Endpoints": { + "text": { + "Url": "http://0.0.0.0:7001" + }, + "tls": { + "Url": "https://0.0.0.0:7441", + "SslProtocols": ["Tls13"], + "Certificate": { + "Path": "certificate.pfx", + "Password": "" + } + } + } + } +} diff --git a/dotnet/scenario3/ApiA/certificate.pfx b/dotnet/scenario3/ApiA/certificate.pfx new file mode 100644 index 0000000..dfa8f32 Binary files /dev/null and b/dotnet/scenario3/ApiA/certificate.pfx differ diff --git a/dotnet/scenario3/ApiB/Program.cs b/dotnet/scenario3/ApiB/Program.cs new file mode 100644 index 0000000..4855fbc --- /dev/null +++ b/dotnet/scenario3/ApiB/Program.cs @@ -0,0 +1,11 @@ +using scenario3; + +var builder = WebApplication.CreateSlimBuilder(args); +builder.WebHost.ConfigureKestrelWebServer(); +var app = builder.Build(); + +const string Response = "B OK!"; +app.MapGet("/aggregator/text",() => Results.Text(Response)); +app.MapGet("/tls/aggregator/text",() => Results.Text(Response)); + +await app.RunAsync(); \ No newline at end of file diff --git a/dotnet/scenario3/ApiB/Properties/launchSettings.json b/dotnet/scenario3/ApiB/Properties/launchSettings.json new file mode 100644 index 0000000..3654a5c --- /dev/null +++ b/dotnet/scenario3/ApiB/Properties/launchSettings.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "launchUrl": "tls/aggregator/text", + "applicationUrl": "https://localhost:7442", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Production" + } + } + } +} diff --git a/dotnet/scenario3/ApiB/Scenario3-ApiB.csproj b/dotnet/scenario3/ApiB/Scenario3-ApiB.csproj new file mode 100644 index 0000000..b58c482 --- /dev/null +++ b/dotnet/scenario3/ApiB/Scenario3-ApiB.csproj @@ -0,0 +1,21 @@ + + + + net9.0 + enable + enable + true + true + true + true + link + ApiB + + + + + Always + + + + diff --git a/dotnet/scenario3/ApiB/WebServerConfig.cs b/dotnet/scenario3/ApiB/WebServerConfig.cs new file mode 100644 index 0000000..a557da0 --- /dev/null +++ b/dotnet/scenario3/ApiB/WebServerConfig.cs @@ -0,0 +1,15 @@ +namespace scenario3; + +public static class WebServerConfig +{ + public static void ConfigureKestrelWebServer(this ConfigureWebHostBuilder builder) + { + // Certificate is configured in the appsettings.json file + builder.UseKestrelHttpsConfiguration() + .ConfigureKestrel(c => + { + //Set body request size to 0, as we do not expect anything + c.Limits.MaxRequestBodySize = 0; + }); + } +} \ No newline at end of file diff --git a/dotnet/scenario3/ApiB/appsettings.json b/dotnet/scenario3/ApiB/appsettings.json new file mode 100644 index 0000000..f2c4c07 --- /dev/null +++ b/dotnet/scenario3/ApiB/appsettings.json @@ -0,0 +1,24 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Critical", + "Microsoft.AspNetCore": "Critical" + } + }, + "AllowedHosts": "*", + "Kestrel": { + "Endpoints": { + "text": { + "Url": "http://0.0.0.0:7002" + }, + "tls": { + "Url": "https://0.0.0.0:7442", + "SslProtocols": ["Tls13"], + "Certificate": { + "Path": "certificate.pfx", + "Password": "" + } + } + } + } +} diff --git a/dotnet/scenario3/ApiB/certificate.pfx b/dotnet/scenario3/ApiB/certificate.pfx new file mode 100644 index 0000000..dfa8f32 Binary files /dev/null and b/dotnet/scenario3/ApiB/certificate.pfx differ diff --git a/dotnet/scenario3/ApiC/Program.cs b/dotnet/scenario3/ApiC/Program.cs new file mode 100644 index 0000000..b058e1e --- /dev/null +++ b/dotnet/scenario3/ApiC/Program.cs @@ -0,0 +1,22 @@ +using Microsoft.AspNetCore.Mvc; +using scenario3; + +var builder = WebApplication.CreateSlimBuilder(args); +builder.WebHost.ConfigureKestrelWebServer(); +var app = builder.Build(); + +app.MapPost("/aggregator/text", async (HttpRequest request) => +{ + using var reader = new StreamReader(request.Body); + var content = await reader.ReadToEndAsync(); + return Results.Text(content); +}); + +app.MapPost("/tls/aggregator/text", async (HttpRequest request) => +{ + using var reader = new StreamReader(request.Body); + var content = await reader.ReadToEndAsync(); + return Results.Text(content); +}); + +await app.RunAsync(); \ No newline at end of file diff --git a/dotnet/scenario3/ApiC/Properties/launchSettings.json b/dotnet/scenario3/ApiC/Properties/launchSettings.json new file mode 100644 index 0000000..0436398 --- /dev/null +++ b/dotnet/scenario3/ApiC/Properties/launchSettings.json @@ -0,0 +1,15 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "launchUrl": "tls/aggregator/text", + "applicationUrl": "https://localhost:7443", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Production" + } + } + } +} diff --git a/dotnet/scenario3/ApiC/Scenario3-ApiC.csproj b/dotnet/scenario3/ApiC/Scenario3-ApiC.csproj new file mode 100644 index 0000000..a4ae79c --- /dev/null +++ b/dotnet/scenario3/ApiC/Scenario3-ApiC.csproj @@ -0,0 +1,21 @@ + + + + net9.0 + enable + enable + true + true + true + true + link + ApiC + + + + + Always + + + + diff --git a/dotnet/scenario3/ApiC/WebServerConfig.cs b/dotnet/scenario3/ApiC/WebServerConfig.cs new file mode 100644 index 0000000..3ccf2d0 --- /dev/null +++ b/dotnet/scenario3/ApiC/WebServerConfig.cs @@ -0,0 +1,10 @@ +namespace scenario3; + +public static class WebServerConfig +{ + public static void ConfigureKestrelWebServer(this ConfigureWebHostBuilder builder) + { + // Certificate is configured in the appsettings.json file + builder.UseKestrelHttpsConfiguration(); + } +} \ No newline at end of file diff --git a/dotnet/scenario3/ApiC/appsettings.json b/dotnet/scenario3/ApiC/appsettings.json new file mode 100644 index 0000000..ae7d706 --- /dev/null +++ b/dotnet/scenario3/ApiC/appsettings.json @@ -0,0 +1,24 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Critical", + "Microsoft.AspNetCore": "Critical" + } + }, + "AllowedHosts": "*", + "Kestrel": { + "Endpoints": { + "text": { + "Url": "http://0.0.0.0:7003" + }, + "tls": { + "Url": "https://0.0.0.0:7443", + "SslProtocols": ["Tls13"], + "Certificate": { + "Path": "certificate.pfx", + "Password": "" + } + } + } + } +} diff --git a/dotnet/scenario3/ApiC/certificate.pfx b/dotnet/scenario3/ApiC/certificate.pfx new file mode 100644 index 0000000..dfa8f32 Binary files /dev/null and b/dotnet/scenario3/ApiC/certificate.pfx differ diff --git a/dotnet/scenario3/README-Scenario3.md b/dotnet/scenario3/README-Scenario3.md new file mode 100644 index 0000000..2aa2e5a --- /dev/null +++ b/dotnet/scenario3/README-Scenario3.md @@ -0,0 +1,36 @@ +Chained calls in ASP.NET Core +======================= + +This is a simple implementation of scenario 3 of the spec from https://networknt.github.io/microservices-framework-benchmark/specification/ + +In this sample we look at how .NET handles chaining calls from one service to another. + +We use the built-in Kestrel web server. The three services run as 3 completely separated processes, +only sharing the underlaying .NET framework. + +This means some code duplication is found, but it makes each service a more natural self-contained entity. + +Each service has its urls and certificate configured in an appsettings.json file. + + +Build the apps: +------ +Getting the app samples ready to run should be as simple as opening a console in each of the three api folders and executing +``` +dotnet publish +``` +This will build the apps for your machine architecture, e.g. on Windows this gives +``` +> dotnet publish + Scenario3-ApiA succeeded (13,6s) → bin\Release\net9.0\win-x64\publish\ +``` + +in each console. + +Run the app: +------ +After the apps has been built by running `dotnet publish`, you can run the apps by going into the publish folder shown +above and run the `Scenario3-ApiA`, `Scenario3-ApiB` and `Scenario3-Apic` binaries. + +You can then call the app using a browser, Postman or another tool at http://localhost:7001/aggregator/text +for http and https://localhost:7441/tls/aggregator/text for a https request. The certificates are, of course, self-signed certs. \ No newline at end of file diff --git a/helidon/.gitignore b/helidon/.gitignore new file mode 100644 index 0000000..f8b92c3 --- /dev/null +++ b/helidon/.gitignore @@ -0,0 +1,2 @@ +.gradle +build diff --git a/helidon/README.md b/helidon/README.md new file mode 100644 index 0000000..6ff08c7 --- /dev/null +++ b/helidon/README.md @@ -0,0 +1,11 @@ +To compile: + +``` +./gradlew clean shadowJar +``` + +to run: + +``` +java -jar build/libs/helidon-1.0-SNAPSHOT-all.jar +``` diff --git a/helidon/build.gradle b/helidon/build.gradle new file mode 100644 index 0000000..9da71ad --- /dev/null +++ b/helidon/build.gradle @@ -0,0 +1,40 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '8.1.1' + id 'org.graalvm.buildtools.native' version '0.9.27' +} + +group = 'org.example' +version = '1.0-SNAPSHOT' + +repositories { + mavenCentral() + gradlePluginPortal() +} + +dependencies { + implementation 'io.helidon.webserver:helidon-webserver:4.0.0-RC1' +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +graalvmNative { + binaries { + main { + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(21) + vendor = JvmVendorSpec.matching("Oracle Corporation") + } + useFatJar = true + } + } +} + +application { + mainClass = 'Example' +} diff --git a/helidon/gradle/wrapper/gradle-wrapper.properties b/helidon/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..3fa8f86 --- /dev/null +++ b/helidon/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/helidon/gradlew b/helidon/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/helidon/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/helidon/gradlew.bat b/helidon/gradlew.bat new file mode 100644 index 0000000..6689b85 --- /dev/null +++ b/helidon/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/helidon/settings.gradle b/helidon/settings.gradle new file mode 100644 index 0000000..9074c5d --- /dev/null +++ b/helidon/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'helidon' diff --git a/helidon/src/main/java/Example.java b/helidon/src/main/java/Example.java new file mode 100644 index 0000000..2d8c84f --- /dev/null +++ b/helidon/src/main/java/Example.java @@ -0,0 +1,16 @@ +import io.helidon.webserver.WebServer; + +public class Example { + + public static void main(String[] args) { + WebServer webServer = WebServer.builder() + .routing((rules) -> { + rules.get("/", ((req, res) -> { + res.send("Hello World"); + })); + }) + .port(8080) + .build() + .start(); + } +} diff --git a/iris/server.go b/iris/server.go index cfaafd8..12448ca 100644 --- a/iris/server.go +++ b/iris/server.go @@ -1,12 +1,11 @@ package main -import ("github.com/kataras/iris") +import "github.com/kataras/iris" func main() { - iris.Config.Charset = "UTF-8" // this is the default, you don't have to set it manually - - iris.Get("/", func(ctx *iris.Context) { - ctx.Text(iris.StatusOK, "Hello World!") + app := iris.New() + app.Get("/", func(ctx iris.Context) { + ctx.WriteString("Hello World!") }) - iris.Listen(":8080") + app.Run(iris.Addr(":8080")) } diff --git a/javalin/pom.xml b/javalin/pom.xml new file mode 100644 index 0000000..2ba6512 --- /dev/null +++ b/javalin/pom.xml @@ -0,0 +1,90 @@ + + 4.0.0 + com.networknt + javalin-3 + 1.0-SNAPSHOT + + + 1.8 + 1.8 + 1.8 + + 9.4.48.v20220622 + + com.networknt.example.ExampleApplication + + + + + io.javalin + javalin + 6.3.0 + + + org.slf4j + slf4j-simple + 2.0.16 + + + + + + + javalin-3 + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.2 + + + package + + shade + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + ${application.class} + + + + + + + + + + + + + diff --git a/javalin/src/main/java/com/networknt/example/ExampleApplication.java b/javalin/src/main/java/com/networknt/example/ExampleApplication.java new file mode 100644 index 0000000..301feff --- /dev/null +++ b/javalin/src/main/java/com/networknt/example/ExampleApplication.java @@ -0,0 +1,35 @@ +package com.networknt.example; + +import io.javalin.Javalin; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.util.ssl.SslContextFactory; + +public class ExampleApplication { + + public static void main(String[] args) { + // Get example from https://github.com/javalin/javalin/blob/master/javalin/src/test/java/io/javalin/examples/HelloWorldSecure.java#L22-L30 + Javalin.create(config -> { + config.jetty.addConnector((server, httpConfiguration) -> { + ServerConnector sslConnector = new ServerConnector(server, getSslContextFactory()); + sslConnector.setPort(443); + return sslConnector; + }); + config.jetty.addConnector((server, httpConfiguration) -> { + ServerConnector connector = new ServerConnector(server); + connector.setPort(80); + return connector; + }); + + }) + .start() + .get("/", ctx -> ctx.result("Hello World")); + + } + + private static SslContextFactory.Server getSslContextFactory() { + SslContextFactory.Server sslContextFactory = new SslContextFactory.Server(); + sslContextFactory.setKeyStorePath(ExampleApplication.class.getResource("/keystore.jks").toExternalForm()); + sslContextFactory.setKeyStorePassword("password"); + return sslContextFactory; + } +} diff --git a/javalin/src/main/resources/keystore.jks b/javalin/src/main/resources/keystore.jks new file mode 100644 index 0000000..feab9b6 Binary files /dev/null and b/javalin/src/main/resources/keystore.jks differ diff --git a/javalin/src/main/resources/logback.xml b/javalin/src/main/resources/logback.xml new file mode 100644 index 0000000..8aa2270 --- /dev/null +++ b/javalin/src/main/resources/logback.xml @@ -0,0 +1,12 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + diff --git a/jfinal/pom.xml b/jfinal/pom.xml index af5d3a9..03af26f 100644 --- a/jfinal/pom.xml +++ b/jfinal/pom.xml @@ -16,7 +16,7 @@ junit junit - 3.8.1 + 4.13.1 test @@ -37,7 +37,7 @@ mysql mysql-connector-java - 5.1.20 + 8.0.28 com.alibaba diff --git a/jooby-2.x/README.md b/jooby-2.x/README.md new file mode 100644 index 0000000..e2cc268 --- /dev/null +++ b/jooby-2.x/README.md @@ -0,0 +1,33 @@ +[Jooby 2.x](https://jooby.io) + +## hello world! + +Java: + +```java +import io.jooby.Jooby; + +public class App extends Jooby { + + { + get("/", ctx -> ctx.sendString("Hello World!")); + } + + public static void main(final String[] args) { + run(App::new, args); + } +} + +``` + +## build + +``` +mvn package +``` + +# run + +``` +java -jar target/jooby-2.x.jar +``` diff --git a/jooby-2.x/conf/logback.xml b/jooby-2.x/conf/logback.xml new file mode 100644 index 0000000..2d1c514 --- /dev/null +++ b/jooby-2.x/conf/logback.xml @@ -0,0 +1,11 @@ + + + + + [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n + + + + + + diff --git a/jooby-2.x/pom.xml b/jooby-2.x/pom.xml new file mode 100644 index 0000000..36dc30e --- /dev/null +++ b/jooby-2.x/pom.xml @@ -0,0 +1,66 @@ + + + + 4.0.0 + + io.jooby + jooby + 2.0.0 + + jooby + + + 2.0.0.M1 + + example.App + + + + + + io.jooby + jooby-utow + ${jooby.version} + + + + + jooby-2.x + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + + package + + shade + + + + + + ${application.class} + + + + + + + + + + + diff --git a/jooby-2.x/src/main/java/example/App.java b/jooby-2.x/src/main/java/example/App.java new file mode 100644 index 0000000..babc9b0 --- /dev/null +++ b/jooby-2.x/src/main/java/example/App.java @@ -0,0 +1,16 @@ +package example; + +import io.jooby.Jooby; +import static io.jooby.ExecutionMode.EVENT_LOOP; + +public class App extends Jooby { + + { + get("/", ctx -> ctx.sendString("Hello World!")); + } + + public static void main(final String[] args) { + run(App::new, EVENT_LOOP, args); + } + +} diff --git a/light-java/a/pom.xml b/light-4j/pom.xml similarity index 53% rename from light-java/a/pom.xml rename to light-4j/pom.xml index 82ad2f3..ade88f9 100644 --- a/light-java/a/pom.xml +++ b/light-4j/pom.xml @@ -1,117 +1,47 @@ - - org.sonatype.oss - oss-parent - 5 - 4.0.0 - io.swagger - swagger-light-java + com.networknt + plaintext jar - swagger-light-java + plaintext 1.0.0 - - 2.2.0 - - 1.8 + 11 UTF-8 - 0.1.7 - 2.8.2 - 1.7.21 - 0.5.2 - 4.5.3 - 2.6 - 2.5 - 1.10 - 1.2 - 3.1.2 - 1.1.7 - 4.12 - 2.1.0-beta.124 - 1.4.10.Final - 2.2.0 - 4.5.2 - 4.1.2 - 1.5.10 + 2.3.6-SNAPSHOT + 2.19.4 + 2.0.17 + 1.5.37 + 4.13.2 + 2.4.1.Final com.networknt config - ${version.framework} + ${version.light-4j} com.networknt utility - ${version.framework} + ${version.light-4j} com.networknt - security - ${version.framework} - - - com.networknt - client - ${version.framework} - - - com.networknt - audit - ${version.framework} - - - com.networknt - info - ${version.framework} - - - com.networknt - validator - ${version.framework} - - - com.networknt - status - ${version.framework} - - - com.networknt - exception - ${version.framework} - - - com.networknt - body - ${version.framework} - - - com.networknt - mask - ${version.framework} - - - com.networknt - swagger - ${version.framework} - - - com.networknt - metrics - ${version.framework} + handler + ${version.light-4j} com.networknt - handler - ${version.framework} + service + ${version.light-4j} com.networknt server - ${version.framework} + ${version.light-4j} @@ -124,11 +54,6 @@ jackson-core ${version.jackson} - - com.jayway.jsonpath - json-path - ${version.jsonpath} - ch.qos.logback logback-classic @@ -139,11 +64,6 @@ undertow-core ${version.undertow} - - io.swagger - swagger-annotations - ${version.swagger} - @@ -152,13 +72,6 @@ ${version.junit} test - - org.apache.httpcomponents - httpclient - ${version.httpclient} - test - - diff --git a/light-java/a/src/main/java/Example.java b/light-4j/src/main/java/Example.java similarity index 93% rename from light-java/a/src/main/java/Example.java rename to light-4j/src/main/java/Example.java index 2a63956..3dfb83a 100644 --- a/light-java/a/src/main/java/Example.java +++ b/light-4j/src/main/java/Example.java @@ -1,4 +1,4 @@ -import com.networknt.server.HandlerProvider; +import com.networknt.handler.HandlerProvider; import io.undertow.Handlers; import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; diff --git a/light-4j/src/main/resources/config/server.keystore b/light-4j/src/main/resources/config/server.keystore new file mode 100644 index 0000000..feab9b6 Binary files /dev/null and b/light-4j/src/main/resources/config/server.keystore differ diff --git a/light-4j/src/main/resources/config/server.truststore b/light-4j/src/main/resources/config/server.truststore new file mode 100644 index 0000000..fb0c19c Binary files /dev/null and b/light-4j/src/main/resources/config/server.truststore differ diff --git a/light-4j/src/main/resources/config/server.yml b/light-4j/src/main/resources/config/server.yml new file mode 100644 index 0000000..0caff51 --- /dev/null +++ b/light-4j/src/main/resources/config/server.yml @@ -0,0 +1,67 @@ +# Server configuration +--- +# This is the default binding address if the service is dockerized. +ip: 0.0.0.0 + +# Http port if enableHttp is true. It will be ignored if dynamicPort is true. +httpPort: 8080 + +# Enable HTTP should be false by default. It should be only used for testing with clients or tools +# that don't support https or very hard to import the certificate. Otherwise, https should be used. +# When enableHttp, you must set enableHttps to false, otherwise, this flag will be ignored. There is +# only one protocol will be used for the server at anytime. If both http and https are true, only +# https listener will be created and the server will bind to https port only. +enableHttp: true + +# Https port if enableHttps is true. It will be ignored if dynamicPort is true. +httpsPort: 8443 + +# Enable HTTPS should be true on official environment and most dev environments. +enableHttps: true + +# Http/2 is enabled by default for better performance and it works with the client module +enableHttp2: true + +# Keystore file name in config folder. KeystorePass is in secret.yml to access it. +keystoreName: server.keystore + +# Keystore password +keystorePass: password + +# Private key password +keyPass: password + +# Flag that indicate if two way TLS is enabled. Not recommended in docker container. +enableTwoWayTls: false + +# Truststore file name in config folder. TruststorePass is in secret.yml to access it. +truststoreName: server.truststore + +# Truststore password +truststorePass: password + +# Unique service identifier. Used in service registration and discovery etc. +serviceId: com.networknt.plaintext-1.0.0 + +# Flag to enable self service registration. This should be turned on on official test and production. And +# dyanmicPort should be enabled if any orchestration tool is used like Kubernetes. +enableRegistry: false + +# Dynamic port is used in situation that multiple services will be deployed on the same host and normally +# you will have enableRegistry set to true so that other services can find the dynamic port service. When +# deployed to Kubernetes cluster, the Pod must be annotated as hostNetwork: true +dynamicPort: false + +# Minimum port range. This define a range for the dynamic allocated ports so that it is easier to setup +# firewall rule to enable this range. Default 2400 to 2500 block has 100 port numbers and should be +# enough for most cases unless you are using a big bare metal box as Kubernetes node that can run 1000s pods +minPort: 2400 + +# Maximum port rang. The range can be customized to adopt your network security policy and can be increased or +# reduced to ease firewall rules. +maxPort: 2500 + +# environment tag that will be registered on consul to support multiple instances per env for testing. +# https://github.com/networknt/light-doc/blob/master/docs/content/design/env-segregation.md +# This tag should only be set for testing env, not production. The production certification process will enforce it. +# environment: test1 diff --git a/light-4j/src/main/resources/config/service.yml b/light-4j/src/main/resources/config/service.yml new file mode 100644 index 0000000..9d9add7 --- /dev/null +++ b/light-4j/src/main/resources/config/service.yml @@ -0,0 +1,5 @@ +# Singleton service factory configuration/IoC injection +singletons: +# HandlerProvider implementation +- com.networknt.handler.HandlerProvider: + - Example diff --git a/light-java/a/src/main/resources/logback.xml b/light-4j/src/main/resources/logback.xml similarity index 100% rename from light-java/a/src/main/resources/logback.xml rename to light-4j/src/main/resources/logback.xml diff --git a/light-java/a/src/main/resources/META-INF/services/com.networknt.server.HandlerProvider b/light-java/a/src/main/resources/META-INF/services/com.networknt.server.HandlerProvider deleted file mode 100644 index 0c3c67e..0000000 --- a/light-java/a/src/main/resources/META-INF/services/com.networknt.server.HandlerProvider +++ /dev/null @@ -1 +0,0 @@ -Example \ No newline at end of file diff --git a/light-java/a/src/main/resources/config/server.json b/light-java/a/src/main/resources/config/server.json deleted file mode 100644 index 276acff..0000000 --- a/light-java/a/src/main/resources/config/server.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "description": "server config", - "ip": "0.0.0.0", - "port": 8080 -} diff --git a/micronaut-reactor/micronaut-cli.yml b/micronaut-reactor/micronaut-cli.yml new file mode 100644 index 0000000..c7646b7 --- /dev/null +++ b/micronaut-reactor/micronaut-cli.yml @@ -0,0 +1,5 @@ +profile: service +defaultPackage: hello +--- +testFramework: junit +sourceLanguage: java \ No newline at end of file diff --git a/micronaut-reactor/pom.xml b/micronaut-reactor/pom.xml new file mode 100644 index 0000000..87c7040 --- /dev/null +++ b/micronaut-reactor/pom.xml @@ -0,0 +1,209 @@ + + + 4.0.0 + hello + micronaut-reactor + 0.1.0-SNAPSHOT + + + 1.2.10 + 8 + ${jdk.version} + ${jdk.version} + UTF-8 + UTF-8 + hello.ServerApp + 2.22.2 + 2.22.2 + 3.3.2.RELEASE + + + + + jcenter.bintray.com + https://jcenter.bintray.com + + + + + + + io.micronaut + micronaut-bom + ${micronaut.version} + pom + import + + + + + + + io.micronaut + micronaut-inject + compile + + + io.micronaut + micronaut-validation + compile + + + io.micronaut + micronaut-runtime + compile + + + javax.annotation + javax.annotation-api + compile + + + io.micronaut + micronaut-http-server-netty + compile + + + io.micronaut + micronaut-http-client + compile + + + io.micronaut + micronaut-security + + + io.projectreactor + reactor-core + ${reactor.version} + + + ch.qos.logback + logback-classic + 1.2.3 + runtime + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + package + + shade + + + + + ${exec.mainClass} + + + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + java + + -classpath + + -noverify + -XX:TieredStopAtLevel=1 + -Dcom.sun.management.jmxremote + + + ${exec.mainClass} + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + true + + %regex[.*] + + + + + org.apache.maven.plugins + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + + + integration-test + verify + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + + -parameters + + + + io.micronaut + micronaut-inject-java + 1.2.10 + + + io.micronaut + micronaut-validation + 1.2.10 + + + + + + test-compile + + testCompile + + + + -parameters + + + + io.micronaut + micronaut-inject-java + 1.2.10 + + + io.micronaut + micronaut-validation + 1.2.10 + + + + + + + + + + diff --git a/micronaut-reactor/src/main/java/hello/HelloController.java b/micronaut-reactor/src/main/java/hello/HelloController.java new file mode 100644 index 0000000..955cee1 --- /dev/null +++ b/micronaut-reactor/src/main/java/hello/HelloController.java @@ -0,0 +1,15 @@ +package hello; + +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; +import reactor.core.publisher.Mono; + +@Controller("/") +public class HelloController { + + @Get("/") + public Mono greet() { + return Mono.just("Hello World!"); + } + +} diff --git a/micronaut-reactor/src/main/java/hello/ServerApp.java b/micronaut-reactor/src/main/java/hello/ServerApp.java new file mode 100644 index 0000000..54d2fe3 --- /dev/null +++ b/micronaut-reactor/src/main/java/hello/ServerApp.java @@ -0,0 +1,10 @@ +package hello; + +import io.micronaut.runtime.Micronaut; + +public class ServerApp { + + public static void main(String[] args) { + Micronaut.run(ServerApp.class); + } +} \ No newline at end of file diff --git a/micronaut-reactor/src/main/resources/application.yml b/micronaut-reactor/src/main/resources/application.yml new file mode 100644 index 0000000..69f71b4 --- /dev/null +++ b/micronaut-reactor/src/main/resources/application.yml @@ -0,0 +1,6 @@ +micronaut: + application: + name: micronaut-reactor + ssl: + enabled: true + buildSelfSigned: true \ No newline at end of file diff --git a/micronaut-reactor/src/main/resources/logback.xml b/micronaut-reactor/src/main/resources/logback.xml new file mode 100644 index 0000000..8221870 --- /dev/null +++ b/micronaut-reactor/src/main/resources/logback.xml @@ -0,0 +1,15 @@ + + + + false + + + %cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n + + + + + + + diff --git a/micronaut-rxjava/micronaut-cli.yml b/micronaut-rxjava/micronaut-cli.yml new file mode 100644 index 0000000..c7646b7 --- /dev/null +++ b/micronaut-rxjava/micronaut-cli.yml @@ -0,0 +1,5 @@ +profile: service +defaultPackage: hello +--- +testFramework: junit +sourceLanguage: java \ No newline at end of file diff --git a/micronaut-rxjava/pom.xml b/micronaut-rxjava/pom.xml new file mode 100644 index 0000000..65557a1 --- /dev/null +++ b/micronaut-rxjava/pom.xml @@ -0,0 +1,203 @@ + + + 4.0.0 + hello + micronaut-rxjava + 0.1.0-SNAPSHOT + + + 1.2.10 + 8 + ${jdk.version} + ${jdk.version} + UTF-8 + UTF-8 + hello.ServerApp + 2.22.2 + 2.22.2 + + + + + jcenter.bintray.com + https://jcenter.bintray.com + + + + + + + io.micronaut + micronaut-bom + ${micronaut.version} + pom + import + + + + + + + io.micronaut + micronaut-inject + compile + + + io.micronaut + micronaut-validation + compile + + + io.micronaut + micronaut-runtime + compile + + + io.micronaut + micronaut-security + + + javax.annotation + javax.annotation-api + compile + + + io.micronaut + micronaut-http-server-netty + compile + + + io.micronaut + micronaut-http-client + compile + + + ch.qos.logback + logback-classic + 1.2.3 + runtime + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.1.0 + + + package + + shade + + + + + ${exec.mainClass} + + + + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + java + + -classpath + + -noverify + -XX:TieredStopAtLevel=1 + -Dcom.sun.management.jmxremote + + + ${exec.mainClass} + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + true + + %regex[.*] + + + + + org.apache.maven.plugins + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + + + integration-test + verify + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + + -parameters + + + + io.micronaut + micronaut-inject-java + 1.2.10 + + + io.micronaut + micronaut-validation + 1.2.10 + + + + + + test-compile + + testCompile + + + + -parameters + + + + io.micronaut + micronaut-inject-java + 1.2.10 + + + io.micronaut + micronaut-validation + 1.2.10 + + + + + + + + + + diff --git a/micronaut-rxjava/src/main/java/hello/HelloController.java b/micronaut-rxjava/src/main/java/hello/HelloController.java new file mode 100644 index 0000000..d6ee853 --- /dev/null +++ b/micronaut-rxjava/src/main/java/hello/HelloController.java @@ -0,0 +1,15 @@ +package hello; + +import io.micronaut.http.annotation.Controller; +import io.micronaut.http.annotation.Get; +import io.reactivex.Single; + +@Controller("/") +public class HelloController { + + @Get("/") + public Single greet() { + return Single.just("Hello World!"); + } + +} diff --git a/micronaut-rxjava/src/main/java/hello/ServerApp.java b/micronaut-rxjava/src/main/java/hello/ServerApp.java new file mode 100644 index 0000000..54d2fe3 --- /dev/null +++ b/micronaut-rxjava/src/main/java/hello/ServerApp.java @@ -0,0 +1,10 @@ +package hello; + +import io.micronaut.runtime.Micronaut; + +public class ServerApp { + + public static void main(String[] args) { + Micronaut.run(ServerApp.class); + } +} \ No newline at end of file diff --git a/micronaut-rxjava/src/main/resources/application.yml b/micronaut-rxjava/src/main/resources/application.yml new file mode 100644 index 0000000..1522c40 --- /dev/null +++ b/micronaut-rxjava/src/main/resources/application.yml @@ -0,0 +1,6 @@ +micronaut: + application: + name: micronaut-rxjava + ssl: + enabled: true + buildSelfSigned: true diff --git a/micronaut-rxjava/src/main/resources/logback.xml b/micronaut-rxjava/src/main/resources/logback.xml new file mode 100644 index 0000000..8221870 --- /dev/null +++ b/micronaut-rxjava/src/main/resources/logback.xml @@ -0,0 +1,15 @@ + + + + false + + + %cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n + + + + + + + diff --git a/ninjaframework/pom.xml b/ninjaframework/pom.xml index 1431a86..13fff40 100644 --- a/ninjaframework/pom.xml +++ b/ninjaframework/pom.xml @@ -168,7 +168,7 @@ com.h2database h2 - 1.4.186 + 2.1.210 diff --git a/node-express/package.json b/node-express/package.json index 8f257a7..a669149 100644 --- a/node-express/package.json +++ b/node-express/package.json @@ -5,7 +5,7 @@ "dependencies": { "express": "4.14.0", "body-parser": "1.15.2", - "method-override": "2.3.6", + "method-override": "3.0.0", "errorhandler": "1.4.3", "async": "1.5.2" } diff --git a/node-loopback/package.json b/node-loopback/package.json index 5e282e9..3f48ae2 100644 --- a/node-loopback/package.json +++ b/node-loopback/package.json @@ -20,7 +20,7 @@ "strong-error-handler": "^2.0.0" }, "devDependencies": { - "eslint": "^3.17.1", + "eslint": "^6.6.0", "eslint-config-loopback": "^8.0.0", "nsp": "^2.1.0" }, diff --git a/pippo-jetty/pom.xml b/pippo-jetty/pom.xml index 4aa3452..6624e1c 100644 --- a/pippo-jetty/pom.xml +++ b/pippo-jetty/pom.xml @@ -9,7 +9,7 @@ 1.8 - 1.1.0 + 1.12.0 diff --git a/pippo-tomcat/pom.xml b/pippo-tomcat/pom.xml index 56a8d95..4355996 100644 --- a/pippo-tomcat/pom.xml +++ b/pippo-tomcat/pom.xml @@ -9,7 +9,7 @@ 1.8 - 1.1.0 + 1.12.0 diff --git a/pippo-undertow/pom.xml b/pippo-undertow/pom.xml index 981c1c2..52f96f5 100644 --- a/pippo-undertow/pom.xml +++ b/pippo-undertow/pom.xml @@ -9,7 +9,7 @@ 1.8 - 1.1.0 + 1.12.0 diff --git a/quarkus/.dockerignore b/quarkus/.dockerignore new file mode 100644 index 0000000..94810d0 --- /dev/null +++ b/quarkus/.dockerignore @@ -0,0 +1,5 @@ +* +!target/*-runner +!target/*-runner.jar +!target/lib/* +!target/quarkus-app/* \ No newline at end of file diff --git a/quarkus/.gitignore b/quarkus/.gitignore new file mode 100644 index 0000000..91a800a --- /dev/null +++ b/quarkus/.gitignore @@ -0,0 +1,45 @@ +#Maven +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +release.properties +.flattened-pom.xml + +# Eclipse +.project +.classpath +.settings/ +bin/ + +# IntelliJ +.idea +*.ipr +*.iml +*.iws + +# NetBeans +nb-configuration.xml + +# Visual Studio Code +.vscode +.factorypath + +# OSX +.DS_Store + +# Vim +*.swp +*.swo + +# patch +*.orig +*.rej + +# Local environment +.env + +# Plugin directory +/.quarkus/cli/plugins/ +# TLS Certificates +.certs/ diff --git a/quarkus/README.md b/quarkus/README.md new file mode 100644 index 0000000..65f9511 --- /dev/null +++ b/quarkus/README.md @@ -0,0 +1,66 @@ +# code-with-quarkus + +This project uses Quarkus, the Supersonic Subatomic Java Framework. + +If you want to learn more about Quarkus, please visit its website: . + +## Running the application in dev mode + +You can run your application in dev mode that enables live coding using: + +```shell script +./mvnw compile quarkus:dev +``` + +> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at . + +## Packaging and running the application + +The application can be packaged using: + +```shell script +./mvnw package +``` + +It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory. +Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory. + +The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`. + +If you want to build an _über-jar_, execute the following command: + +```shell script +./mvnw package -Dquarkus.package.jar.type=uber-jar +``` + +The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`. + +## Creating a native executable + +You can create a native executable using: + +```shell script +./mvnw package -Dnative +``` + +Or, if you don't have GraalVM installed, you can run the native executable build in a container using: + +```shell script +./mvnw package -Dnative -Dquarkus.native.container-build=true +``` + +You can then execute your native executable with: `./target/code-with-quarkus-1.0.0-SNAPSHOT-runner` + +If you want to learn more about building native executables, please consult . + +## Related Guides + +- RESTEasy Classic ([guide](https://quarkus.io/guides/resteasy)): REST endpoint framework implementing Jakarta REST and more + +## Provided Code + +### RESTEasy JAX-RS + +Easily start your RESTful Web Services + +[Related guide section...](https://quarkus.io/guides/getting-started#the-jax-rs-resources) diff --git a/quarkus/mvnw b/quarkus/mvnw new file mode 100644 index 0000000..5e9618c --- /dev/null +++ b/quarkus/mvnw @@ -0,0 +1,332 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.3.2 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ]; then + + if [ -f /usr/local/etc/mavenrc ]; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ]; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ]; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false +darwin=false +mingw=false +case "$(uname)" in +CYGWIN*) cygwin=true ;; +MINGW*) mingw=true ;; +Darwin*) + darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="$(/usr/libexec/java_home)" + export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home" + export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ]; then + if [ -r /etc/gentoo-release ]; then + JAVA_HOME=$(java-config --jre-home) + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin; then + [ -n "$JAVA_HOME" ] \ + && JAVA_HOME=$(cygpath --unix "$JAVA_HOME") + [ -n "$CLASSPATH" ] \ + && CLASSPATH=$(cygpath --path --unix "$CLASSPATH") +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw; then + [ -n "$JAVA_HOME" ] && [ -d "$JAVA_HOME" ] \ + && JAVA_HOME="$( + cd "$JAVA_HOME" || ( + echo "cannot cd into $JAVA_HOME." >&2 + exit 1 + ) + pwd + )" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="$(which javac)" + if [ -n "$javaExecutable" ] && ! [ "$(expr "$javaExecutable" : '\([^ ]*\)')" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=$(which readlink) + if [ ! "$(expr "$readLink" : '\([^ ]*\)')" = "no" ]; then + if $darwin; then + javaHome="$(dirname "$javaExecutable")" + javaExecutable="$(cd "$javaHome" && pwd -P)/javac" + else + javaExecutable="$(readlink -f "$javaExecutable")" + fi + javaHome="$(dirname "$javaExecutable")" + javaHome=$(expr "$javaHome" : '\(.*\)/bin') + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ]; then + if [ -n "$JAVA_HOME" ]; then + if [ -x "$JAVA_HOME/jre/sh/java" ]; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="$( + \unset -f command 2>/dev/null + \command -v java + )" + fi +fi + +if [ ! -x "$JAVACMD" ]; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ]; then + echo "Warning: JAVA_HOME environment variable is not set." >&2 +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ]; then + echo "Path not specified to find_maven_basedir" >&2 + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ]; do + if [ -d "$wdir"/.mvn ]; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=$( + cd "$wdir/.." || exit 1 + pwd + ) + fi + # end of workaround + done + printf '%s' "$( + cd "$basedir" || exit 1 + pwd + )" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + # Remove \r in case we run on Windows within Git Bash + # and check out the repository with auto CRLF management + # enabled. Otherwise, we may read lines that are delimited with + # \r\n and produce $'-Xarg\r' rather than -Xarg due to word + # splitting rules. + tr -s '\r\n' ' ' <"$1" + fi +} + +log() { + if [ "$MVNW_VERBOSE" = true ]; then + printf '%s\n' "$1" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname "$0")") +if [ -z "$BASE_DIR" ]; then + exit 1 +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +export MAVEN_PROJECTBASEDIR +log "$MAVEN_PROJECTBASEDIR" + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +wrapperJarPath="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" +if [ -r "$wrapperJarPath" ]; then + log "Found $wrapperJarPath" +else + log "Couldn't find $wrapperJarPath, downloading it ..." + + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar" + fi + while IFS="=" read -r key value; do + # Remove '\r' from value to allow usage on windows as IFS does not consider '\r' as a separator ( considers space, tab, new line ('\n'), and custom '=' ) + safeValue=$(echo "$value" | tr -d '\r') + case "$key" in wrapperUrl) + wrapperUrl="$safeValue" + break + ;; + esac + done <"$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" + log "Downloading from: $wrapperUrl" + + if $cygwin; then + wrapperJarPath=$(cygpath --path --windows "$wrapperJarPath") + fi + + if command -v wget >/dev/null; then + log "Found wget ... using wget" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--quiet" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl >/dev/null; then + log "Found curl ... using curl" + [ "$MVNW_VERBOSE" = true ] && QUIET="" || QUIET="--silent" + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L || rm -f "$wrapperJarPath" + fi + else + log "Falling back to using Java to download" + javaSource="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$MAVEN_PROJECTBASEDIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=$(cygpath --path --windows "$javaSource") + javaClass=$(cygpath --path --windows "$javaClass") + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + log " - Compiling MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + log " - Running MavenWrapperDownloader.java ..." + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$wrapperUrl" "$wrapperJarPath") || rm -f "$wrapperJarPath" + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +# If specified, validate the SHA-256 sum of the Maven wrapper jar file +wrapperSha256Sum="" +while IFS="=" read -r key value; do + case "$key" in wrapperSha256Sum) + wrapperSha256Sum=$value + break + ;; + esac +done <"$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.properties" +if [ -n "$wrapperSha256Sum" ]; then + wrapperSha256Result=false + if command -v sha256sum >/dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | sha256sum -c >/dev/null 2>&1; then + wrapperSha256Result=true + fi + elif command -v shasum >/dev/null; then + if echo "$wrapperSha256Sum $wrapperJarPath" | shasum -a 256 -c >/dev/null 2>&1; then + wrapperSha256Result=true + fi + else + echo "Checksum validation was requested but neither 'sha256sum' or 'shasum' are available." >&2 + echo "Please install either command, or disable validation by removing 'wrapperSha256Sum' from your maven-wrapper.properties." >&2 + exit 1 + fi + if [ $wrapperSha256Result = false ]; then + echo "Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised." >&2 + echo "Investigate or delete $wrapperJarPath to attempt a clean download." >&2 + echo "If you updated your Maven version, you need to update the specified wrapperSha256Sum property." >&2 + exit 1 + fi +fi + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] \ + && JAVA_HOME=$(cygpath --path --windows "$JAVA_HOME") + [ -n "$CLASSPATH" ] \ + && CLASSPATH=$(cygpath --path --windows "$CLASSPATH") + [ -n "$MAVEN_PROJECTBASEDIR" ] \ + && MAVEN_PROJECTBASEDIR=$(cygpath --path --windows "$MAVEN_PROJECTBASEDIR") +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $*" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +# shellcheck disable=SC2086 # safe args +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/quarkus/mvnw.cmd b/quarkus/mvnw.cmd new file mode 100644 index 0000000..4136715 --- /dev/null +++ b/quarkus/mvnw.cmd @@ -0,0 +1,206 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.3.2 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. >&2 +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. >&2 +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. >&2 +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. >&2 +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.3.2/maven-wrapper-3.3.2.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM If specified, validate the SHA-256 sum of the Maven wrapper jar file +SET WRAPPER_SHA_256_SUM="" +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperSha256Sum" SET WRAPPER_SHA_256_SUM=%%B +) +IF NOT %WRAPPER_SHA_256_SUM%=="" ( + powershell -Command "&{"^ + "Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash;"^ + "$hash = (Get-FileHash \"%WRAPPER_JAR%\" -Algorithm SHA256).Hash.ToLower();"^ + "If('%WRAPPER_SHA_256_SUM%' -ne $hash){"^ + " Write-Error 'Error: Failed to validate Maven wrapper SHA-256, your Maven wrapper might be compromised.';"^ + " Write-Error 'Investigate or delete %WRAPPER_JAR% to attempt a clean download.';"^ + " Write-Error 'If you updated your Maven version, you need to update the specified wrapperSha256Sum property.';"^ + " exit 1;"^ + "}"^ + "}" + if ERRORLEVEL 1 goto error +) + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/quarkus/pom.xml b/quarkus/pom.xml new file mode 100644 index 0000000..0e752d8 --- /dev/null +++ b/quarkus/pom.xml @@ -0,0 +1,124 @@ + + + 4.0.0 + org.acme + code-with-quarkus + 1.0.0-SNAPSHOT + + + 3.13.0 + 21 + UTF-8 + UTF-8 + quarkus-bom + io.quarkus.platform + 3.16.1 + true + 3.5.0 + + + + + + ${quarkus.platform.group-id} + ${quarkus.platform.artifact-id} + ${quarkus.platform.version} + pom + import + + + + + + + io.quarkus + quarkus-resteasy + + + io.quarkus + quarkus-arc + + + io.quarkus + quarkus-junit5 + test + + + io.rest-assured + rest-assured + test + + + + + + + ${quarkus.platform.group-id} + quarkus-maven-plugin + ${quarkus.platform.version} + true + + + + build + generate-code + generate-code-tests + native-image-agent + + + + + + maven-compiler-plugin + ${compiler-plugin.version} + + true + + + + maven-surefire-plugin + ${surefire-plugin.version} + + + org.jboss.logmanager.LogManager + ${maven.home} + + + + + maven-failsafe-plugin + ${surefire-plugin.version} + + + + integration-test + verify + + + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + native + + + native + + + + false + true + + + + diff --git a/quarkus/src/main/docker/Dockerfile.jvm b/quarkus/src/main/docker/Dockerfile.jvm new file mode 100644 index 0000000..3857821 --- /dev/null +++ b/quarkus/src/main/docker/Dockerfile.jvm @@ -0,0 +1,97 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/code-with-quarkus-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus-jvm +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +### +FROM registry.access.redhat.com/ubi8/openjdk-21:1.20 + +ENV LANGUAGE='en_US:en' + + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/ +COPY --chown=185 target/quarkus-app/*.jar /deployments/ +COPY --chown=185 target/quarkus-app/app/ /deployments/app/ +COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] + diff --git a/quarkus/src/main/docker/Dockerfile.legacy-jar b/quarkus/src/main/docker/Dockerfile.legacy-jar new file mode 100644 index 0000000..7eb464a --- /dev/null +++ b/quarkus/src/main/docker/Dockerfile.legacy-jar @@ -0,0 +1,93 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# ./mvnw package -Dquarkus.package.jar.type=legacy-jar +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/code-with-quarkus-legacy-jar . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus-legacy-jar +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005 being the default) like this : EXPOSE 8080 5005. +# Additionally you will have to set -e JAVA_DEBUG=true and -e JAVA_DEBUG_PORT=*:5005 +# when running the container +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus-legacy-jar +# +# This image uses the `run-java.sh` script to run the application. +# This scripts computes the command line to execute your Java application, and +# includes memory/GC tuning. +# You can configure the behavior using the following environment properties: +# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") +# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options +# in JAVA_OPTS (example: "-Dsome.property=foo") +# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is +# used to calculate a default maximal heap memory based on a containers restriction. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio +# of the container available memory as set here. The default is `50` which means 50% +# of the available memory is used as an upper boundary. You can skip this mechanism by +# setting this value to `0` in which case no `-Xmx` option is added. +# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This +# is used to calculate a default initial heap memory based on the maximum heap memory. +# If used in a container without any memory constraints for the container then this +# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio +# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` +# is used as the initial heap size. You can skip this mechanism by setting this value +# to `0` in which case no `-Xms` option is added (example: "25") +# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. +# This is used to calculate the maximum value of the initial heap memory. If used in +# a container without any memory constraints for the container then this option has +# no effect. If there is a memory constraint then `-Xms` is limited to the value set +# here. The default is 4096MB which means the calculated value of `-Xms` never will +# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") +# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output +# when things are happening. This option, if set to true, will set +# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). +# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: +# true"). +# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). +# - CONTAINER_CORE_LIMIT: A calculated core limit as described in +# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") +# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). +# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. +# (example: "20") +# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. +# (example: "40") +# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. +# (example: "4") +# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus +# previous GC times. (example: "90") +# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") +# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") +# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should +# contain the necessary JRE command-line options to specify the required GC, which +# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). +# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") +# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") +# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be +# accessed directly. (example: "foo.example.com,bar.example.com") +# +### +FROM registry.access.redhat.com/ubi8/openjdk-21:1.20 + +ENV LANGUAGE='en_US:en' + + +COPY target/lib/* /deployments/lib/ +COPY target/*-runner.jar /deployments/quarkus-run.jar + +EXPOSE 8080 +USER 185 +ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" +ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" + +ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ] diff --git a/quarkus/src/main/docker/Dockerfile.native b/quarkus/src/main/docker/Dockerfile.native new file mode 100644 index 0000000..60b0f9a --- /dev/null +++ b/quarkus/src/main/docker/Dockerfile.native @@ -0,0 +1,27 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t quarkus/code-with-quarkus . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/quarkus/src/main/docker/Dockerfile.native-micro b/quarkus/src/main/docker/Dockerfile.native-micro new file mode 100644 index 0000000..373286b --- /dev/null +++ b/quarkus/src/main/docker/Dockerfile.native-micro @@ -0,0 +1,30 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. +# It uses a micro base image, tuned for Quarkus native executables. +# It reduces the size of the resulting container image. +# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. +# +# Before building the container image run: +# +# ./mvnw package -Dnative +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/code-with-quarkus . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus +# +### +FROM quay.io/quarkus/quarkus-micro-image:2.0 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root target/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/quarkus/src/main/java/org/acme/GreetingResource.java b/quarkus/src/main/java/org/acme/GreetingResource.java new file mode 100644 index 0000000..00c9def --- /dev/null +++ b/quarkus/src/main/java/org/acme/GreetingResource.java @@ -0,0 +1,16 @@ +package org.acme; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.Produces; +import jakarta.ws.rs.core.MediaType; + +@Path("/") +public class GreetingResource { + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String hello() { + return "Hello World"; + } +} diff --git a/quarkus/src/main/resources/application.properties b/quarkus/src/main/resources/application.properties new file mode 100644 index 0000000..ee283bd --- /dev/null +++ b/quarkus/src/main/resources/application.properties @@ -0,0 +1,4 @@ +# Enable SSL +quarkus.http.ssl-port=443 +quarkus.http.ssl.certificate.key-store-file=keystore.jks +quarkus.http.ssl.certificate.key-store-password=password \ No newline at end of file diff --git a/quarkus/src/main/resources/keystore.jks b/quarkus/src/main/resources/keystore.jks new file mode 100644 index 0000000..feab9b6 Binary files /dev/null and b/quarkus/src/main/resources/keystore.jks differ diff --git a/ratpack/pom.xml b/ratpack/pom.xml index 602821b..b189433 100644 --- a/ratpack/pom.xml +++ b/ratpack/pom.xml @@ -15,7 +15,7 @@ io.ratpack ratpack-core - 1.4.4 + 1.9.0 diff --git a/seedstack-filter/pom.xml b/seedstack-filter/pom.xml index dfd5298..555ee2c 100644 --- a/seedstack-filter/pom.xml +++ b/seedstack-filter/pom.xml @@ -14,7 +14,7 @@ UTF-8 UTF-8 - 1.1.6 + 1.2.0 diff --git a/seedstack-jersey2/pom.xml b/seedstack-jersey2/pom.xml index 70eaf08..a41ab43 100644 --- a/seedstack-jersey2/pom.xml +++ b/seedstack-jersey2/pom.xml @@ -14,7 +14,7 @@ UTF-8 UTF-8 - 1.1.6 + 1.2.0 diff --git a/spark/pom.xml b/spark/pom.xml index 6c90ee4..cf1e7f3 100644 --- a/spark/pom.xml +++ b/spark/pom.xml @@ -15,7 +15,7 @@ com.sparkjava spark-core - 2.7.0 + 2.7.2 diff --git a/spring-boot-3-tomcat/.gitignore b/spring-boot-3-tomcat/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/spring-boot-3-tomcat/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/spring-boot-3-tomcat/build.gradle b/spring-boot-3-tomcat/build.gradle new file mode 100644 index 0000000..042ac8a --- /dev/null +++ b/spring-boot-3-tomcat/build.gradle @@ -0,0 +1,22 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.0.6' + id 'io.spring.dependency-management' version '1.1.0' +} + +group = 'com.example' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '17' + +repositories { + mavenCentral() +} + +dependencies { + implementation 'org.springframework.boot:spring-boot-starter-web' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/spring-boot-3-tomcat/gradle/wrapper/gradle-wrapper.jar b/spring-boot-3-tomcat/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/spring-boot-3-tomcat/gradle/wrapper/gradle-wrapper.jar differ diff --git a/spring-boot-3-tomcat/gradle/wrapper/gradle-wrapper.properties b/spring-boot-3-tomcat/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..774fae8 --- /dev/null +++ b/spring-boot-3-tomcat/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/spring-boot-3-tomcat/gradlew b/spring-boot-3-tomcat/gradlew new file mode 100755 index 0000000..a69d9cb --- /dev/null +++ b/spring-boot-3-tomcat/gradlew @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/spring-boot-3-tomcat/gradlew.bat b/spring-boot-3-tomcat/gradlew.bat new file mode 100644 index 0000000..53a6b23 --- /dev/null +++ b/spring-boot-3-tomcat/gradlew.bat @@ -0,0 +1,91 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/spring-boot-3-tomcat/settings.gradle b/spring-boot-3-tomcat/settings.gradle new file mode 100644 index 0000000..2c3fe58 --- /dev/null +++ b/spring-boot-3-tomcat/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'spring-boot-3-tomcat' diff --git a/spring-boot-3-tomcat/src/main/java/com/example/springboot3tomcat/SpringBoot3TomcatApplication.java b/spring-boot-3-tomcat/src/main/java/com/example/springboot3tomcat/SpringBoot3TomcatApplication.java new file mode 100644 index 0000000..3f362a4 --- /dev/null +++ b/spring-boot-3-tomcat/src/main/java/com/example/springboot3tomcat/SpringBoot3TomcatApplication.java @@ -0,0 +1,20 @@ +package com.example.springboot3tomcat; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +@RestController +public class SpringBoot3TomcatApplication { + + @RequestMapping("/") + String home() { + return "Hello World!"; + } + public static void main(String[] args) { + SpringApplication.run(SpringBoot3TomcatApplication.class, args); + } + +} diff --git a/spring-boot-3-tomcat/src/main/resources/application.properties b/spring-boot-3-tomcat/src/main/resources/application.properties new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/spring-boot-3-tomcat/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/spring-boot-3-tomcat/src/test/java/com/example/springboot3tomcat/SpringBoot3TomcatApplicationTests.java b/spring-boot-3-tomcat/src/test/java/com/example/springboot3tomcat/SpringBoot3TomcatApplicationTests.java new file mode 100644 index 0000000..7bc3167 --- /dev/null +++ b/spring-boot-3-tomcat/src/test/java/com/example/springboot3tomcat/SpringBoot3TomcatApplicationTests.java @@ -0,0 +1,13 @@ +package com.example.springboot3tomcat; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SpringBoot3TomcatApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/spring-boot-3-undertow/.gitignore b/spring-boot-3-undertow/.gitignore new file mode 100644 index 0000000..c2065bc --- /dev/null +++ b/spring-boot-3-undertow/.gitignore @@ -0,0 +1,37 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ diff --git a/spring-boot-3-undertow/build.gradle b/spring-boot-3-undertow/build.gradle new file mode 100644 index 0000000..53953d2 --- /dev/null +++ b/spring-boot-3-undertow/build.gradle @@ -0,0 +1,35 @@ +plugins { + id 'java' + id 'org.springframework.boot' version '3.0.6' + id 'io.spring.dependency-management' version '1.1.0' +} + +group = 'com.example' +version = '0.0.1-SNAPSHOT' +sourceCompatibility = '19' + +repositories { + mavenCentral() +} + +dependencies { + implementation('org.springframework.boot:spring-boot-starter-web') { + exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' + exclude group: 'org.hibernate.validator', module: 'hibernate-validator' + } + implementation 'org.springframework.boot:spring-boot-starter-undertow' + testImplementation 'org.springframework.boot:spring-boot-starter-test' +} + +tasks.withType(JavaCompile) { + options.compilerArgs += "--enable-preview" +} + +tasks.withType(JavaExec) { + jvmArgs("--enable-preview") +} + + +tasks.named('test') { + useJUnitPlatform() +} diff --git a/spring-boot-3-undertow/gradle/wrapper/gradle-wrapper.jar b/spring-boot-3-undertow/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/spring-boot-3-undertow/gradle/wrapper/gradle-wrapper.jar differ diff --git a/spring-boot-3-undertow/gradle/wrapper/gradle-wrapper.properties b/spring-boot-3-undertow/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..774fae8 --- /dev/null +++ b/spring-boot-3-undertow/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/spring-boot-3-undertow/gradlew b/spring-boot-3-undertow/gradlew new file mode 100755 index 0000000..a69d9cb --- /dev/null +++ b/spring-boot-3-undertow/gradlew @@ -0,0 +1,240 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/spring-boot-3-undertow/gradlew.bat b/spring-boot-3-undertow/gradlew.bat new file mode 100644 index 0000000..53a6b23 --- /dev/null +++ b/spring-boot-3-undertow/gradlew.bat @@ -0,0 +1,91 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/spring-boot-3-undertow/settings.gradle b/spring-boot-3-undertow/settings.gradle new file mode 100644 index 0000000..b29fe08 --- /dev/null +++ b/spring-boot-3-undertow/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'spring-boot-3-undertow' diff --git a/spring-boot-3-undertow/src/main/java/demo/SpringBoot3UndertowApplication.java b/spring-boot-3-undertow/src/main/java/demo/SpringBoot3UndertowApplication.java new file mode 100644 index 0000000..8b41472 --- /dev/null +++ b/spring-boot-3-undertow/src/main/java/demo/SpringBoot3UndertowApplication.java @@ -0,0 +1,20 @@ +package demo; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +@RestController +public class SpringBoot3UndertowApplication { + @RequestMapping("/") + String home() { + return "Hello World!"; + } + + public static void main(String[] args) { + SpringApplication.run(SpringBoot3UndertowApplication.class, args); + } + +} diff --git a/spring-boot-3-undertow/src/main/resources/application.properties b/spring-boot-3-undertow/src/main/resources/application.properties new file mode 100644 index 0000000..20647fa --- /dev/null +++ b/spring-boot-3-undertow/src/main/resources/application.properties @@ -0,0 +1 @@ +server.compression.enabled=false diff --git a/spring-boot-3-undertow/src/test/java/demo/SpringBoot3UndertowApplicationTests.java b/spring-boot-3-undertow/src/test/java/demo/SpringBoot3UndertowApplicationTests.java new file mode 100644 index 0000000..d763712 --- /dev/null +++ b/spring-boot-3-undertow/src/test/java/demo/SpringBoot3UndertowApplicationTests.java @@ -0,0 +1,13 @@ +package demo; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class SpringBoot3UndertowApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/spring-boot-tomcat/pom.xml b/spring-boot-tomcat/pom.xml index 3330e33..57cd6c9 100644 --- a/spring-boot-tomcat/pom.xml +++ b/spring-boot-tomcat/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.example - myproject - 0.0.1-SNAPSHOT + spring-boot-tomcat + 0.1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent - 1.4.1.RELEASE + 1.5.13.RELEASE diff --git a/spring-boot-undertow/pom.xml b/spring-boot-undertow/pom.xml index 942f3ac..ff49e34 100644 --- a/spring-boot-undertow/pom.xml +++ b/spring-boot-undertow/pom.xml @@ -4,13 +4,13 @@ 4.0.0 com.example - myproject - 0.0.1-SNAPSHOT + spring-boot-undertow + 0.1.0-SNAPSHOT org.springframework.boot spring-boot-starter-parent - 1.4.1.RELEASE + 1.5.13.RELEASE diff --git a/spring-boot2-tomcat/README.md b/spring-boot2-tomcat/README.md new file mode 100644 index 0000000..05dce7b --- /dev/null +++ b/spring-boot2-tomcat/README.md @@ -0,0 +1,4 @@ +``` +mvn clean install +mvn spring-boot:run +``` diff --git a/spring-boot2-tomcat/pom.xml b/spring-boot2-tomcat/pom.xml new file mode 100644 index 0000000..84e62c4 --- /dev/null +++ b/spring-boot2-tomcat/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + com.example + spring-boot2-tomcat + 0.1.0-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-parent + 2.0.2.RELEASE + + + + + + org.springframework.boot + spring-boot-starter-webflux + + + + + 1.8 + + diff --git a/spring-boot2-tomcat/src/main/java/Example.java b/spring-boot2-tomcat/src/main/java/Example.java new file mode 100644 index 0000000..20a4c60 --- /dev/null +++ b/spring-boot2-tomcat/src/main/java/Example.java @@ -0,0 +1,29 @@ +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.Bean; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.RequestPredicates; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; + +@RestController +@EnableAutoConfiguration +public class Example { + + @Bean + public RouterFunction route() { + return RouterFunctions + .route(RequestPredicates.GET("/").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), + serverRequest -> ServerResponse.ok() + .contentType(MediaType.TEXT_PLAIN) + .body(BodyInserters.fromObject("Hello World!"))); + } + + public static void main(String[] args) { + SpringApplication.run(Example.class, args); + } + +} \ No newline at end of file diff --git a/spring-boot2-undertow/README.md b/spring-boot2-undertow/README.md new file mode 100644 index 0000000..05dce7b --- /dev/null +++ b/spring-boot2-undertow/README.md @@ -0,0 +1,4 @@ +``` +mvn clean install +mvn spring-boot:run +``` diff --git a/spring-boot2-undertow/pom.xml b/spring-boot2-undertow/pom.xml new file mode 100644 index 0000000..38567d0 --- /dev/null +++ b/spring-boot2-undertow/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + com.example + spring-boot2-undertow + 0.0.1-SNAPSHOT + + + org.springframework.boot + spring-boot-starter-parent + 2.0.2.RELEASE + + + + + + org.springframework.boot + spring-boot-starter-webflux + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-undertow + + + + + 1.9 + + diff --git a/spring-boot2-undertow/src/main/java/Example.java b/spring-boot2-undertow/src/main/java/Example.java new file mode 100644 index 0000000..50da451 --- /dev/null +++ b/spring-boot2-undertow/src/main/java/Example.java @@ -0,0 +1,30 @@ +import org.springframework.boot.*; +import org.springframework.boot.autoconfigure.*; +import org.springframework.context.annotation.Bean; +import org.springframework.http.MediaType; +import org.springframework.stereotype.*; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.reactive.function.BodyInserters; +import org.springframework.web.reactive.function.server.RequestPredicates; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.RouterFunctions; +import org.springframework.web.reactive.function.server.ServerResponse; + +@RestController +@EnableAutoConfiguration +public class Example { + + @Bean + public RouterFunction route() { + return RouterFunctions + .route(RequestPredicates.GET("/").and(RequestPredicates.accept(MediaType.TEXT_PLAIN)), + serverRequest -> ServerResponse.ok() + .contentType(MediaType.TEXT_PLAIN) + .body(BodyInserters.fromObject("Hello World!"))); + } + + public static void main(String[] args) { + SpringApplication.run(Example.class, args); + } + +} \ No newline at end of file diff --git a/spring-boot2-webflux-netty/.gitignore b/spring-boot2-webflux-netty/.gitignore new file mode 100755 index 0000000..7079a3e --- /dev/null +++ b/spring-boot2-webflux-netty/.gitignore @@ -0,0 +1,21 @@ +target/ +bower_components/ +node_modules/ +dist/ +.idea/¬¬¬∑ +.tmp/ +.settings +.metadata/ +*.iml +*.log +*.tmp +*.zip +*.bak +dependency-reduced-pom.xml + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +.DS_Store + +.idea diff --git a/spring-boot2-webflux-netty/pom.xml b/spring-boot2-webflux-netty/pom.xml new file mode 100644 index 0000000..81f566e --- /dev/null +++ b/spring-boot2-webflux-netty/pom.xml @@ -0,0 +1,31 @@ + + 4.0.0 + com.networknt + spring-boot2-webflux-netty + 1.0-SNAPSHOT + + org.springframework.boot + spring-boot-starter-parent + 2.0.0.RELEASE + + + 1.8 + + + + org.springframework.boot + spring-boot-starter-webflux + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.0.3.RELEASE + + + + + \ No newline at end of file diff --git a/spring-boot2-webflux-netty/src/main/java/com/networknt/example/Example.java b/spring-boot2-webflux-netty/src/main/java/com/networknt/example/Example.java new file mode 100644 index 0000000..b276a46 --- /dev/null +++ b/spring-boot2-webflux-netty/src/main/java/com/networknt/example/Example.java @@ -0,0 +1,17 @@ +package com.networknt.example; + +import org.reactivestreams.Publisher; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import reactor.core.publisher.Mono; + +@Controller +public class Example { + + @GetMapping("/") + @ResponseBody + public Publisher handler() { + return Mono.just("Hello world!"); + } +} \ No newline at end of file diff --git a/spring-boot2-webflux-netty/src/main/java/com/networknt/example/ExampleApplication.java b/spring-boot2-webflux-netty/src/main/java/com/networknt/example/ExampleApplication.java new file mode 100644 index 0000000..016a2d9 --- /dev/null +++ b/spring-boot2-webflux-netty/src/main/java/com/networknt/example/ExampleApplication.java @@ -0,0 +1,14 @@ +package com.networknt.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.reactive.config.EnableWebFlux; + +@SpringBootApplication +@EnableWebFlux +public class ExampleApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(ExampleApplication.class); + } +} diff --git a/spring-boot2-webflux-undertow/.gitignore b/spring-boot2-webflux-undertow/.gitignore new file mode 100755 index 0000000..7079a3e --- /dev/null +++ b/spring-boot2-webflux-undertow/.gitignore @@ -0,0 +1,21 @@ +target/ +bower_components/ +node_modules/ +dist/ +.idea/¬¬¬∑ +.tmp/ +.settings +.metadata/ +*.iml +*.log +*.tmp +*.zip +*.bak +dependency-reduced-pom.xml + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +.DS_Store + +.idea diff --git a/spring-boot2-webflux-undertow/pom.xml b/spring-boot2-webflux-undertow/pom.xml new file mode 100644 index 0000000..3c6be3d --- /dev/null +++ b/spring-boot2-webflux-undertow/pom.xml @@ -0,0 +1,41 @@ + + 4.0.0 + com.networknt + spring-boot2-webflux-undertow + 1.0-SNAPSHOT + + org.springframework.boot + spring-boot-starter-parent + 2.0.0.RELEASE + + + 1.8 + + + + org.springframework.boot + spring-boot-starter-webflux + + + spring-boot-starter-reactor-netty + org.springframework.boot + + + + + org.springframework.boot + spring-boot-starter-undertow + + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.0.3.RELEASE + + + + + \ No newline at end of file diff --git a/spring-boot2-webflux-undertow/src/main/java/com/networknt/example/Example.java b/spring-boot2-webflux-undertow/src/main/java/com/networknt/example/Example.java new file mode 100644 index 0000000..b276a46 --- /dev/null +++ b/spring-boot2-webflux-undertow/src/main/java/com/networknt/example/Example.java @@ -0,0 +1,17 @@ +package com.networknt.example; + +import org.reactivestreams.Publisher; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import reactor.core.publisher.Mono; + +@Controller +public class Example { + + @GetMapping("/") + @ResponseBody + public Publisher handler() { + return Mono.just("Hello world!"); + } +} \ No newline at end of file diff --git a/spring-boot2-webflux-undertow/src/main/java/com/networknt/example/ExampleApplication.java b/spring-boot2-webflux-undertow/src/main/java/com/networknt/example/ExampleApplication.java new file mode 100644 index 0000000..016a2d9 --- /dev/null +++ b/spring-boot2-webflux-undertow/src/main/java/com/networknt/example/ExampleApplication.java @@ -0,0 +1,14 @@ +package com.networknt.example; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.reactive.config.EnableWebFlux; + +@SpringBootApplication +@EnableWebFlux +public class ExampleApplication { + + public static void main(String[] args) throws Exception { + SpringApplication.run(ExampleApplication.class); + } +} diff --git a/spring-vertx/README.md b/spring-vertx/README.md new file mode 100644 index 0000000..13a5e78 --- /dev/null +++ b/spring-vertx/README.md @@ -0,0 +1,15 @@ +# Spring Vertx Integration + +[Hello World!](https://www.baeldung.com/spring-vertx) + +## Build + +```shell script +mvn clean install +``` + +## Run + +```shell script +mvn spring-boot:run +``` \ No newline at end of file diff --git a/spring-vertx/pom.xml b/spring-vertx/pom.xml new file mode 100644 index 0000000..0af9509 --- /dev/null +++ b/spring-vertx/pom.xml @@ -0,0 +1,79 @@ + + + 4.0.0 + + org.example + spring-vertx + 1.0-SNAPSHOT + + 3.9.4 + 2.5.12 + 2.11.2 + + + + org.springframework.boot + spring-boot-starter-data-jpa + ${spring-boot.version} + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot.version} + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + io.vertx + vertx-web + ${vertx.version} + + + org.springframework.boot + spring-boot-starter-test + ${spring-boot.version} + test + + + com.fasterxml.jackson.core + jackson-core + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + + \ No newline at end of file diff --git a/spring-vertx/src/main/java/com/github/thinhda/VertxSpringApplication.java b/spring-vertx/src/main/java/com/github/thinhda/VertxSpringApplication.java new file mode 100644 index 0000000..37a9726 --- /dev/null +++ b/spring-vertx/src/main/java/com/github/thinhda/VertxSpringApplication.java @@ -0,0 +1,38 @@ +package com.github.thinhda; + +import com.github.thinhda.verticles.ServerVerticle; +import io.vertx.core.Vertx; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; +import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; +import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +import javax.annotation.PostConstruct; + +/** Created by thinhda. Date: 8/3/20 */ +@SpringBootApplication( + exclude = { + DataSourceAutoConfiguration.class, + DataSourceTransactionManagerAutoConfiguration.class, + HibernateJpaAutoConfiguration.class + }) +@Configuration +@ComponentScan(basePackages = {"com.github.thinhda"}) +public class VertxSpringApplication { + + @Autowired private ServerVerticle serverVerticle; + + public static void main(String[] args) { + SpringApplication.run(VertxSpringApplication.class, args); + } + + @PostConstruct + public void deployVerticle() { + final Vertx vertx = Vertx.vertx(); + vertx.deployVerticle(serverVerticle); + } +} diff --git a/spring-vertx/src/main/java/com/github/thinhda/config/ServiceConfig.java b/spring-vertx/src/main/java/com/github/thinhda/config/ServiceConfig.java new file mode 100644 index 0000000..4956091 --- /dev/null +++ b/spring-vertx/src/main/java/com/github/thinhda/config/ServiceConfig.java @@ -0,0 +1,31 @@ +package com.github.thinhda.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +import java.io.IOException; +import java.net.ServerSocket; + +/** Created by thinhda. Date: 8/4/20 */ +@Configuration +public class ServiceConfig { + private static final int DEFAULT_PORT = 8080; + + @Profile("default") + @Bean + public Integer defaultPort() { + return DEFAULT_PORT; + } + + @Profile("test") + @Bean + public Integer randomPort() { + try (ServerSocket socket = new ServerSocket(0)) { + return socket.getLocalPort(); + + } catch (IOException e) { + return DEFAULT_PORT; + } + } +} diff --git a/spring-vertx/src/main/java/com/github/thinhda/service/PingService.java b/spring-vertx/src/main/java/com/github/thinhda/service/PingService.java new file mode 100644 index 0000000..b58cb8d --- /dev/null +++ b/spring-vertx/src/main/java/com/github/thinhda/service/PingService.java @@ -0,0 +1,16 @@ +package com.github.thinhda.service; + +import io.vertx.core.Future; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** Created by thinhda. Date: 8/4/20 */ +@Service +public class PingService { + private static final String TEXT = "Hello World!"; + + @Autowired + public Future ping() { + return Future.succeededFuture(TEXT); + } +} diff --git a/spring-vertx/src/main/java/com/github/thinhda/verticles/ServerVerticle.java b/spring-vertx/src/main/java/com/github/thinhda/verticles/ServerVerticle.java new file mode 100644 index 0000000..c98ba72 --- /dev/null +++ b/spring-vertx/src/main/java/com/github/thinhda/verticles/ServerVerticle.java @@ -0,0 +1,44 @@ +package com.github.thinhda.verticles; + +import com.github.thinhda.service.PingService; +import io.vertx.core.AbstractVerticle; +import io.vertx.core.http.HttpHeaders; +import io.vertx.ext.web.Router; +import io.vertx.ext.web.RoutingContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** Created by thinhda. Date: 8/4/20 */ +@Component +public class ServerVerticle extends AbstractVerticle { + + @Autowired private Integer defaultPort; + @Autowired private PingService pingService; + private static final String TEXT = "Hello World!"; + + private void ping(RoutingContext routingContext) { + pingService + .ping() + .setHandler( + res -> { + routingContext + .response() + .putHeader("content-type", "application/json") + .setStatusCode(200) + .end(res.result()); + }); + } + + @Override + public void start() throws Exception { + super.start(); + + Router router = Router.router(vertx); + router.get("/").handler(this::ping); + + vertx + .createHttpServer() + .requestHandler(req -> req.response().end(TEXT)) + .listen(config().getInteger("http.port", defaultPort)); + } +} diff --git a/spring-vertx/src/main/resources/logback.xml b/spring-vertx/src/main/resources/logback.xml new file mode 100644 index 0000000..7d900d8 --- /dev/null +++ b/spring-vertx/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/undertow/.gitignore b/undertow/.gitignore new file mode 100644 index 0000000..b63da45 --- /dev/null +++ b/undertow/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/undertow/build.gradle b/undertow/build.gradle new file mode 100644 index 0000000..f130725 --- /dev/null +++ b/undertow/build.gradle @@ -0,0 +1,23 @@ +plugins { + id 'java' + id 'application' + id 'com.github.johnrengelman.shadow' version '8.1.1' +} + +group = 'org.example' +version = '1.0-SNAPSHOT' +sourceCompatibility = 11 + +repositories { + mavenCentral() +} + +application { + mainClass = 'Example' +} + +dependencies { + implementation 'io.undertow:undertow-core:2.3.5.Final' +// implementation 'io.undertow:undertow-servlet:2.3.5.Final' +// implementation 'io.undertow:undertow-websockets-jsr:2.3.5.Final' + } \ No newline at end of file diff --git a/undertow/gradle/wrapper/gradle-wrapper.jar b/undertow/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..249e583 Binary files /dev/null and b/undertow/gradle/wrapper/gradle-wrapper.jar differ diff --git a/undertow/gradle/wrapper/gradle-wrapper.properties b/undertow/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..80972d1 --- /dev/null +++ b/undertow/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Tue May 09 16:54:18 ICT 2023 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/undertow/gradlew b/undertow/gradlew new file mode 100755 index 0000000..1b6c787 --- /dev/null +++ b/undertow/gradlew @@ -0,0 +1,234 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +APP_NAME="Gradle" +APP_BASE_NAME=${0##*/} + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/undertow/gradlew.bat b/undertow/gradlew.bat new file mode 100644 index 0000000..ac1b06f --- /dev/null +++ b/undertow/gradlew.bat @@ -0,0 +1,89 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/undertow/run.sh b/undertow/run.sh new file mode 100644 index 0000000..069170a --- /dev/null +++ b/undertow/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +./gradlew shadowJar && java -jar build/libs/undertow-1.0-SNAPSHOT-all.jar \ No newline at end of file diff --git a/undertow/settings.gradle b/undertow/settings.gradle new file mode 100644 index 0000000..94dbe87 --- /dev/null +++ b/undertow/settings.gradle @@ -0,0 +1,2 @@ +rootProject.name = 'undertow' + diff --git a/undertow/src/main/java/Example.java b/undertow/src/main/java/Example.java new file mode 100644 index 0000000..b3f58df --- /dev/null +++ b/undertow/src/main/java/Example.java @@ -0,0 +1,14 @@ +import io.undertow.Undertow; +import io.undertow.util.Headers; + +public class Example { + public static void main(String[] args) { + Undertow server = Undertow.builder() + .addHttpListener(8080, "localhost") + .setHandler(exchange -> { + exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain"); + exchange.getResponseSender().send("Hello World"); + }).build(); + server.start(); + } +} diff --git a/vertx/pom.xml b/vertx/pom.xml index cc929e3..4c51cef 100644 --- a/vertx/pom.xml +++ b/vertx/pom.xml @@ -17,7 +17,7 @@ io.vertx vertx-core - 3.5.0 + 3.5.4 diff --git a/vertx/src/main/java/hello/Server.java b/vertx/src/main/java/hello/Server.java index 5429ee3..4bf41d3 100644 --- a/vertx/src/main/java/hello/Server.java +++ b/vertx/src/main/java/hello/Server.java @@ -3,14 +3,16 @@ import io.vertx.core.AbstractVerticle; import io.vertx.core.DeploymentOptions; import io.vertx.core.Vertx; +import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpHeaders; -import java.util.Date; - public class Server extends AbstractVerticle { - private static final int INSTANCES = 4; - private static final String TEXT = "Hello World!"; + private static final int INSTANCES = Runtime.getRuntime().availableProcessors() * 2; + private static final Buffer TEXT = Buffer.buffer("Hello World!"); + + private static final String TEXT_PLAIN = "text/plain"; + private static final String VERTX = "Vertx"; // Convenience method so you can run it in your IDE public static void main(String[] args) { @@ -22,8 +24,8 @@ public static void main(String[] args) { public void start() throws Exception { vertx.createHttpServer().requestHandler(req -> { req.response() - .putHeader(HttpHeaders.SERVER, "Vertx") - .putHeader(HttpHeaders.CONTENT_TYPE, "text/plain") + .putHeader(HttpHeaders.SERVER, VERTX) + .putHeader(HttpHeaders.CONTENT_TYPE, TEXT_PLAIN) .end(TEXT); }).listen(8080); }