diff --git a/.env.example b/.env.example index 2785890..3c9a23a 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ +ROUTE_SERVICE_ENDPOINT="http://0.0.0.0:8888" DATABASE_URL="jdbc:postgresql://host:port/postgres?user=postgres&password=password" diff --git a/InAndOut-API-Modelling b/InAndOut-API-Modelling index 7a1ab8a..5a3381c 160000 --- a/InAndOut-API-Modelling +++ b/InAndOut-API-Modelling @@ -1 +1 @@ -Subproject commit 7a1ab8ae54bd88a272f2dfc3b1638a62c0004e78 +Subproject commit 5a3381c5918825f9b3ad7d757222f04c7842b648 diff --git a/build.gradle.kts b/build.gradle.kts index d8f4d13..39a455a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,96 +1,67 @@ -plugins { - java - application - id("org.springframework.boot") version "4.0.3" - id("io.spring.dependency-management") version "1.1.7" - id("org.graalvm.buildtools.native") version "0.11.4" -} +group = "com.shopping.inandout" +version = "0.0.1" +description = "A RESTful web service for handling customer queries and computing TSP solutions" -java { - toolchain { - languageVersion = JavaLanguageVersion.of(25) - } +allprojects { + repositories { + mavenLocal() + mavenCentral() + } } -application { - mainClass = "com.shopping.inandout.routeservice.RouteServiceApplication" +plugins { + `java-library` + application + id("software.amazon.smithy.gradle.smithy-base") } -configurations { - compileOnly { - extendsFrom(configurations.annotationProcessor.get()) - } +application { + mainClass = "com.shopping.inandout.routeservice.RouteServer" } -group = "com.shopping.inandout" -version = "0.0.1-SNAPSHOT" -description = "A RESTful web service for handling customer queries and computing TSP solutions" - repositories { mavenCentral() mavenLocal() } -val smithyJavaVersion: String by project - dependencies { - implementation("software.amazon.smithy.java:client-core:0.0.3") - implementation("software.amazon.smithy.java.codegen:plugins:$smithyJavaVersion") - // Core library for the Java client - // Adds the server implementation of the `RestJson1` protocol - implementation("software.amazon.smithy.java:aws-server-restjson:$smithyJavaVersion") + val smithyJavaVersion: String by project + + // Smithy java model generation + smithyBuild("software.amazon.smithy.java.codegen:plugins:$smithyJavaVersion") + implementation(project(":InAndOut-API-Modelling")) + // Adds an HTTP server implementation based on netty implementation("software.amazon.smithy.java:server-netty:$smithyJavaVersion") + // Adds the server implementation of the `RestJson1` protocol + implementation("software.amazon.smithy.java:aws-server-restjson:$smithyJavaVersion") - implementation("org.springframework.boot:spring-boot-starter-jdbc") - implementation("org.springframework.boot:spring-boot-starter-r2dbc") - implementation("org.springframework.boot:spring-boot-starter-restclient") - implementation("org.springframework.boot:spring-boot-starter-security") - implementation("org.springframework.boot:spring-boot-starter-security-oauth2-authorization-server") - implementation("org.springframework.boot:spring-boot-starter-security-oauth2-client") - implementation("org.springframework.boot:spring-boot-starter-session-jdbc") - implementation("org.springframework.boot:spring-boot-starter-webclient") - implementation("org.springframework.boot:spring-boot-starter-webmvc") - implementation("org.springframework.boot:spring-boot-starter-webservices") - compileOnly("org.projectlombok:lombok") - developmentOnly("org.springframework.boot:spring-boot-devtools") - annotationProcessor("org.projectlombok:lombok") - testImplementation("org.springframework.boot:spring-boot-starter-jdbc-test") - testImplementation("org.springframework.boot:spring-boot-starter-r2dbc-test") - testImplementation("org.springframework.boot:spring-boot-starter-restclient-test") - testImplementation("org.springframework.boot:spring-boot-starter-security-oauth2-authorization-server-test") - testImplementation("org.springframework.boot:spring-boot-starter-security-oauth2-client-test") - testImplementation("org.springframework.boot:spring-boot-starter-security-test") - testImplementation("org.springframework.boot:spring-boot-starter-session-jdbc-test") - testImplementation("org.springframework.boot:spring-boot-starter-webclient-test") - testImplementation("org.springframework.boot:spring-boot-starter-webmvc-test") - testImplementation("org.springframework.boot:spring-boot-starter-webservices-test") - testRuntimeOnly("org.junit.platform:junit-platform-launcher") - testRuntimeOnly("com.h2database:h2") - testRuntimeOnly("io.r2dbc:r2dbc-h2") -} + compileOnly("org.projectlombok:lombok:1.18.30") + annotationProcessor("org.projectlombok:lombok:1.18.30") + + testCompileOnly("org.projectlombok:lombok:1.18.30") + testAnnotationProcessor("org.projectlombok:lombok:1.18.30") -afterEvaluate { - sourceSets { - main { - java.srcDir("build/java-client/java-client-codegen") - } - } + testImplementation("org.junit.jupiter:junit-jupiter:5.7.1") + testRuntimeOnly("org.junit.platform:junit-platform-launcher") } -tasks.register("smithyBuild") { - group = "build" - description = "Java models codegen from Smithy model." - commandLine("cmd", "/c", "smithy", "build", - "--config", ".\\InAndOut-API-Modelling\\smithy-build.json", - "--projection", "java-client", - "--output", "build/") +// Add generated source code to the compilation sourceSet +afterEvaluate { + val serverPath = smithy.getPluginProjectionPath(smithy.sourceProjection.get(), "java-server-codegen") + sourceSets.main.get().java.srcDir(serverPath) } tasks.named("compileJava") { dependsOn("smithyBuild") } -tasks.withType { - useJUnitPlatform() -} +tasks.named("test") { + useJUnitPlatform() + + maxHeapSize = "1G" + + testLogging { + events("passed") + } +} \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 61285a6..ccebba7 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37f78a6..17a8ddc 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip networkTimeout=10000 -validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index adff685..79a61d4 100644 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015 the original authors. +# 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. @@ -15,8 +15,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # -# SPDX-License-Identifier: Apache-2.0 -# ############################################################################## # @@ -57,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# 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/. @@ -85,8 +83,10 @@ 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 -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# 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 @@ -114,6 +114,7 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -132,13 +133,10 @@ 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. + 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 fi # Increase the maximum file descriptors if we can. @@ -146,7 +144,7 @@ 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 + # shellcheck disable=SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -154,7 +152,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC2039,SC3045 + # shellcheck disable=SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -171,6 +169,7 @@ fi # 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" ) @@ -198,19 +197,16 @@ if "$cygwin" || "$msys" ; then 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, 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. +# 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" \ - -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ "$@" # Stop when "xargs" is not available. diff --git a/gradlew.bat b/gradlew.bat index c4bdd3a..93e3f59 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,8 +13,6 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem -@rem SPDX-License-Identifier: Apache-2.0 -@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## @@ -45,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. 1>&2 -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 +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 @@ -59,21 +57,22 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. 1>&2 -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 -echo. 1>&2 -echo Please set the JAVA_HOME variable in your environment to match the 1>&2 -echo location of your Java installation. 1>&2 +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%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* +"%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 diff --git a/settings.gradle.kts b/settings.gradle.kts index c9160d0..6e145ec 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,8 +1,10 @@ +rootProject.name = "routeservice" + pluginManagement { val smithyGradleVersion: String by settings plugins { - id("software.amazon.smithy.gradle.smithy-jar") version smithyGradleVersion - id("software.amazon.smithy.gradle.smithy-base") version smithyGradleVersion + id("software.amazon.smithy.gradle.smithy-jar").version(smithyGradleVersion) + id("software.amazon.smithy.gradle.smithy-base").version(smithyGradleVersion) } repositories { @@ -12,4 +14,5 @@ pluginManagement { } } -rootProject.name = "routeservice" +// Subprojects +include("InAndOut-API-Modelling") diff --git a/smithy-build.json b/smithy-build.json new file mode 100644 index 0000000..2dd8076 --- /dev/null +++ b/smithy-build.json @@ -0,0 +1,9 @@ +{ + "version": "1.0", + "plugins": { + "java-server-codegen": { + "service": "com.shopping.inandout#RouteService", + "namespace": "com.shopping.inandout" + } + } +} diff --git a/src/main/java/com/shopping/inandout/routeservice/RouteServer.java b/src/main/java/com/shopping/inandout/routeservice/RouteServer.java new file mode 100644 index 0000000..c2c8b84 --- /dev/null +++ b/src/main/java/com/shopping/inandout/routeservice/RouteServer.java @@ -0,0 +1,51 @@ +package com.shopping.inandout.routeservice; + +import com.shopping.inandout.service.RouteService; +import com.shopping.inandout.routeservice.activities.CreateRouteActivity; +import com.shopping.inandout.routeservice.activities.DeleteRouteActivity; +import com.shopping.inandout.routeservice.activities.GetRouteActivity; + +import java.net.URI; +import java.util.logging.Logger; +import java.util.concurrent.ExecutionException; + +import software.amazon.smithy.java.server.Service; +import software.amazon.smithy.java.server.Server; + +public class RouteServer implements Runnable { + private static final Logger LOGGER = Logger.getLogger(RouteServer.class.getName()); + + public static void main(String... args) throws RuntimeException { + new RouteServer().run(); + } + + @Override + public void run() { + Service service = RouteService.builder() + .addCreateRouteOperation(new CreateRouteActivity()) + .addDeleteRouteOperation(new DeleteRouteActivity()) + .addGetRouteOperation(new GetRouteActivity()) + .build(); + + String endpoint = System.getenv() + .getOrDefault("ROUTE_SERVICE_ENDPOINT", "http://0.0.0.0:8888"); + Server server = Server.builder() + .endpoints(URI.create(endpoint)) + .addService(service) + .build(); + + LOGGER.info("Starting server..."); + server.start(); + + try { + Thread.currentThread().join(); + } catch (InterruptedException e) { + LOGGER.info("Stopping server..."); + try { + server.shutdown().get(); + } catch (InterruptedException | ExecutionException ex) { + throw new RuntimeException(ex); + } + } + } +} diff --git a/src/main/java/com/shopping/inandout/routeservice/RouteServiceApplication.java b/src/main/java/com/shopping/inandout/routeservice/RouteServiceApplication.java deleted file mode 100644 index 6b8454a..0000000 --- a/src/main/java/com/shopping/inandout/routeservice/RouteServiceApplication.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.shopping.inandout.routeservice; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class RouteServiceApplication { - - public static void main(String[] args) { - SpringApplication.run(RouteServiceApplication.class, args); - } -} diff --git a/src/main/java/com/shopping/inandout/routeservice/activities/CreateRouteActivity.java b/src/main/java/com/shopping/inandout/routeservice/activities/CreateRouteActivity.java new file mode 100644 index 0000000..45b3f3e --- /dev/null +++ b/src/main/java/com/shopping/inandout/routeservice/activities/CreateRouteActivity.java @@ -0,0 +1,13 @@ +package com.shopping.inandout.routeservice.activities; + +import com.shopping.inandout.service.CreateRouteOperation; +import com.shopping.inandout.model.CreateRouteInput; +import com.shopping.inandout.model.CreateRouteOutput; + +import software.amazon.smithy.java.server.RequestContext; + +public class CreateRouteActivity implements CreateRouteOperation { + public CreateRouteOutput createRoute(CreateRouteInput input, RequestContext context) { + throw new UnsupportedOperationException("Not (yet) supported operation"); + } +} diff --git a/src/main/java/com/shopping/inandout/routeservice/activities/DeleteRouteActivity.java b/src/main/java/com/shopping/inandout/routeservice/activities/DeleteRouteActivity.java new file mode 100644 index 0000000..ae87298 --- /dev/null +++ b/src/main/java/com/shopping/inandout/routeservice/activities/DeleteRouteActivity.java @@ -0,0 +1,13 @@ +package com.shopping.inandout.routeservice.activities; + +import com.shopping.inandout.service.DeleteRouteOperation; +import com.shopping.inandout.model.DeleteRouteInput; +import com.shopping.inandout.model.DeleteRouteOutput; + +import software.amazon.smithy.java.server.RequestContext; + +public class DeleteRouteActivity implements DeleteRouteOperation { + public DeleteRouteOutput deleteRoute(DeleteRouteInput input, RequestContext context) { + throw new UnsupportedOperationException("Not (yet) supported operation"); + } +} diff --git a/src/main/java/com/shopping/inandout/routeservice/activities/GetRouteActivity.java b/src/main/java/com/shopping/inandout/routeservice/activities/GetRouteActivity.java new file mode 100644 index 0000000..89a94df --- /dev/null +++ b/src/main/java/com/shopping/inandout/routeservice/activities/GetRouteActivity.java @@ -0,0 +1,13 @@ +package com.shopping.inandout.routeservice.activities; + +import com.shopping.inandout.service.GetRouteOperation; +import com.shopping.inandout.model.GetRouteInput; +import com.shopping.inandout.model.GetRouteOutput; + +import software.amazon.smithy.java.server.RequestContext; + +public class GetRouteActivity implements GetRouteOperation { + public GetRouteOutput getRoute(GetRouteInput input, RequestContext context) { + throw new UnsupportedOperationException("Not (yet) supported operation"); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 0016d12..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -spring.application.name=routeservice diff --git a/src/test/java/com/shopping/inandout/routeservice/RouteServiceApplicationTests.java b/src/test/java/com/shopping/inandout/routeservice/RouteServerTest.java similarity index 50% rename from src/test/java/com/shopping/inandout/routeservice/RouteServiceApplicationTests.java rename to src/test/java/com/shopping/inandout/routeservice/RouteServerTest.java index d528e6f..7191aee 100644 --- a/src/test/java/com/shopping/inandout/routeservice/RouteServiceApplicationTests.java +++ b/src/test/java/com/shopping/inandout/routeservice/RouteServerTest.java @@ -1,10 +1,8 @@ package com.shopping.inandout.routeservice; import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; -@SpringBootTest -class RouteServiceApplicationTests { +class RouteServerTest { @Test void contextLoads() {