diff --git a/build.gradle b/build.gradle index 5ec2f950..f05eb9fa 100644 --- a/build.gradle +++ b/build.gradle @@ -83,6 +83,11 @@ ext { javaFxUtilsVersion = '1.0.8-SNAPSHOT' + /* REST APIs */ + + quarkusVersion="1.8.1.Final" + + /* Test */ junitVersion = '4.12' diff --git a/gradle.properties b/gradle.properties index db748cc8..63d65d4f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,9 @@ kotlin.code.style=official # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. -org.gradle.jvmargs=-Xmx3072m \ No newline at end of file +org.gradle.jvmargs=-Xmx3072m + + +quarkusVersion=1.8.1.Final + +#kotlin.js.compiler=ir \ No newline at end of file diff --git a/rest/BankFinderRest/.dockerignore b/rest/BankFinderRest/.dockerignore new file mode 100644 index 00000000..4361d2fb --- /dev/null +++ b/rest/BankFinderRest/.dockerignore @@ -0,0 +1,5 @@ +* +!build/*-runner +!build/*-runner.jar +!build/lib/* +!build/quarkus-app/* \ No newline at end of file diff --git a/rest/BankFinderRest/build.gradle b/rest/BankFinderRest/build.gradle new file mode 100644 index 00000000..da5a0caa --- /dev/null +++ b/rest/BankFinderRest/build.gradle @@ -0,0 +1,66 @@ +plugins { + id 'org.jetbrains.kotlin.jvm' + id "org.jetbrains.kotlin.plugin.allopen" version "1.3.72" + id 'io.quarkus' +} + +apply plugin: 'java-library' +apply plugin: 'kotlin' + + + +dependencies { + implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' + + // TODO: why can't Gradle find BankFinder project? .jars have temporarily to be copied to libs folder - which are not committed to repo of course - till this issue is fixed +// implementation project(path: ":common", configuration: 'jvmDefault') +// implementation project(path: ":BankFinder", configuration: 'jvmDefault') +// implementation "net.dankito.banking:BankFinder-jvm:$version" + + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation "net.dankito.utils:java-utils:$javaUtilsVersion" + + implementation enforcedPlatform("io.quarkus:quarkus-universe-bom:$quarkusVersion") + implementation 'io.quarkus:quarkus-kotlin' + implementation 'io.quarkus:quarkus-resteasy' + implementation 'io.quarkus:quarkus-resteasy-jackson' + + testImplementation 'io.quarkus:quarkus-junit5' + testImplementation 'io.rest-assured:kotlin-extensions' +} + + +quarkus { + setOutputDirectory("$projectDir/build/classes/kotlin/main") +} + +quarkusDev { + setSourceDir("$projectDir/src/main/kotlin") +} + +allOpen { + annotation("javax.ws.rs.Path") + annotation("javax.enterprise.context.ApplicationScoped") + annotation("io.quarkus.test.junit.QuarkusTest") +} + + +def javaVersion = JavaVersion.VERSION_11 + +java { + sourceCompatibility = javaVersion + targetCompatibility = javaVersion +} + +compileKotlin { + kotlinOptions.jvmTarget = javaVersion + kotlinOptions.javaParameters = true +} + +compileTestKotlin { + kotlinOptions.jvmTarget = javaVersion +} +test { + systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager" +} \ No newline at end of file diff --git a/rest/BankFinderRest/src/main/docker/Dockerfile.fast-jar b/rest/BankFinderRest/src/main/docker/Dockerfile.fast-jar new file mode 100644 index 00000000..2793e081 --- /dev/null +++ b/rest/BankFinderRest/src/main/docker/Dockerfile.fast-jar @@ -0,0 +1,57 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# mvn package -Dquarkus.package.type=fast-jar +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.fast-jar -t codinux/bank-finder-fast-jar . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 codinux/bank-finder-fast-jar +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5050 +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" codinux/bank-finder-fast-jar +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.1 + +ARG JAVA_PACKAGE=java-11-openjdk-headless +ARG RUN_JAVA_VERSION=1.3.8 + +ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' + +# Install java and the run-java script +# Also set up permissions for user `1001` +RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ + && microdnf update \ + && microdnf clean all \ + && mkdir /deployments \ + && chown 1001 /deployments \ + && chmod "g+rwX" /deployments \ + && chown 1001:root /deployments \ + && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ + && chown 1001 /deployments/run-java.sh \ + && chmod 540 /deployments/run-java.sh \ + && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security + +# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" + +# We make four distinct layers so if there are application changes the library layers can be re-used +COPY --chown=1001 build/quarkus-app/lib/ /deployments/lib/ +COPY --chown=1001 build/quarkus-app/*.jar /deployments/ +COPY --chown=1001 build/quarkus-app/app/ /deployments/app/ +COPY --chown=1001 build/quarkus-app/quarkus/ /deployments/quarkus/ + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT [ "/deployments/run-java.sh" ] \ No newline at end of file diff --git a/rest/BankFinderRest/src/main/docker/Dockerfile.jvm b/rest/BankFinderRest/src/main/docker/Dockerfile.jvm new file mode 100644 index 00000000..771a9ae2 --- /dev/null +++ b/rest/BankFinderRest/src/main/docker/Dockerfile.jvm @@ -0,0 +1,54 @@ +#### +# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode +# +# Before building the container image run: +# +# mvn package +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.jvm -t codinux/bank-finder-jvm . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 codinux/bank-finder-jvm +# +# If you want to include the debug port into your docker image +# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5050 +# +# Then run the container using : +# +# docker run -i --rm -p 8080:8080 -p 5005:5005 -e JAVA_ENABLE_DEBUG="true" codinux/bank-finder-jvm +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.1 + +ARG JAVA_PACKAGE=java-11-openjdk-headless +ARG RUN_JAVA_VERSION=1.3.8 + +ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' + +# Install java and the run-java script +# Also set up permissions for user `1001` +RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ + && microdnf update \ + && microdnf clean all \ + && mkdir /deployments \ + && chown 1001 /deployments \ + && chmod "g+rwX" /deployments \ + && chown 1001:root /deployments \ + && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ + && chown 1001 /deployments/run-java.sh \ + && chmod 540 /deployments/run-java.sh \ + && echo "securerandom.source=file:/dev/urandom" >> /etc/alternatives/jre/lib/security/java.security + +# Configure the JAVA_OPTIONS, you can add -XshowSettings:vm to also display the heap size. +ENV JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" + +COPY build/lib/* /deployments/lib/ +COPY build/*-runner.jar /deployments/app.jar + +EXPOSE 8080 +USER 1001 + +ENTRYPOINT [ "/deployments/run-java.sh" ] \ No newline at end of file diff --git a/rest/BankFinderRest/src/main/docker/Dockerfile.native b/rest/BankFinderRest/src/main/docker/Dockerfile.native new file mode 100644 index 00000000..39ba04c6 --- /dev/null +++ b/rest/BankFinderRest/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: +# +# mvn package -Pnative -Dquarkus.native.container-build=true +# +# Then, build the image with: +# +# docker build -f src/main/docker/Dockerfile.native -t codinux/bank-finder . +# +# Then run the container using: +# +# docker run -i --rm -p 8080:8080 codinux/bank-finder +# +### +FROM registry.access.redhat.com/ubi8/ubi-minimal:8.1 +WORKDIR /work/ +RUN chown 1001 /work \ + && chmod "g+rwX" /work \ + && chown 1001:root /work +COPY --chown=1001:root build/*-runner /work/application + +EXPOSE 8080 +USER 1001 + +CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] \ No newline at end of file diff --git a/rest/BankFinderRest/src/main/kotlin/net/dankito/banking/bankfinder/rest/BankFinderResource.kt b/rest/BankFinderRest/src/main/kotlin/net/dankito/banking/bankfinder/rest/BankFinderResource.kt new file mode 100644 index 00000000..36df7493 --- /dev/null +++ b/rest/BankFinderRest/src/main/kotlin/net/dankito/banking/bankfinder/rest/BankFinderResource.kt @@ -0,0 +1,25 @@ +package net.dankito.banking.bankfinder.rest + +import net.dankito.banking.bankfinder.BankInfo +import net.dankito.banking.bankfinder.InMemoryBankFinder +import org.jboss.resteasy.annotations.jaxrs.PathParam +import javax.ws.rs.GET +import javax.ws.rs.Path +import javax.ws.rs.Produces +import javax.ws.rs.core.MediaType + + +@Path("/bankfinder") +class BankFinderResource { + + protected var bankFinder = InMemoryBankFinder() + + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("{query}") + fun findBank(@PathParam query: String): List { + return bankFinder.findBankByNameBankCodeOrCity(query) + } + +} \ No newline at end of file diff --git a/rest/BankFinderRest/src/main/resources/application.properties b/rest/BankFinderRest/src/main/resources/application.properties new file mode 100644 index 00000000..4c6d1e55 --- /dev/null +++ b/rest/BankFinderRest/src/main/resources/application.properties @@ -0,0 +1 @@ +quarkus.http.port=5666 \ No newline at end of file diff --git a/rest/BankFinderRest/src/native-test/kotlin/net/dankito/banking/bankfinder/rest/NativeBankFinderResourceIT.kt b/rest/BankFinderRest/src/native-test/kotlin/net/dankito/banking/bankfinder/rest/NativeBankFinderResourceIT.kt new file mode 100644 index 00000000..c3437278 --- /dev/null +++ b/rest/BankFinderRest/src/native-test/kotlin/net/dankito/banking/bankfinder/rest/NativeBankFinderResourceIT.kt @@ -0,0 +1,6 @@ +package net.dankito.banking.bankfinder.rest + +import io.quarkus.test.junit.NativeImageTest + +@NativeImageTest +class NativeBankFinderResourceIT : ExampleResourceTest() \ No newline at end of file diff --git a/rest/BankFinderRest/src/test/kotlin/net/dankito/banking/bankfinder/rest/BankFinderResourceTest.kt b/rest/BankFinderRest/src/test/kotlin/net/dankito/banking/bankfinder/rest/BankFinderResourceTest.kt new file mode 100644 index 00000000..4bb0ce8a --- /dev/null +++ b/rest/BankFinderRest/src/test/kotlin/net/dankito/banking/bankfinder/rest/BankFinderResourceTest.kt @@ -0,0 +1,22 @@ +package net.dankito.banking.bankfinder.rest + +import io.quarkus.test.junit.QuarkusTest +import io.restassured.RestAssured.given +import org.hamcrest.CoreMatchers.containsString +import org.junit.jupiter.api.Test + + +@QuarkusTest +class BankFinderResourceTest { + + @Test + fun testSparkasse() { + given() + .`when`().get("/bankfinder/Sparkasse") + .then() + .statusCode(200) + .body(containsString("Berliner Sparkasse")) + .body(containsString("\"bankCode\":\"10050000\"")) + } + +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index c88874f0..936a3db3 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,14 @@ +pluginManagement { + repositories { + mavenLocal() + mavenCentral() + gradlePluginPortal() + } + plugins { + id 'io.quarkus' version "$quarkusVersion" + } +} + rootProject.name = 'fints4kProject' enableFeaturePreview('GRADLE_METADATA') @@ -45,6 +56,13 @@ project(':LuceneBankingPersistence').projectDir = "$rootDir/persistence/LuceneBa project(':RoomBankingPersistence').projectDir = "$rootDir/persistence/database/RoomBankingPersistence/" as File +/* REST APIs */ + +include ':BankFinderRest' + +project(':BankFinderRest').projectDir = "$rootDir/rest/BankFinderRest/" as File + + /* Tools */