-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#30 - Add example-jdk-jsonb with graalvm native image build
- Loading branch information
Showing
10 changed files
with
270 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.avaje</groupId> | ||
<artifactId>java11-oss</artifactId> | ||
<version>3.3</version> | ||
<relativePath/> | ||
</parent> | ||
|
||
<groupId>org.example</groupId> | ||
<artifactId>example-jdk-jsonb</artifactId> | ||
<version>1</version> | ||
|
||
<properties> | ||
<!-- <maven.compiler.source>18</maven.compiler.source>--> | ||
<!-- <maven.compiler.target>18</maven.compiler.target>--> | ||
<!-- <javadoc.source>11</javadoc.source>--> | ||
<java.release>17</java.release> | ||
<native.maven.plugin.version>0.9.8</native.maven.plugin.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-jex-jdk</artifactId> | ||
<version>2.1-SNAPSHOT</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-jsonb</artifactId> | ||
<version>0.9</version> | ||
</dependency> | ||
|
||
<!-- <dependency>--> | ||
<!-- <groupId>io.avaje</groupId>--> | ||
<!-- <artifactId>avaje-jsonb-generator</artifactId>--> | ||
<!-- <version>0.9</version>--> | ||
<!-- <scope>provided</scope>--> | ||
<!-- </dependency>--> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>1.7.30</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-simple</artifactId> | ||
<version>1.7.30</version> | ||
</dependency> | ||
|
||
<!-- <dependency>--> | ||
<!-- <groupId>ch.qos.logback</groupId>--> | ||
<!-- <artifactId>logback-classic</artifactId>--> | ||
<!-- <version>1.2.3</version>--> | ||
<!-- </dependency>--> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.1</version> | ||
<configuration> | ||
<release>17</release> | ||
<!-- <compilerArgs>--> | ||
<!-- --enable-preview--> | ||
<!-- </compilerArgs>--> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.avaje</groupId> | ||
<artifactId>avaje-jsonb-generator</artifactId> | ||
<version>0.9</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
<!-- <plugin>--> | ||
<!-- <groupId>io.repaint.maven</groupId>--> | ||
<!-- <artifactId>tiles-maven-plugin</artifactId>--> | ||
<!-- <version>2.22</version>--> | ||
<!-- <extensions>true</extensions>--> | ||
<!-- <configuration>--> | ||
<!-- <tiles>--> | ||
<!-- <tile>org.avaje.tile:lib-classpath:1.1</tile>--> | ||
<!-- </tiles>--> | ||
<!-- </configuration>--> | ||
<!-- </plugin>--> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>native</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.graalvm.buildtools</groupId> | ||
<artifactId>native-maven-plugin</artifactId> | ||
<version>${native.maven.plugin.version}</version> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<id>build-native</id> | ||
<goals> | ||
<goal>build</goal> | ||
</goals> | ||
<phase>package</phase> | ||
</execution> | ||
<execution> | ||
<id>test-native</id> | ||
<goals> | ||
<goal>test</goal> | ||
</goals> | ||
<phase>test</phase> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<imageName>mytest</imageName> | ||
<mainClass>org.example.Main</mainClass> | ||
<buildArgs> | ||
<buildArg>--no-fallback</buildArg> | ||
<buildArg>--allow-incomplete-classpath</buildArg> | ||
</buildArgs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module example.jdkTwo { | ||
|
||
requires io.avaje.jex.jdk; | ||
requires org.slf4j; | ||
requires io.avaje.jsonb; | ||
|
||
//requires static io.avaje.jsonb.generator; | ||
|
||
provides io.avaje.jsonb.Jsonb.Component with org.example.jsonb.GeneratedJsonComponent; | ||
//exports org.example to com.fasterxml.jackson.databind; | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/example-jdk-jsonb/src/main/java/org/example/HelloDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.example; | ||
|
||
import io.avaje.jsonb.Json; | ||
|
||
@Json | ||
public class HelloDto { | ||
|
||
public long id; | ||
public String name; | ||
} |
66 changes: 66 additions & 0 deletions
66
examples/example-jdk-jsonb/src/main/java/org/example/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package org.example; | ||
|
||
import io.avaje.jex.Context; | ||
import io.avaje.jex.Jex; | ||
import io.avaje.jex.core.JsonbJsonService; | ||
import io.avaje.jsonb.Jsonb; | ||
//import org.example.jsonb.GeneratedJsonComponent; | ||
//import org.example.jsonb.GeneratedJsonComponent; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
//import java.util.concurrent.Executor; | ||
//import java.util.concurrent.Executors; | ||
|
||
public class Main { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(Main.class); | ||
|
||
public static void main(String[] args) { | ||
|
||
Jsonb jsonb = Jsonb.newBuilder().build();//.add(new GeneratedJsonComponent()).build(); | ||
|
||
Jex.create() | ||
.configure(config -> config.jsonService(new JsonbJsonService(jsonb))) | ||
//.attribute(Executor.class, Executors.newVirtualThreadPerTaskExecutor()) | ||
.routing(routing -> routing | ||
.get("/", ctx -> ctx.text("hello world")) | ||
.get("/foo/{id}", Main::fooBean) | ||
.get("/delay", Main::delay) | ||
.get("/dump", ctx -> { | ||
dumpThreadCount(); | ||
ctx.text("done"); | ||
}) | ||
) | ||
.port(7003) | ||
.start(); | ||
} | ||
|
||
private static void fooBean(Context ctx) { | ||
HelloDto bean = new HelloDto(); | ||
bean.id = Integer.parseInt(ctx.pathParam("id")); | ||
bean.name = "Rob"; | ||
ctx.json(bean); | ||
} | ||
|
||
private static void delay(Context ctx) { | ||
log.info("delay start"); | ||
try { | ||
Thread.sleep(5_000); | ||
} catch (InterruptedException e) { | ||
Thread.currentThread().interrupt(); | ||
e.printStackTrace(); | ||
} | ||
ctx.text("delay done"); | ||
log.info("delay done"); | ||
} | ||
|
||
private static void dumpThreadCount() { | ||
Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces(); | ||
System.out.println("Thread count: " + allStackTraces.size()); | ||
Set<Thread> threads = allStackTraces.keySet(); | ||
System.out.println("Threads: " + threads); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
examples/example-jdk-jsonb/src/main/resources/content/basic.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<html><body>basic</body><html> |
1 change: 1 addition & 0 deletions
1
examples/example-jdk-jsonb/src/main/resources/content/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<html>index</html> |
1 change: 1 addition & 0 deletions
1
examples/example-jdk-jsonb/src/main/resources/content/plain-file.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
plain-file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<configuration scan="true" scanPeriod="10 seconds"> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | ||
<level>TRACE</level> | ||
</filter> | ||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
<logger name="io.avaje.jex" level="TRACE"/> | ||
<logger name="io.avaje.http.client" level="TRACE"/> | ||
<logger name="org.eclipse.jetty" level="WARN"/> | ||
|
||
</configuration> |
19 changes: 19 additions & 0 deletions
19
examples/example-jdk-jsonb/src/test/resources/logback-test.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<configuration scan="true" scanPeriod="10 seconds"> | ||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> | ||
<level>TRACE</level> | ||
</filter> | ||
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> | ||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<root level="INFO"> | ||
<appender-ref ref="STDOUT"/> | ||
</root> | ||
|
||
<logger name="io.avaje.jex" level="TRACE"/> | ||
<logger name="io.avaje.http.client" level="TRACE"/> | ||
<logger name="org.eclipse.jetty" level="WARN"/> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters