From 867e94ea8dbc255fb79426732a97c4ee9eeaecc1 Mon Sep 17 00:00:00 2001 From: Raja Kolli Date: Sun, 22 Dec 2024 08:18:31 +0000 Subject: [PATCH] feat : build native image --- .github/workflows/boot-strategy-plugin.yml | 2 +- .../config/GlobalExceptionHandler.java | 19 ++++++++++++------- .../exception/PluginNotFoundException.java | 1 + 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/boot-strategy-plugin.yml b/.github/workflows/boot-strategy-plugin.yml index 3f8c3ef5a..8d78f138c 100644 --- a/.github/workflows/boot-strategy-plugin.yml +++ b/.github/workflows/boot-strategy-plugin.yml @@ -57,7 +57,7 @@ jobs: - if: ${{ github.ref == 'refs/heads/main' }} name: Build container image - run: ./mvnw spring-boot:build-image -Dspring-boot.build-image.imageName=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/boot-strategy-plugin:${{ env.VERSION }} + run: ./mvnw -Pnative spring-boot:build-image -Dspring-boot.build-image.imageName=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/boot-strategy-plugin:${{ env.VERSION }} - if: ${{ github.ref == 'refs/heads/main' }} name: OCI image vulnerability scanning diff --git a/boot-strategy-plugin/src/main/java/com/example/plugin/strategyplugin/config/GlobalExceptionHandler.java b/boot-strategy-plugin/src/main/java/com/example/plugin/strategyplugin/config/GlobalExceptionHandler.java index 9350fcb0a..b4cc2d52c 100644 --- a/boot-strategy-plugin/src/main/java/com/example/plugin/strategyplugin/config/GlobalExceptionHandler.java +++ b/boot-strategy-plugin/src/main/java/com/example/plugin/strategyplugin/config/GlobalExceptionHandler.java @@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.ResponseStatus; +import java.net.URI; import java.util.Comparator; import java.util.List; import java.util.Objects; @@ -26,19 +27,23 @@ ProblemDetail onException(MethodArgumentNotValidException methodArgumentNotValid ProblemDetail problemDetail = ProblemDetail.forStatusAndDetail( HttpStatusCode.valueOf(400), "Invalid request content."); + problemDetail.setType(URI.create("https://api.example.com/errors/validation")); problemDetail.setTitle("Constraint Violation"); List validationErrorsList = methodArgumentNotValidException.getAllErrors().stream() .map( objectError -> { - FieldError fieldError = (FieldError) objectError; - return new ApiValidationError( - fieldError.getObjectName(), - fieldError.getField(), - fieldError.getRejectedValue(), - Objects.requireNonNull( - fieldError.getDefaultMessage(), "")); + if (objectError instanceof FieldError fieldError) { + return new ApiValidationError( + fieldError.getObjectName(), + fieldError.getField(), + fieldError.getRejectedValue(), + Objects.requireNonNull( + fieldError.getDefaultMessage(), "")); + } + return null; }) + .filter(Objects::nonNull) .sorted(Comparator.comparing(ApiValidationError::field)) .toList(); problemDetail.setProperty("violations", validationErrorsList); diff --git a/boot-strategy-plugin/src/main/java/com/example/plugin/strategyplugin/exception/PluginNotFoundException.java b/boot-strategy-plugin/src/main/java/com/example/plugin/strategyplugin/exception/PluginNotFoundException.java index a2c21f4bf..bd93579c2 100644 --- a/boot-strategy-plugin/src/main/java/com/example/plugin/strategyplugin/exception/PluginNotFoundException.java +++ b/boot-strategy-plugin/src/main/java/com/example/plugin/strategyplugin/exception/PluginNotFoundException.java @@ -8,6 +8,7 @@ import java.time.Instant; public class PluginNotFoundException extends ErrorResponseException { + public PluginNotFoundException(String message) { super( HttpStatus.BAD_REQUEST,