Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Helidon to use YAML config #6

Merged
merged 5 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
helidon/target/
/helidon/.helidon
6 changes: 0 additions & 6 deletions helidon/.helidon

This file was deleted.

4 changes: 4 additions & 0 deletions helidon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
<groupId>io.helidon.security.providers</groupId>
<artifactId>helidon-security-providers-jwt</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.config</groupId>
<artifactId>helidon-config-yaml</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.http.media</groupId>
<artifactId>helidon-http-media-jsonp</artifactId>
Expand Down
62 changes: 21 additions & 41 deletions helidon/src/main/java/com/okta/rest/HelloApplication.java
Original file line number Diff line number Diff line change
@@ -1,55 +1,35 @@
package com.okta.rest;

import java.net.URI;

import com.okta.rest.controller.HelloResource;

import io.helidon.common.configurable.Resource;
import io.helidon.config.Config;
import io.helidon.security.Security;
import io.helidon.security.providers.jwt.JwtProvider;
import io.helidon.config.ConfigSources;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.context.ContextFeature;
import io.helidon.webserver.http.HttpRouting;
import io.helidon.webserver.security.SecurityFeature;
import io.helidon.webserver.WebServerConfig;
import io.helidon.webserver.security.SecurityHttpFeature;

import java.util.concurrent.TimeUnit;

public class HelloApplication {

public static void main(String[] args) {
WebServerConfig.Builder builder = WebServer.builder();
setup(builder);
WebServer server = builder.port(8080).build();

var config = Config.global();
var oauth =
JwtProvider.builder()
.issuer(config.get("se.jwt.verify.issuer").asString().get())
.verifyJwk(
Resource.create(
config
.get("se.jwt.verify.publickey.location")
.asString()
.map(URI::create)
.orElseThrow()))
.build();

Security security = Security.builder().addProvider(oauth).build();
var securityFeature =
SecurityFeature.create(
sfb ->
sfb.security(security)
.addPath(p -> p.path("/hello").handler(h -> h.authenticate(true))));

WebServer.builder()
.config(config.get("server"))
.routing(HelloApplication::routing)
.addFeature(ContextFeature.create())
.addFeature(securityFeature)
.build()
.start();
long t = System.nanoTime();
server.start();
long time = System.nanoTime() - t;

System.out.printf("""
Started server at http://localhost:%1$d
""", server.port(), TimeUnit.MILLISECONDS.convert(time, TimeUnit.NANOSECONDS));
}

/**
* Updates HTTP Routing.
*/
static void routing(HttpRouting.Builder routing) {
routing.addFeature(new HelloResource());
static void setup(WebServerConfig.Builder server) {
Config config = Config.create(ConfigSources.classpath("application.yml"));

server.routing(routing -> routing
.addFeature(SecurityHttpFeature.create(config.get("security.web-server")))
.addFeature(new HelloResource()));
}
}
10 changes: 4 additions & 6 deletions helidon/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Microprofile server properties
server.port=8080
server.host=0.0.0.0

se.jwt.verify.issuer=https://dev-06bzs1cu.us.auth0.com/
se.jwt.verify.publickey.location=${se.jwt.verify.issuer}.well-known/jwks.json
#security.providers.0.jwt.atn-token.jwk.resource.uri=https://dev-06bzs1cu.us.auth0.com/.well-known/jwks.json
#security.web-server.defaults.authenticate=true
#security.web-server.paths.0.path=/hello
#security.web-server.paths.0.methods=["get"]
11 changes: 11 additions & 0 deletions helidon/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
security:
providers:
- jwt:
atn-token:
jwk.resource.uri: https://dev-06bzs1cu.us.auth0.com/.well-known/jwks.json
web-server:
defaults:
authenticate: true
paths:
- path: "/hello"
methods: ["get"]
25 changes: 25 additions & 0 deletions tests/ab.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -c is concurrent clients
# -n is the number of requests to run in the test
# -k is keep alive i.e., perform multiple requests within one HTTP session
# ulimit -n 10000
ab -H Authorization:"Bearer $TOKEN" -c 5000 -k -n 10000 $URL/hello

# Gitpod: 4 cores, 8 GB RAM

# http $URL/hello Authorization:"Bearer $TOKEN"

# ==========================================
# Imperative Results
# ==========================================
# Micronaut: 2 failed, 106.22 requests per second, 9.414 [ms] time per request
# Quarkus: 2 failed, 104.09 rps, 9.607 tpr
# Spring Boot: 0 failed, 101.21 rps, 9.880 tpr
# Helidon: Total of 7725 requests completed

# ==========================================
# Reactive Results
# ==========================================
# Micronaut: Total of 2145 requests completed
# Quarkus: Total of 6015 requests completed
# Spring Boot: Total of 9173 requests completed
# Helidon: 0 failed, 106.07 rps, 9.427 [ms] time per request
35 changes: 35 additions & 0 deletions tests/gatling/HelloSimulation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.okta.developer;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.*;

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

public class HelloSimulation extends Simulation {

String TOKEN = System.getenv().get("TOKEN");
String URL = System.getenv().get("URL");

HttpProtocolBuilder httpProtocol =
http.baseUrl(URL)
.authorizationHeader("Bearer " + TOKEN)
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.acceptLanguageHeader("en-US,en;q=0.5")
.acceptEncodingHeader("gzip, deflate")
.userAgentHeader(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/119.0"
);

ScenarioBuilder scn = scenario("Test URL scenario").exec(
http("Hello").get("/hello")
);

{
setUp(
scn.injectOpen(rampUsersPerSec(10).to(200).during(120))
).assertions(
global().successfulRequests().percent().gt(90.0)
).protocols(httpProtocol);
}
}